MexVision (Obsolete)
MexVision is a matlab interface to the XVision2 visual tracking libraries. MexVision connects to XVision through pvm, so pvm must be running.
MexVision commands are invoked using the matlab function
MexVision('command',p1,p2,...) where p1..pn are the parameters required for the command.
Using MexVision to capture images:
-
In a terminal type:
$pvm
pvm>quit
$matlab
-
In matlab initialize MexVision:
>>MexVision('init','S4R1'); %For "new" point-grey cameras at 640X480 resolution
OR
>>MexVision('init','S0R1'); %For webcams at 640X480 resolution
(For initization at other resolutions see the description of the 'init' command below.)
- Capture images with MexVision (and show them):
>>im=MexVision('frame');
>>figure
>>imshow(im);
- Quit MexVision:
>>MexVision('quit');
- type halt in the pvm window before you log out:
$pvm
pvm>halt
Also make sure that all the mexv2 processes are killed before logging out:
$ps -A|grep mexv2
$killall mexv2
- Another way to get MexVision started quickly is via the command:
>>xvui
This will start pvm, MexVision and bring up a window to initialize trackers.
From this point you can grab images with the MexVision('frame')
command.
- Another useful command is MexVision('get') which returns a vector of
tracked image coordinates positions when any trackers are running.
The tracker we will be using is the "SSD1" (Sum of Squared Differences) 2DOF tracker.
- SSD1 tracker works well, and is mathematically sililar to the one you will implement in the labs. Trying SSD1 gives you an intution for what targets and how fast motions can be tracked.
- SSD2 does not currently work. For ssd2 think the call has to be modified to account for the 4DOF state.
- Color works acceptably, but perhaps some tuning of parameters could make it work better.
- Edge is to be used in combination with other trackers. By its nature it is not stable alone.
More MexVision Commands
- 'init': initialize using a ieee1394 camera as the video source
preconditions: video has not already been created
parameters (specifies the video mode):
- For webcams:
- 'S0R1': RGB 640X480 resolution
- 'S0R0': YUV 640X480 resolution
- 'S1R0': YUV 320X240 resolution
- For "new" point-grey cameras:
- 'S4R1': RGB 640X480 resolution
- 'S2R0': YUV 1024X768 resolution
- 'S3R0': YUV 800X600 resolution
- 'S4R0': YUV 640X480 resolution
- 'S5R0': YUV 320X240 resolution
other options the can be appended to the above string (where X and Y are 0-255) are:
- 'gX': set gain to X
- 'uXvY': set white balance components to X,Y
- 'sX': set saturation to X
- 'window': create a window to display the video, and use for interactive tracker initialization
preconditions: video has been created
parameters: window title (optional)
- 'edge': create an edge tracker and have the user initialize it
preconditions: window has been created
returns: id of the tracker
- 'ssd1': create a translation only ssd Tracker
preconditions: window has been created
parameters: with no parameters, the tracker will be initialized by the user.
Optionally, a vector [Width Height X Y] specifying the initial state of the the
tracker may be given as a parameter.
returns: id of the tracker
- 'ssd2': create a translating/rotating/scaling ssd tracker and have the user initialize it
preconditions: window has been created
returns: id of the tracker
- 'blob': create a color blob tracker and have the user initialize it
preconditions: window has been created
returns: id of the tracker
- 'frame':
grab a frame from the video
returns: matrix containing the image (format depends on the 'init' string)
- 'framerate': get the current tracking framerate
preconditions: video has been created
returns: the tracking framerate
- 'image': get the transformed image associated with a tracker
preconditions: the tracker exists and is of type ssd2
parameters: the id of the tracker
returns: grayscale image for the tracker
- 'get': get the state of a tracker
preconditions: the tracker exists
parameters: the id of the tracker or none to return all tracker states
returns: vector containing the state of the tracker
- 'set': set the state of a tracker
preconditions: the tracker exists
parameters: the id of the tracker, and the new state
returns: vector containing the state of the tracker
- 'delete': remove a tracker
preconditions: the tracker exists
parameters: the id of the tracker
- 'quit': End MexVision
When something doesn't work
If you get an error message "no camera found" in coriander, or
MexVision will not work one of the following can help:
- Quit programs using the camera and potentially hogging the
interface.
- If you have used MexVision in matlab and it crashed, there may also be
additional processses running. These are managed by pvm. In a terminal type:
$pvm
pvm>halt
Also, check and kill stray pvm and mexv2 processes if any:
$ps -A|grep pvmd3
$killall pvmd3
$ps -A|grep mexv2
$killall mexv2
- If the problem still persists, try reloading camera drivers:
- For webcams - first try resetting using coriander, if this does not work try plugging out and then plugging back in the camera.
- For "new" point-grey cameras - ALWAYS use coriander to reset these cameras. NEVER plug out these cameras, they are very expensive and get ruined when the screw lock connectors are repeatedly connected and disconnected.
- As a final resort log out of your account and then log back in (this will almost always fix the problem), but NEVER reboot the computers (TST does NOT like this).
How does MexVision interface with XVision?
MexVision runs as a distributed software using the "pvm - Parallel Virtual Machine " system. When you initialize it pvm will spawn a "mexv2" process (you can see this using "ps" either in the pvm console or at ther command prompt). The
mexv2 process has a thread which handles the real time video, image capture and tracking independently of matlab.
The structure is illustrated below: