This function takes a snapshot picture from the camera module.
The picture taken is in the industry standard JPEG format and four different resolutions are available.
The following resolutions are available:
80 x 64 pixels. Not supported on NX32L
|
160 x 128 pixels. Not supported on NX32L
|
320 x 240 pixels.
|
640 x 480 pixels.
|
The recommended resolution is 320 x 240 pixels as it represents a good balance between buffer size, quality, and resolution.
Input:
res : INT
The resolution of the snapshot picture:
1
|
80 x 64 pixels.
|
2
|
160 x 128 pixels.
|
3
|
320 x 240 pixels.
|
4
|
640 x 480 pixels.
|
pic : PTR
The buffer for the picture snapshot.
The picture returned is in the standard JPEG-compressed format.
picsize : DINT
The size of the picture snapshot buffer.
Recommended buffer sizes:
Resolution
|
Buffer size
|
80 x 64
|
1..2 kB
|
160 x 128
|
3..5 kB
|
320 x 240
|
10..15 kB
|
640 x 480
|
35..45 kB
|
Note: the actual picture size depends on the level of JPEG compression possible on the actual picture.
If the buffer specified in too small for the actual picture. an error code will be returned (see below).
Returns: DINT
The size of the picture snapshot or:
-1
|
- Failed (camera removed, communication problem, camera does not support MJPEG format(see camGetInfo)).
|
-2
|
- Buffer too small.
|
-3
|
- Invalid parameter.
|
-4
|
- Camera is currently recording.
|
-5
|
- Camera interface not open.
|
Declaration:
FUNCTION camSnapshot : DINT;
VAR_INPUT
res : INT;
pic : PTR;
picsize : DINT;
END_VAR;
Example:
INCLUDE rtcu.inc
VAR_INPUT
snapshot : BOOL R_EDGE;
END_VAR;
VAR
size : DINT;
filedes : FILE;
buffer : ARRAY[1..15360] OF SINT;
END_VAR;
PROGRAM test;
fsMediaOpen(media := 0);
camOpen();
BEGIN
IF snapshot THEN
IF camPresent() THEN
size := camSnapshot(res := 3, pic := ADDR(buffer), picsize := SIZEOF(buffer));
IF size > 0 THEN
filedes:=fsFileCreate(name := "PIC.JPG");
fsFileWrite(fd := filedes, buffer := ADDR(buffer), length := INT(size));
fsFileClose(fd := filedes);
END_IF;
END_IF;
END_IF;
END;
END_PROGRAM;
|