Skip to main content

A Python module for controlling PTZ cameras running on Sony VISCA protocol via serial USB

Project description

pyvisca

A Python module for controlling PTZ cameras running on Sony VISCA protocol via serial USB.

This repository is a "fork" of a previous Python VISCA library initially published on November 23, 2015 by Matthew Mage under the repo name python-visca (GPL-3.0-licensed). The original code was written in Python 2.0, but was discontinued since 2016.

In pyvisca, we have converted the source code to make it compatible with Python 3.0. (Python 2.0 is deprecated, and the third version is used in most circumstances nowadays.) More functionalities and commands are also added to the library, which was previously unavailable in the original work done by Matthew Mage. These new commands include the following:

  • Ability to zoom in/out the camera
  • Ability to set and recall presets
  • Ability to turn the PTZ camera on and off
  • Ability to change iris setting
  • Ability to change brightness setting

In addition, the following commands are already present in the original work by Matthew Mage:

  • Panning the camera left, up, right, and down
  • Homing the camera position to its default position
  • Enabling autofocus of camera lens
  • Setting picture effect (on supported devices only)
  • Setting white balance
  • Move relative to the current position

Note that not every command can be executed in any given PTZ camera. Please refer to your VISCA-compatible PTZ camera's specification to see which commands and features are available.

Installation

The pyvisca module can be installed directly from pip:

python -m pip install pyvisca

The Python script can also be downloaded directly from this repository and imported right away. To do so, run:

git clone https://github.com/groaking/pyvisca

Then cd into the src folder of the cloned repository, and execute the following line in the Python terminal:

from pyvisca import visca

Usage

The following is a basic example on how to make use of this library.

from pyvisca import visca

# Instantiating a new VISCA PTZ object
# This also automatically initializes and connects to the serial port
cam = visca.PTZ('/dev/ttyS0')
# Windows users may need to run the following command instead
# cam = visca.PTZ('COM10')

# Turning the power of the camera on and off
# "1" for on, "0" for off (you can use "True" and "False" as well)
cam.power(1)

# Send the camera to its home/default position
cam.home()

# Move the camera in one direction
# This will send the camera to move indefinitely
cam.left()
cam.up()
cam.down()
cam.right(7)  # --- adjust movement speed by specifying 0-24; defaults to 5

# Move the camera in two directions
cam.left_up()
cam.left_down()
cam.right_up()
cam.right_down(3, 7)  # --- adjust movement speed by specifying 0-24 into (pan, tilt) parameter
                      # ---defaults to (5, 5)

# Relative movement
# ---
# relative_position(pan, tilt, amount_pan, amount_tilt, direction_pan, direction_tilt)
# 
# pan                       : pan speed (0-24)
# tilt                      : tilt speed (0-24)
# amount_pan, amount_tilt   : amount to move in pixels
# direction_pan             : 1 = right, -1 = left
# direction_tilt            : 1 = up,    -1 = down
cam.relative_position(2, 2, 100, 100, 1, -1)

# Stop the pan and/or tilt movements of the camera right away
cam.stop()

# Adjust camera zoom (wide or tele)
# This will send the camera to zoom indefinitely
cam.zoom_in()
cam.zoom_out(3)  # --- adjust zooming speed by specifying 0-7; defaults to 5

# Stop any zoom movement
cam.zoom_stop()

# Adjust the iris of the camera (constant speed)
cam.iris_up()
cam.iris_down()
cam.iris_reset()

# Adjust the brightness of the camera (constant speed)
cam.bright_up()
cam.bright_down()
cam.bright_reset()

# Assign the current camera position to a preset (0-255)
cam.preset_set(255)

# Recall a preset assignment (0-255)
cam.preset_recall(255)

# Setting white balance
cam.white_balance_auto()
cam.white_balance_indoor()
cam.white_balance_outdoor()

# Change picture effects
cam.picture_effect_b_w()
cam.picture_effect_mosaic()
cam.picture_effect_negative()
cam.picture_effect_pastel()
cam.picture_effect_sepia()
cam.picture_effect_slim()
cam.picture_effect_solarize()
cam.picture_effect_stretch()

# Turn off picture effect
cam.picture_effect_off()

# Autofocus the camera
cam.autofocus_sens_high()

Roadmap

In the future versions, we plan to add the following feature commands:

  • Adjust camera gain
  • Adjust camera aperture
  • Turn backlight compensation on/off (on supported devices)
  • Freeze the current view

Contributing

If you find this library helpful, feel free to star this repository.

You can also contribute by opening an issue, proposing a new feature, and creating a new pull request in this repository.

Acknowledgement

The original work of this library is due to Matthew Mage.

We refer to the following reference manual in developing this library: https://docs.crestron.com/en-us/9326/Content/Topics/Configuration/VISCA-Comands.htm.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyvisca-0.0.2.tar.gz (42.5 kB view details)

Uploaded Source

Built Distribution

pyvisca-0.0.2-py3-none-any.whl (31.9 kB view details)

Uploaded Python 3

File details

Details for the file pyvisca-0.0.2.tar.gz.

File metadata

  • Download URL: pyvisca-0.0.2.tar.gz
  • Upload date:
  • Size: 42.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.3

File hashes

Hashes for pyvisca-0.0.2.tar.gz
Algorithm Hash digest
SHA256 843d0c19aacd562703b65486b3afa110dbee8ba29bc626169fbf5795dc969e9b
MD5 62c448d3ff5efbef7ea9963f54a61652
BLAKE2b-256 7b7f11f2f26915041b25234d6f06b64f8a0e9a2402c3ae609add377ca5fec0da

See more details on using hashes here.

Provenance

File details

Details for the file pyvisca-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: pyvisca-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 31.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.3

File hashes

Hashes for pyvisca-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6f4a8feb0cbc6d758d7095f096718a59cb5a18e0c46d8cbf91ad713404aefaf3
MD5 203f389f20095cdb887a36bf61d79e06
BLAKE2b-256 edb315fa84cd4eae630a4d4d52c2f1b7bcfab5c531d02b081b3d158e11647037

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page