Warning
This page is located in archive.

USB camera Chameleon

Camera Chameleon is digital USB 2.0 camera Chameleon manufactued by PointGrey.

Camera control (Matlab on Windows)

The camera can be operated in MATLAB via Image Acquisition Toolboxu.

  1. Camera can be accessed as follows
    vid = videoinput('winvideo',1,'Y800_1280x960');
  2. If you need to change capturing parameters (the default setting is fully automatic camera), the following script sets the manual control::
    inspect(getselectedsource(vid));
    or the following command sets a parameter value:
    set(getselectedsource(vid), 'PropertyName', 'PropertyValue');
    If you need to determine the current value of the parameter it is possible to use the command
    get(getselectedsource(vid), 'PropertyName');
    Useful information can be obtained by calling
    propoinfo(getselectedsource(vid), 'PropertyName');
    NOTE: Most of the parameters influencing the image capturing can be set only when capturing is off (before calling “start(vid)”).
  3. Capturing of the endless video stream is initiated by the following commands
    set(vid,'TriggerRepeat',Inf);
    vid.FrameGrabInterval = 1;
    start(vid);
  4. The following command reads one frame from the current buffer
    im = getdata(vid,1);
  5. The camera provides video in RAW format, therefore debayering is needed. This can be done for example by using the following commands. We could not figure out how to change the white balance for blue channel in the MATLAB environment, therefore blue channel must be multiplied by an appropriate value
    im_debay(:,:,1) = im(2:2:end,1:2:end);
    im_debay(:,:,2) = im(1:2:end,1:2:end)/2 + im(2:2:end,2:2:end)/2;
    im_debay(:,:,3) = 6.5 * im(1:2:end,2:2:end);
  6. Eventually, you can clear the memory by the following commands
    stop(vid);
    delete(vid);

Camera control (Matlab on Linux)

  • In linux version of matlab the driver for the camera doe's not work properly, therefore we have added simple function to grab an image (flygrab).
  • First add path to the flygrab directory:

addpath('/opt/flygrab');

  • Then grab an image:

img = flygrab();

  • In order to configuration the camera use the FlyCap2 utility.

Camera control (ROS)

Driver documentation: pointgray_camera_driver

Start camera driver nodes:

# Assuming that the B3B33ROB ROS Enviroment was properly sourced i.e. :
source /opt/ros/b3b33rob
 
# just camera driver
$ roslaunch b3b33rob_ros camera.launch
 
# or camera with robot
$ roslaunch b3b33rob_ros start_rv6sdl.launch camera:=true
$ roslaunch b3b33rob_ros start_rv6s.launch camera:=true
$ roslaunch b3b33rob_ros start_fake_rv6sdl.launch camera:=true
$ roslaunch b3b33rob_ros start_fake_rv6sdl.launch camera:=true

Display camera stream:

$ rosrun image_view image_view image:=/camera/image_color

  • In order to configuration the camera use the FlyCap2 utility.

Camera Control (Python)

From Python the library used for the communication with the camera is PyCapture2. There is an example of the camera usage in python:

import PyCapture2
import cv2
import numpy as np
 
# Initialize bus and camera
bus = PyCapture2.BusManager()
camera = PyCapture2.Camera()
 
# Select first camera on the bus
camera.connect(bus.getCameraFromIndex(0))
 
# Start capture
camera.startCapture()
 
while True:
  # Retrieve image from camara in PyCapture2.Image format
  image = camera.retrieveBuffer()
 
  # Convert from MONO8 to RGB8
  image = image.convert(PyCapture2.PIXEL_FORMAT.RGB8)
 
  # Convert image to Numpy array
  rgb_cv_image = np.array(image.getData(), dtype="uint8").reshape((image.getRows(), image.getCols(), 3));
 
  # Convert RGB image to BGR image to be shown by OpenCV
  bgr_cv_image = cv2.cvtColor(rgb_cv_image, cv2.COLOR_RGB2BGR)
 
  # Show image
  cv2.imshow('frame',bgr_cv_image)
 
  # Wait for key press, stop if the key is q
  if cv2.waitKey(1) & 0xFF == ord('q'):
    break

More documentation about the PyCapture2 can be found with this command:

evince /opt/salt-install/PyCapture2-2.13.31/docs/PyCapture2doc.pdf

Parameter Settings

As described above, it is possible to set some camera parameters in the MATLAB environment. These parameters influence the image provided by the camera, and they are therefore important for the successful use of the camera. Description of paremeters in the camera documentation is very limited. Therefore, we conducted a limited survey and testing in order to determine the possibility to set the capturing parameters.

Unfortunately MATLAB interface allows to adjust only a limited number of parameters. The following parameters can be set:

Gain - This parameter is used to change the gain of the video signal amplifier. With the growing gain, grows also the image brightness, but unfortunately also the noise. If it is not necessary for other reasons (e.g. maintaining a slow shutter speed), it is recommended to set the gain at 1.0 ~ 0 dB (output = input). Gain value equal to 0dB corresponds to the value of parameter 160.

set(getselectedsource(vid),'GainMode','manual');
set(getselectedsource(vid),'Gain',160);

Gamma - Sets the amount of non-linear amplification of the video signal. Non-linear amplification compensates (i) imaging device inaccuracy and (ii) the human perception properties (details e.g. Wikipedia:Gamma correction). This additional nonlinear compensation has no meaning for autonomous computer processing. It can reduce measurement accuracy for some brightness levels due to uneven discretization. Therefore, we recommend that you set up the scanning without compensation, which corresponds to the gamma=1.0. Gamma equal to 1.0 corresponds to the value of the parameter equal to 1024.

set(getselectedsource(vid),'GammaMode','manual');
set(getselectedsource(vid),'Gamma',1024);

WhiteBalance - White Balance determines the overall mixture of colors in an image (Wikipedia:White balance). Autonomous white balance setting of the Chameleon camera is not properly implemented and the used algorithm is not described. You are encourage to play with it. If you do not need to use a color image, we recommend to set this parameter manually to the default value equal to 100.

set(getselectedsource(vid),'WhiteBalanceMode','manual');
set(getselectedsource(vid),'WhiteBalance',100);

Brightness - is a global parameter, which can be used to adjust the overall brightness in the image. This parameter does not have a direct physical meaning. If “Shutter ” and “ Gain” are set to “Auto Select”, brightness value directly influences these parameters​. Method for determining the brightness of the image (and the corresponding algorithm) is not described in detail. In our case, if the “Shutter ” and “ Gain” are adjusted manually (not automatically), then “Brightness” has no influence on the camera settings.

Unfortunately, the shutter speed setting (“Shutter”) is not allowed in the Matlab environment. However, “Brightness” can be used for this purpose. If you set the “Brightness” mode to “auto” (using the program AMCAP Shutter) and set the appropriate constant value of the “Exposure”, then “Brightness” directly influences the shutter speed (“Shutter”). However, the shutter speed will change according to “Brightness” with a certain delay corresponding to the time constants of the automatic camera settings.

For all the above mentioned parameters, there is always pair parameter “NameMode”. This pair parameter determines which value will be adjusted manually and which automatically. Automatic setting is provided directly by the camera. In the automatic setting, it is necessary to take into account the time constants of the in-built algorithm. Stabilization of automatically set values ​after the arameter change should be about 1s.

AMCAP program (provided by the camera manufacturer) is suitable for real-time monitoring of parameter changes. Running the AMCAP program simultaneously with capturing in the Matlab environment is not recommended. Problems are as follows:

  • Irregular distribution of captured frames between the two programs. Variable frame rate and/or transport delay is especially annoying during the critical time image processing (closing the feedback loop).
  • Picture degradation (spillage) when using different image resolution.

Parameter Settings (flycap2)

  • In terminal run:

<code shell> $ flycap2 <code>

help/common/kamera_matlab_chameleon_en.txt · Last modified: 2022/10/25 12:27 by wagnelib