|
Camera API Technical Report:
Example Code |
#include <stdio.h>
#include <camera.h>
.
.
int num_cameras, i;
CameraList *cameras;
Camera camera;
char *databuf;
/* get the list of cameras supported by the library */
num_cameras = CameraGetList( &cameras );
/* check status, open, read data and close each camera */
for(i=0; i < num_cameras; i++){
/* test camera status */
if( CameraStatus( cameras[i]->def_init_str, cameras[i]->class ) )
continue;
camera = CameraInit( cameras[i]->def_init_str, cameras[i]->class );
/* read data from the camera */
databuf = (char *) malloc(CameraDataSize(camera));
CameraRead(camera, databuf);
free( databuf );
/* close the camera */
CameraClose( camera );
}
Note CameraStatus() is of marginal use here because CameraInit()
will return NULL on failure. CameraDataSize() is a convenience
routine to calculate the total datasize associated with the current window
and image depth and CameraRead() transfers data from the camera into
the given buffer.