CAMERA — cameras
CAMERA["name"] refers to one camera registered in the Vision Tool Editor. Scripts open and close the camera,
turn live video on and off, and take one picture (grab). The picture goes into the image object chosen as the camera's GRAB IMAGE,
and vision tools find marks or measure on that image (VISION).
Use it when an inspection or align sequence needs a new picture. Usually you take one picture with OneShot() and then run a vision tool.
Access
Cameras are created under CAMERA CONFIGURATION in the studio's Vision Tool Editor.
| Setting | Meaning |
|---|---|
| CAMERA NAME | Name used in scripts and controls (CAMERA["this name"], must be unique) |
| CAMERA DRIVER · CAMERA CLASS TYPE | Project driver that provides camera classes, and its class |
| GRAB IMAGE | Image object that receives the camera picture |
| CAMERA ID · CAM FILE | Device ID (IP address · serial number · device path, etc.) and the camera setting file |
| Enabled | When off, the camera is not opened |
| Flip — FlipX · FlipY | Flips the picture in the X / Y direction |
Pressing SAVE in the Vision Tool Editor closes all cameras and reopens them with the new settings.
Basic example
FUNCTION GrabAlignImage()
{
// Check that the camera is connected
if( CAMERA["AlignCam"].IsOpened == false )
{
LogError("AlignCam is not opened");
return false;
}
// Stop it if it is live
if( CAMERA["AlignCam"].IsLive == true )
{
CAMERA["AlignCam"].Stop();
}
// Grab one picture — wait up to 600 ms
if( CAMERA["AlignCam"].OneShot(/*waitMSec*/600) == false )
{
LogError("AlignCam grab failed");
return false;
}
return true;
}Functions
| Signature | Description |
|---|---|
bool OpenCamera() | Connects the camera |
bool CloseCamera() | Disconnects the camera |
bool Live() | Starts live (continuous) video |
bool Stop() | Stops the camera. If it is live, it switches to the stopped state |
bool OneShot(int waitMSec = 600) | Takes one picture (grab). waitMSec is the maximum wait (ms) |
double GetFrameRate() | Current frame rate of the camera |
bool Contains(string keyword) | Whether this camera's name contains keyword |
string ToString() | Camera information string (CAMERA ['name']) |
void StateChanged() | Announces that the camera state has changed |
bool SetSimScene(string imageFile, string motorX, string motorY, double pixelPerMm, double originX, double originY) (4.0.29~) | Sets the simulation scene (see 'Simulation scene' below) |
bool SetSimShift(double dx, double dy, double deg, double pivotX, double pivotY) (4.0.29~) | Makes the material of the scene look moved and turned |
bool ClearSimScene() (4.0.29~) | Clears the simulation scene (live view stops too) |
Properties
| Property | Description |
|---|---|
bool InitOk | Whether the camera has been initialized |
bool IsOpened | Whether the camera is connected |
bool IsLive | Whether it is live |
string Name | Camera name |
bool Visible | Display flag (set · get) |
bool IsSimScene (4.0.29~) | Whether the camera serves a simulation scene (true with a scene in simulation mode — always false for a real camera) |
Simulation scene (4.0.29~)
A camera whose driver is left empty in the camera data (a virtual camera) can serve part of a large scene image (a picture of the whole board) as its image in simulation mode. On grab and live it cuts out the camera size (Width × Height of the camera data) so that the current position of the camera X · Y motors is the image center, so the camera calibration, teaching and measurement of an align run as on a machine without hardware (sample SampleProject\VisionSample\AlignSample). Outside simulation mode, or on a camera with a real driver, the scene is not accepted and the functions return false (log only — a fake image must never pass a measurement on a machine).
// end of INIT — scene pixel (px, py) = machine ( 0 + px / 20 , 0 + py / 20 ) mm
if( CAMERA["FidCam"].SetSimScene("SimImages\\AlignBoard.png", "M_CamX", "M_CamY", 20, 0, 0) == false )
{
Log("simulation scene not set");
}
// as if the material turned 0.5 deg about (70, 55) and moved X +0.3 mm
CAMERA["FidCam"].SetSimShift(0.3, 0, 0.5, 70, 55);SetSimScene—imageFileis the scene image (relative to the project folder or a full path, PNG · BMP · JPG etc. — converted to gray),motorX·motorYare the camera X · Y motor names,pixelPerMmis the scene scale (px / mm — this becomes the camera scale), andoriginX·originYare the machine coordinates (mm) of the top-left scene pixel (down in the image is Y +). Outside the scene the edge pixels continue, and the material shift and turn (SetSimShift) is reset to 0. Returnsfalseoutside simulation mode, when the file or a motor is missing, when the scale is 0 or less or the origin is not a number, when the camera data has no Width · Height or the Width is not a multiple of 4, when the camera image is not gray (Gray8), or when the image is smaller than 2 pixels. The camera FlipX · FlipY are not used (the scene is served as it is).SetSimShift— a scene point P appears at pivot + R(deg)·(P − pivot) + (dx, dy) (dx · dy in mm, deg in degrees, turning from machine X toward Y is +, pivot in machine mm). Used to change the correction an align measures. With the rotation center at the rotation center of the align result (the middle of the two marks for 2 marks, the centroid for 3 marks, the corner for an edge), the shift and angle of the align result equal the values given. Returnsfalsewhen there is no scene.ClearSimScene— clears the scene (live view stops too). Afterwards grab and live fail as before.
Cautions
- When
OneShot()returnsfalse, no picture was received. Check the result and do not run vision tools when it fails. - If the camera is live, stop it with
Stop()before grabbing withOneShot(), as in the example above. Contains()checks whether this camera's name contains the text. It does not search for a camera with another name.- Camera object names are not checked at build time. Make sure they match the camera names in the Vision Tool Editor.
Related
- VISION — vision images and tools
- Vision Tool Editor — screen that registers cameras, images and vision tools
- ALIGN — align — finds marks (1 to 3) or two board edges with a camera to measure the part position