extended libdc1394 backend (the patch is by Michael Joachimiak)

pull/13383/head
Vadim Pisarevsky 14 years ago
parent c820438b22
commit 535425982f
  1. 27
      modules/highgui/include/opencv2/highgui/highgui_c.h
  2. 138
      modules/highgui/src/cap_dc1394_v2.cpp
  3. 1
      modules/python/defs

@ -315,6 +315,12 @@ CVAPI(void) cvReleaseCapture( CvCapture** capture );
enum
{
// modes of the controlling registers (can be: auto, manual, auto single push, absolute Latter allowed with any other mode)
// every feature can have only one mode turned on at a time
CV_CAP_PROP_DC1394_OFF = -4, //turn the feature off (not controlled manually nor automatically)
CV_CAP_PROP_DC1394_MODE_MANUAL = -3, //set automatically when a value of the feature is set by the user
CV_CAP_PROP_DC1394_MODE_AUTO = -2,
CV_CAP_PROP_DC1394_MODE_ONE_PUSH_AUTO = -1,
CV_CAP_PROP_POS_MSEC =0,
CV_CAP_PROP_POS_FRAMES =1,
CV_CAP_PROP_POS_AVI_RATIO =2,
@ -332,20 +338,29 @@ enum
CV_CAP_PROP_GAIN =14,
CV_CAP_PROP_EXPOSURE =15,
CV_CAP_PROP_CONVERT_RGB =16,
CV_CAP_PROP_WHITE_BALANCE =17,
CV_CAP_PROP_WHITE_BALANCE_BLUE_U =17,
CV_CAP_PROP_RECTIFICATION =18,
CV_CAP_PROP_MONOCROME =19,
CV_CAP_PROP_SHARPNESS =20,
CV_CAP_PROP_AUTO_EXPOSURE =21, // exposure control done by camera,
// user can adjust refernce level
// using this feature
CV_CAP_PROP_GAMMA =22,
CV_CAP_PROP_TEMPERATURE =23,
CV_CAP_PROP_TRIGGER =24,
CV_CAP_PROP_TRIGGER_DELAY =25,
CV_CAP_PROP_WHITE_BALANCE_RED_V =26,
CV_CAP_PROP_MAX_DC1394 =27,
// OpenNI map generators
CV_CAP_OPENNI_DEPTH_GENERATOR = 0,
CV_CAP_OPENNI_IMAGE_GENERATOR = 1 << 31,
CV_CAP_OPENNI_GENERATORS_MASK = 1 << 31,
// Properties of cameras avalible through OpenNI interfaces
CV_CAP_PROP_OPENNI_OUTPUT_MODE = 20,
CV_CAP_PROP_OPENNI_FRAME_MAX_DEPTH = 21, // in mm
CV_CAP_PROP_OPENNI_BASELINE = 22, // in mm
CV_CAP_PROP_OPENNI_FOCAL_LENGTH = 23, // in pixels
CV_CAP_PROP_OPENNI_OUTPUT_MODE = 100,
CV_CAP_PROP_OPENNI_FRAME_MAX_DEPTH = 101, // in mm
CV_CAP_PROP_OPENNI_BASELINE = 102, // in mm
CV_CAP_PROP_OPENNI_FOCAL_LENGTH = 103, // in pixels
CV_CAP_OPENNI_IMAGE_GENERATOR_OUTPUT_MODE = CV_CAP_OPENNI_IMAGE_GENERATOR + CV_CAP_PROP_OPENNI_OUTPUT_MODE,
CV_CAP_OPENNI_DEPTH_GENERATOR_BASELINE = CV_CAP_OPENNI_DEPTH_GENERATOR + CV_CAP_PROP_OPENNI_BASELINE,
CV_CAP_OPENNI_DEPTH_GENERATOR_FOCAL_LENGTH = CV_CAP_OPENNI_DEPTH_GENERATOR + CV_CAP_PROP_OPENNI_FOCAL_LENGTH

@ -190,6 +190,7 @@ static CvDC1394 dc1394;
class CvCaptureCAM_DC1394_v2_CPP : public CvCapture
{
public:
static int dc1394properties[CV_CAP_PROP_MAX_DC1394];
CvCaptureCAM_DC1394_v2_CPP();
virtual ~CvCaptureCAM_DC1394_v2_CPP()
{
@ -236,8 +237,31 @@ protected:
bool rectify;
bool init_rectify;
IplImage *maps[NIMG][2];
dc1394featureset_t feature_set;
};
//mapping CV_CAP_PROP_ to DC1394_FEATUREs
int CvCaptureCAM_DC1394_v2_CPP::dc1394properties[CV_CAP_PROP_MAX_DC1394] = {
-1, //no corresponding feature for CV_CAP_PROP_POS_MSEC
-1,-1,-1,-1,
DC1394_FEATURE_FRAME_RATE, //CV_CAP_PROP_FPS - fps can be set for format 7 only!
-1,-1,-1,-1,
DC1394_FEATURE_BRIGHTNESS,//CV_CAP_PROP_BRIGHTNESS 10
-1,
DC1394_FEATURE_SATURATION,//CV_CAP_PROP_SATURATION
DC1394_FEATURE_HUE,
DC1394_FEATURE_GAIN,
DC1394_FEATURE_SHUTTER, //CV_CAP_PROP_EXPOSURE
-1,//CV_CAP_PROP_CONVERT_RGB
DC1394_FEATURE_WHITE_BALANCE, //corresponds to CV_CAP_PROP_WHITE_BALANCE_BLUE_U and CV_CAP_PROP_WHITE_BALANCE_RED_V, see set function to check these props are set
-1,-1,
DC1394_FEATURE_SHARPNESS, //20
DC1394_FEATURE_EXPOSURE, //CV_CAP_PROP_AUTO_EXPOSURE - this is auto exposure according to the IIDC standard
DC1394_FEATURE_GAMMA, //CV_CAP_PROP_GAMMA
DC1394_FEATURE_TEMPERATURE, //CV_CAP_PROP_TEMPERATURE
DC1394_FEATURE_TRIGGER, //CV_CAP_PROP_TRIGGER
DC1394_FEATURE_TRIGGER_DELAY, //CV_CAP_PROP_TRIGGER_DELAY
DC1394_FEATURE_WHITE_BALANCE//CV_CAP_PROP_WHITE_BALANCE_RED_V
};
CvCaptureCAM_DC1394_v2_CPP::CvCaptureCAM_DC1394_v2_CPP()
{
guid = 0;
@ -411,7 +435,11 @@ bool CvCaptureCAM_DC1394_v2_CPP::open(int index)
goto _exit_;
cameraId = dcCam->vendor_id;
result = true;
//get all features
if (dc1394_feature_get_all(dcCam,&feature_set) == DC1394_SUCCESS)
result = true;
else
result = false;
_exit_:
if (cameraList)
@ -579,13 +607,27 @@ double CvCaptureCAM_DC1394_v2_CPP::getProperty(int propId)
return fps;
case CV_CAP_PROP_RECTIFICATION:
return rectify ? 1 : 0;
// case CV_CAP_PROP_BRIGHTNESS :
// case CV_CAP_PROP_CONTRAST :
// case CV_CAP_PROP_WHITE_BALANCE :
case CV_CAP_PROP_WHITE_BALANCE_BLUE_U:
if (dc1394_feature_whitebalance_get_value(dcCam,
&feature_set.feature[DC1394_FEATURE_WHITE_BALANCE-DC1394_FEATURE_MIN].BU_value,
&feature_set.feature[DC1394_FEATURE_WHITE_BALANCE-DC1394_FEATURE_MIN].RV_value) == DC1394_SUCCESS)
return feature_set.feature[DC1394_FEATURE_WHITE_BALANCE-DC1394_FEATURE_MIN].BU_value;
break;
case CV_CAP_PROP_WHITE_BALANCE_RED_V:
if (dc1394_feature_whitebalance_get_value(dcCam,
&feature_set.feature[DC1394_FEATURE_WHITE_BALANCE-DC1394_FEATURE_MIN].BU_value,
&feature_set.feature[DC1394_FEATURE_WHITE_BALANCE-DC1394_FEATURE_MIN].RV_value) == DC1394_SUCCESS)
return feature_set.feature[DC1394_FEATURE_WHITE_BALANCE-DC1394_FEATURE_MIN].RV_value;
break;
default:
;
if (propId<CV_CAP_PROP_MAX_DC1394 && dc1394properties[propId]!=-1
&& dcCam)
//&& feature_set.feature[dc1394properties[propId]-DC1394_FEATURE_MIN].on_off_capable)
if (dc1394_feature_get_value(dcCam,(dc1394feature_t)dc1394properties[propId],
&feature_set.feature[dc1394properties[propId]-DC1394_FEATURE_MIN].value) == DC1394_SUCCESS)
return feature_set.feature[dc1394properties[propId]-DC1394_FEATURE_MIN].value;
}
return 0;
return -1; // the value of the feature can be 0, so returning 0 as an error is wrong
}
bool CvCaptureCAM_DC1394_v2_CPP::setProperty(int propId, double value)
@ -617,8 +659,86 @@ bool CvCaptureCAM_DC1394_v2_CPP::setProperty(int propId, double value)
case CV_CAP_PROP_MODE:
userMode = cvRound(value);
break;
default:
return false;
//The code below is based on coriander, callbacks.c:795, refer to case RANGE_MENU_MAN :
default:
if (propId<CV_CAP_PROP_MAX_DC1394 && dc1394properties[propId]!=-1
&& dcCam)
{
if (cvRound(value) == CV_CAP_PROP_DC1394_OFF)
if ((feature_set.feature[dc1394properties[propId]-DC1394_FEATURE_MIN].on_off_capable)
&& (dc1394_feature_set_power(dcCam, (dc1394feature_t)dc1394properties[propId], DC1394_OFF)==DC1394_SUCCESS))
{
feature_set.feature[dc1394properties[propId]-DC1394_FEATURE_MIN].is_on=DC1394_OFF;
return true;
}
else
return false;
//try to turn the feature ON, feature can be ON and at the same time it can be not capable to change state to OFF
if ( feature_set.feature[dc1394properties[propId]-DC1394_FEATURE_MIN].is_on == DC1394_OFF &&
(feature_set.feature[dc1394properties[propId]-DC1394_FEATURE_MIN].on_off_capable == DC1394_TRUE))
{
if (dc1394_feature_set_power(dcCam, (dc1394feature_t)dc1394properties[propId], DC1394_ON) == DC1394_SUCCESS)
feature_set.feature[dc1394properties[propId]-DC1394_FEATURE_MIN].is_on=DC1394_ON;
}
//turn off absolute mode - the actual value will be stored in the value field,
//otherwise it would be stored into CSR (control and status register) absolute value
if (feature_set.feature[dc1394properties[propId]-DC1394_FEATURE_MIN].absolute_capable
&& dc1394_feature_set_absolute_control(dcCam, (dc1394feature_t)dc1394properties[propId], DC1394_OFF) !=DC1394_SUCCESS)
return false;
else
feature_set.feature[(dc1394feature_t)dc1394properties[propId]-DC1394_FEATURE_MIN].abs_control=DC1394_OFF;
//set AUTO
if (cvRound(value) == CV_CAP_PROP_DC1394_MODE_AUTO)
{
if (dc1394_feature_set_mode(dcCam, (dc1394feature_t)dc1394properties[propId], DC1394_FEATURE_MODE_AUTO)!=DC1394_SUCCESS)
return false;
feature_set.feature[(dc1394feature_t)dc1394properties[propId]-DC1394_FEATURE_MIN].current_mode=DC1394_FEATURE_MODE_AUTO;
return true;
}
//set ONE PUSH
if (cvRound(value) == CV_CAP_PROP_DC1394_MODE_ONE_PUSH_AUTO)
{
//have to set to manual first, otherwise one push will be ignored (AVT manual 4.3.0 p. 115)
if (dc1394_feature_set_mode(dcCam, (dc1394feature_t)dc1394properties[propId], DC1394_FEATURE_MODE_ONE_PUSH_AUTO)!=DC1394_SUCCESS)
return false;
//will change to
feature_set.feature[dc1394properties[propId]-DC1394_FEATURE_MIN].current_mode=DC1394_FEATURE_MODE_ONE_PUSH_AUTO;
return true;
}
//set the feature to MANUAL mode,
if (dc1394_feature_set_mode(dcCam, (dc1394feature_t)dc1394properties[propId], DC1394_FEATURE_MODE_MANUAL)!=DC1394_SUCCESS)
return false;
else
feature_set.feature[dc1394properties[propId]-DC1394_FEATURE_MIN].current_mode=DC1394_FEATURE_MODE_MANUAL;
// if property is one of the white balance features treat it in different way
if (propId == CV_CAP_PROP_WHITE_BALANCE_BLUE_U)
{
if (dc1394_feature_whitebalance_set_value(dcCam,cvRound(value), feature_set.feature[dc1394properties[propId]-DC1394_FEATURE_MIN].RV_value)!=DC1394_SUCCESS)
return false;
else
{
feature_set.feature[DC1394_FEATURE_WHITE_BALANCE-DC1394_FEATURE_MIN].BU_value = cvRound(value);
return true;
}
}
if (propId == CV_CAP_PROP_WHITE_BALANCE_RED_V)
{
if (dc1394_feature_whitebalance_set_value(dcCam,feature_set.feature[dc1394properties[propId]-DC1394_FEATURE_MIN].BU_value,cvRound(value))!=DC1394_SUCCESS)
return false;
else
{
feature_set.feature[DC1394_FEATURE_WHITE_BALANCE-DC1394_FEATURE_MIN].RV_value = cvRound(value);
return true;
}
}
// finally set the feature
if (dc1394_feature_set_value(dcCam,(dc1394feature_t)dc1394properties[propId],cvRound(value)) == DC1394_SUCCESS)
{
feature_set.feature[dc1394properties[propId]-DC1394_FEATURE_MIN].value = value;
return true;
}
}
return false;
}
return true;
}

@ -322,7 +322,6 @@
#define CV_CAP_PROP_GAIN 14
#define CV_CAP_PROP_EXPOSURE 15
#define CV_CAP_PROP_CONVERT_RGB 16
#define CV_CAP_PROP_WHITE_BALANCE 17
#define CV_CAP_PROP_RECTIFICATION 18
#define CV_CN_SHIFT 3
#define CV_IMWRITE_JPEG_QUALITY 1

Loading…
Cancel
Save