Main Page | Class List | File List | Class Members | Examples

SC1ModCam Class Reference

Control an SC1-modified pwc-compatible webcam. More...

#include <SC1ModCam.hpp>

List of all members.

Public Types

enum  ERRCODE { ERR_OK = 0, ERR_ERROR, ERR_WARN, ERR_FATAL }

Public Member Functions

 SC1ModCam (string devname="/dev/video", int parport=0x378)
 Initialize the class.

 ~SC1ModCam ()
 Free memory and close the device.

unsigned long set_exposure (unsigned long msecs)
 Set exposure time in milliseconds.

unsigned long get_exposure (void)
 Get exposure time in milliseconds.

unsigned long set_multiplier (unsigned int m)
 Set number of frames to drop.

unsigned long get_multiplier (void)
 Get number of frames that will be dropped.

unsigned int set_fps (unsigned int fps)
 Set frames-per-second for camera.

unsigned int get_fps (void)
 Get number of frames per second.

bool set_resolution (int width, int height)
 Set capture resolution of camera.

void get_resolution (int *width, int *height)
 Get capture resolution from camera.

void * get_buffer (void)
 Get pointer to buffer containing image.

size_t get_buffer_size (void)
 Get size of buffer in bytes.

bool take_photo ()
 Take exposure (synchronously).

enum ERRCODE error (string *msg=NULL)
 Get error code and descriptive string.


Protected Member Functions

void _set_error (string error, enum ERRCODE code=ERR_ERROR)
void _unset_error (void)
bool _sync_settings (void)
 Synchronizes camera settings with local values.

bool _setup_camera (void)
 Sets up all hardcoded settings and calls _sync_settings().

bool _open_shutter ()
 Set pin 2 on the parport low, starting the exposure.

bool _close_shutter ()
 Set pin 2 on the parport high, stopping the exposure.

void _usleep (unsigned long usecs)
 Sleep for the specifed number of microseconds.


Protected Attributes

string _error_string
enum ERRCODE _error_code
void * _buffer
int _multiplier
int _fps
int _image_width
int _image_height
int _devfd

Static Protected Attributes

const float _bytes_per_pixel = 1.5


Detailed Description

Control an SC1-modified pwc-compatible webcam.

This class allows you to control a pwc-compatible camera that has been modified according to the SC1 Modifiction:

http://pmdo.com/SC1.htm

This class has been tested with a Philips ToUcam PRO II (PCVC840K) but should work with any camera supported by the pwc driver:

http://www.smcc.demon.nl/webcam/

Examples:

lexp.cpp.


Constructor & Destructor Documentation

SC1ModCam::SC1ModCam string  devname = "/dev/video",
int  parport = 0x378
 

Initialize the class.

This calls various other functions to set defaults:

  • FPS = 5
  • Multiplier = 8
  • Resolution = 640x480

Parameters:
devname Name of webcam's video4linux device
parport Numerical address of parallel port connected to the webcam


Member Function Documentation

bool SC1ModCam::_close_shutter void   )  [protected]
 

Set pin 2 on the parport high, stopping the exposure.

Currently, this function always returns true.

Returns:
false if an error occurred, true otherwise

bool SC1ModCam::_open_shutter void   )  [protected]
 

Set pin 2 on the parport low, starting the exposure.

Currently, this function always returns true.

Returns:
false if an error occurred, true otherwise

bool SC1ModCam::_setup_camera void   )  [protected]
 

Sets up all hardcoded settings and calls _sync_settings().

Returns:
false if an error occurred, true otherwise
See also:
_sync_settings()

bool SC1ModCam::_sync_settings void   )  [protected]
 

Synchronizes camera settings with local values.

Used in the constructor to set all the default values in the camera.

Returns:
false if an error occurred, true otherwise

void SC1ModCam::_usleep unsigned long  usecs  )  [protected]
 

Sleep for the specifed number of microseconds.

The system call nanosleep(2) is used in this implementation.

Parameters:
usecs Number of microseconds to sleep

enum SC1ModCam::ERRCODE SC1ModCam::error string *  msg = NULL  ) 
 

Get error code and descriptive string.

If msg is null or not specified, only the error code is returned.

Parameters:
msg Pointer to string to set to error string
Returns:
Error code
Examples:
lexp.cpp.

void * SC1ModCam::get_buffer void   ) 
 

Get pointer to buffer containing image.

It only makes sense to call this function after calling take_photo(). If you call this function before take_photo, you will receive a null pointer.

Warning:
The pointer returned by this function is only valid while the object still exists!
Returns:
Pointer to image in YUV420P format (1.5 bytes per pixel)
Examples:
lexp.cpp.

size_t SC1ModCam::get_buffer_size void   ) 
 

Get size of buffer in bytes.

Use this to avoid reading an incomplete image.

Examples:
lexp.cpp.

void SC1ModCam::get_resolution int *  width,
int *  height
 

Get capture resolution from camera.

This function assumes that the internal variables reflect reality. In proper operation, this should be fine.

Parameters:
width Pointer to value to set to image width
height Pointer to value to set to image height

unsigned long SC1ModCam::set_exposure unsigned long  msecs  ) 
 

Set exposure time in milliseconds.

The actual exposure time may be shorter than the specified exposure time by as much as (1/FPS).

A warning will be generated if the exposure time is set to less than 1 second. Exposure times this short have been known to result in corrupted frames.

Warning:
Changing the FPS after calling this function will change the exposure time but won't trigger a warning!
Parameters:
msecs exposure time in miilliseconds
Returns:
Actual exposure time in milliseconds

unsigned int SC1ModCam::set_fps unsigned int  fps  ) 
 

Set frames-per-second for camera.

The FPS will be set in the class and on the camera itself. If the camera does not support the given FPS value, an error of type ERR_WARN will be set and the current value will be returned.

Parameters:
fps Number of frames per second. Acceptable values depend on the specific camera in use, but 5 is the default.
Returns:
Actual FPS set in camera - will be different from parameter if there was an error.
See also:
http://www.smcc.demon.nl/webcam/
Examples:
lexp.cpp.

unsigned long SC1ModCam::set_multiplier unsigned int  mult  ) 
 

Set number of frames to drop.

The long exposure is taken by grabbing a bunch of frames and throwing most of them away. This function sets approximately how many frames get dropped.

Parameters:
mult Number of frames to drop
Returns:
Time, in milliseconds, of exposure
Examples:
lexp.cpp.

bool SC1ModCam::set_resolution int  width,
int  height
 

Set capture resolution of camera.

Parameters:
width Width in pixels
height Height in pixels
Returns:
Success (true) or failure (false)
Examples:
lexp.cpp.

bool SC1ModCam::take_photo void   ) 
 

Take exposure (synchronously).

This function takes the long exposure synchronously, meaning it blocks the calling function for the entire length of the exposure.

Returns:
false if an error occurred, true otherwise.
Examples:
lexp.cpp.


The documentation for this class was generated from the following files:
Generated on Fri Jul 16 12:22:57 2004 for libsc1mod by doxygen 1.3.7