Added new VideoCapture properties for ieee1394 cameras

This commit is contained in:
Alexander Reshetnikov 2012-02-24 10:54:52 +00:00
parent 228b87250a
commit b12f18536f
2 changed files with 113 additions and 41 deletions

View File

@ -365,7 +365,11 @@ enum
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,
CV_CAP_PROP_ZOOM =27,
CV_CAP_PROP_FOCUS =28,
CV_CAP_PROP_GUID =29,
CV_CAP_PROP_ISO_SPEED =30,
CV_CAP_PROP_MAX_DC1394 =31,
CV_CAP_PROP_AUTOGRAB =1024, // property for highgui class CvCapture_Android only
CV_CAP_PROP_SUPPORTED_PREVIEW_SIZES_STRING=1025, // readonly, tricky property, returns cpnst char* indeed
CV_CAP_PROP_PREVIEW_FORMAT=1026, // readonly, tricky property, returns cpnst char* indeed

View File

@ -260,7 +260,10 @@ 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
DC1394_FEATURE_WHITE_BALANCE, //CV_CAP_PROP_WHITE_BALANCE_RED_V
DC1394_FEATURE_ZOOM, //CV_CAP_PROP_ZOOM
DC1394_FEATURE_FOCUS, //CV_CAP_PROP_FOCUS
-1 //CV_CAP_PROP_GUID
};
CvCaptureCAM_DC1394_v2_CPP::CvCaptureCAM_DC1394_v2_CPP()
{
@ -303,6 +306,55 @@ bool CvCaptureCAM_DC1394_v2_CPP::startCapture()
DC1394_ISO_SPEED_3200);
}
// should a specific mode be used
if (userMode >= 0)
{
dc1394video_mode_t wantedMode;
dc1394video_modes_t videoModes;
dc1394_video_get_supported_modes(dcCam, &videoModes);
//set mode from number, for example the second supported mode, i.e userMode = 1
if (userMode < (int)videoModes.num)
{
wantedMode = videoModes.modes[userMode];
}
//set modes directly from DC134 constants (from dc1394video_mode_t)
else if ((userMode >= DC1394_VIDEO_MODE_MIN) && (userMode <= DC1394_VIDEO_MODE_MAX ))
{
//search for wanted mode, to check if camera supports it
int j = 0;
while ((j< (int)videoModes.num) && videoModes.modes[j]!=userMode)
{
j++;
}
if ((int)videoModes.modes[j]==userMode)
{
wantedMode = videoModes.modes[j];
}
else
{
userMode = -1; // wanted mode not supported, search for best mode
}
}
else
{
userMode = -1; // wanted mode not supported, search for best mode
}
//if userMode is available: set it and update size
if (userMode != -1)
{
code = dc1394_video_set_mode(dcCam, wantedMode);
uint32_t width, height;
dc1394_get_image_size_from_video_mode(dcCam, wantedMode, &width, &height);
frameWidth = (int)width;
frameHeight = (int)height;
}
}
if (userMode == -1 && (frameWidth > 0 || frameHeight > 0))
{
dc1394video_mode_t bestMode = (dc1394video_mode_t) - 1;
@ -348,17 +400,6 @@ bool CvCaptureCAM_DC1394_v2_CPP::startCapture()
code = dc1394_video_set_mode(dcCam, bestMode);
}
if (userMode > 0)
{
dc1394video_modes_t videoModes;
dc1394_video_get_supported_modes(dcCam, &videoModes);
if (userMode < (int)videoModes.num)
{
dc1394video_mode_t mode = videoModes.modes[userMode];
code = dc1394_video_set_mode(dcCam, mode);
}
}
if (fps > 0)
{
dc1394video_mode_t mode;
@ -619,6 +660,15 @@ double CvCaptureCAM_DC1394_v2_CPP::getProperty(int propId)
&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;
case CV_CAP_PROP_GUID:
//the least 32 bits are enough to identify the camera
return (double) (guid & 0x00000000FFFFFFFF);
break;
case CV_CAP_PROP_MODE:
return (double) userMode;
break;
case CV_CAP_PROP_ISO_SPEED:
return (double) isoSpeed;
default:
if (propId<CV_CAP_PROP_MAX_DC1394 && dc1394properties[propId]!=-1
&& dcCam)
@ -657,87 +707,105 @@ bool CvCaptureCAM_DC1394_v2_CPP::setProperty(int propId, double value)
rectify = fabs(value) > FLT_EPSILON;
break;
case CV_CAP_PROP_MODE:
if(started)
return false;
userMode = cvRound(value);
break;
case CV_CAP_PROP_ISO_SPEED:
if(started)
return false;
isoSpeed = cvRound(value);
break;
//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)
{
//get the corresponding feature from property-id
dc1394feature_info_t *act_feature = &feature_set.feature[dc1394properties[propId]-DC1394_FEATURE_MIN];
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))
if ( (act_feature->on_off_capable)
&& (dc1394_feature_set_power(dcCam, act_feature->id, DC1394_OFF) == DC1394_SUCCESS))
{
feature_set.feature[dc1394properties[propId]-DC1394_FEATURE_MIN].is_on=DC1394_OFF;
act_feature->is_on=DC1394_OFF;
return true;
}
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 ( (act_feature->is_on == DC1394_OFF) && (act_feature->on_off_capable == DC1394_TRUE))
{
if (dc1394_feature_set_power(dcCam, (dc1394feature_t)dc1394properties[propId], DC1394_ON) == DC1394_SUCCESS)
if (dc1394_feature_set_power(dcCam, act_feature->id, 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)
if (act_feature->absolute_capable
&& dc1394_feature_set_absolute_control(dcCam, act_feature->id, DC1394_OFF) !=DC1394_SUCCESS)
return false;
else
feature_set.feature[(dc1394feature_t)dc1394properties[propId]-DC1394_FEATURE_MIN].abs_control=DC1394_OFF;
act_feature->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)
if (dc1394_feature_set_mode(dcCam, atc_feature->id, DC1394_FEATURE_MODE_AUTO)!=DC1394_SUCCESS)
return false;
feature_set.feature[(dc1394feature_t)dc1394properties[propId]-DC1394_FEATURE_MIN].current_mode=DC1394_FEATURE_MODE_AUTO;
act_feature->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)
if (dc1394_feature_set_mode(dcCam, act_feature->id, 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;
act_feature->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)
if (dc1394_feature_set_mode(dcCam, act_feature->id, DC1394_FEATURE_MODE_MANUAL)!=DC1394_SUCCESS)
return false;
else
feature_set.feature[dc1394properties[propId]-DC1394_FEATURE_MIN].current_mode=DC1394_FEATURE_MODE_MANUAL;
act_feature->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)
if (dc1394_feature_whitebalance_set_value(dcCam,cvRound(value), act_feature->RV_value)!=DC1394_SUCCESS)
return false;
else
{
feature_set.feature[DC1394_FEATURE_WHITE_BALANCE-DC1394_FEATURE_MIN].BU_value = cvRound(value);
act_feature->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)
if (dc1394_feature_whitebalance_set_value(dcCam, act_feature->BU_value, cvRound(value))!=DC1394_SUCCESS)
return false;
else
{
feature_set.feature[DC1394_FEATURE_WHITE_BALANCE-DC1394_FEATURE_MIN].RV_value = cvRound(value);
act_feature->RV_value = cvRound(value);
return true;
}
}
// finally set the feature
if (dc1394_feature_set_value(dcCam,(dc1394feature_t)dc1394properties[propId],cvRound(value)) == DC1394_SUCCESS)
//first: check boundaries
if (value < act_feature->min)
{
feature_set.feature[dc1394properties[propId]-DC1394_FEATURE_MIN].value = value;
return true;
value = act_feature->min;
}
else if (value > act_feature->max)
{
value = act_feature->max;
}
if (dc1394_feature_set_value(dcCam, act_feature->id, cvRound(value)) == DC1394_SUCCESS)
{
act_feature->value = value;
return true;
}
return false;
}