Path: blob/master/modules/videoio/src/cap_dc1394_v2.cpp
16339 views
/*M///////////////////////////////////////////////////////////////////////////////////////1//2// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.3//4// By downloading, copying, installing or using the software you agree to this license.5// If you do not agree to this license, do not download, install,6// copy or use the software.7//8//9// Intel License Agreement10// For Open Source Computer Vision Library11//12// Copyright (C) 2000, Intel Corporation, all rights reserved.13// Third party copyrights are property of their respective owners.14//15// Redistribution and use in source and binary forms, with or without modification,16// are permitted provided that the following conditions are met:17//18// * Redistribution's of source code must retain the above copyright notice,19// this list of conditions and the following disclaimer.20//21// * Redistribution's in binary form must reproduce the above copyright notice,22// this list of conditions and the following disclaimer in the documentation23// and/or other materials provided with the distribution.24//25// * The name of Intel Corporation may not be used to endorse or promote products26// derived from this software without specific prior written permission.27//28// This software is provided by the copyright holders and contributors "as is" and29// any express or implied warranties, including, but not limited to, the implied30// warranties of merchantability and fitness for a particular purpose are disclaimed.31// In no event shall the Intel Corporation or contributors be liable for any direct,32// indirect, incidental, special, exemplary, or consequential damages33// (including, but not limited to, procurement of substitute goods or services;34// loss of use, data, or profits; or business interruption) however caused35// and on any theory of liability, whether in contract, strict liability,36// or tort (including negligence or otherwise) arising in any way out of37// the use of this software, even if advised of the possibility of such damage.38//39//M*/4041#include "precomp.hpp"4243#ifdef HAVE_DC1394_24445#include <unistd.h>46#include <stdint.h>47#ifdef _WIN3248// On Windows, we have no sys/select.h, but we need to pick up49// select() which is in winsock2.50#ifndef __SYS_SELECT_H__51#define __SYS_SELECT_H__ 152#include <winsock2.h>53#endif54#else55#include <sys/select.h>56#endif /*_WIN32*/57#include <dc1394/dc1394.h>58#include <stdlib.h>59#include <string.h>6061static dc1394error_t adaptBufferStereoLocal(dc1394video_frame_t *in, dc1394video_frame_t *out)62{63uint32_t bpp;6465// buffer position is not changed. Size is boubled in Y66out->size[0] = in->size[0];67out->size[1] = in->size[1] * 2;68out->position[0] = in->position[0];69out->position[1] = in->position[1];7071// color coding is set to mono8 or raw8.72switch (in->color_coding)73{74case DC1394_COLOR_CODING_RAW16:75out->color_coding = DC1394_COLOR_CODING_RAW8;76break;77case DC1394_COLOR_CODING_MONO16:78case DC1394_COLOR_CODING_YUV422:79out->color_coding = DC1394_COLOR_CODING_MONO8;80break;81default:82return DC1394_INVALID_COLOR_CODING;83}8485// keep the color filter value in all cases. if the format is not raw it will not be further used anyway86out->color_filter = in->color_filter;8788// the output YUV byte order must be already set if the buffer is YUV422 at the output89// if the output is not YUV we don't care about this field.90// Hence nothing to do.91// we always convert to 8bits (at this point) we can safely set this value to 8.92out->data_depth = 8;9394// don't know what to do with stride... >>>> TODO: STRIDE SHOULD BE TAKEN INTO ACCOUNT... <<<<95// out->stride=??96// the video mode should not change. Color coding and other stuff can be accessed in specific fields of this struct97out->video_mode = in->video_mode;9899// padding is kept:100out->padding_bytes = in->padding_bytes;101102// image bytes changes: >>>> TODO: STRIDE SHOULD BE TAKEN INTO ACCOUNT... <<<<103dc1394_get_color_coding_bit_size(out->color_coding, &bpp);104out->image_bytes = (out->size[0] * out->size[1] * bpp) / 8;105106// total is image_bytes + padding_bytes107out->total_bytes = out->image_bytes + out->padding_bytes;108109// bytes-per-packet and packets_per_frame are internal data that can be kept as is.110out->packet_size = in->packet_size;111out->packets_per_frame = in->packets_per_frame;112113// timestamp, frame_behind, id and camera are copied too:114out->timestamp = in->timestamp;115out->frames_behind = in->frames_behind;116out->camera = in->camera;117out->id = in->id;118119// verify memory allocation:120if (out->total_bytes > out->allocated_image_bytes)121{122free(out->image);123out->image = (uint8_t*)malloc(out->total_bytes * sizeof(uint8_t));124out->allocated_image_bytes = out->total_bytes;125}126127// Copy padding bytes:128memcpy(&(out->image[out->image_bytes]), &(in->image[in->image_bytes]), out->padding_bytes);129out->little_endian = DC1394_FALSE; // not used before 1.32 is out.130out->data_in_padding = DC1394_FALSE; // not used before 1.32 is out.131return DC1394_SUCCESS;132}133134static dc1394error_t dc1394_deinterlace_stereo_frames_fixed(dc1394video_frame_t *in,135dc1394video_frame_t *out, dc1394stereo_method_t method)136{137if((in->color_coding == DC1394_COLOR_CODING_RAW16) ||138(in->color_coding == DC1394_COLOR_CODING_MONO16) ||139(in->color_coding == DC1394_COLOR_CODING_YUV422))140{141switch (method)142{143144case DC1394_STEREO_METHOD_INTERLACED:145adaptBufferStereoLocal(in, out);146//FIXED by AB:147// dc1394_deinterlace_stereo(in->image, out->image, in->size[0], in->size[1]);148dc1394_deinterlace_stereo(in->image, out->image, out->size[0], out->size[1]);149break;150151case DC1394_STEREO_METHOD_FIELD:152adaptBufferStereoLocal(in, out);153memcpy(out->image, in->image, out->image_bytes);154break;155}156157return DC1394_INVALID_STEREO_METHOD;158}159else160return DC1394_FUNCTION_NOT_SUPPORTED;161}162163struct CvDC1394164{165CvDC1394();166~CvDC1394();167168dc1394_t* dc;169fd_set camFds;170};171172CvDC1394::CvDC1394()173{174dc = dc1394_new();175FD_ZERO(&camFds);176}177178CvDC1394::~CvDC1394()179{180if (dc)181dc1394_free(dc);182dc = 0;183}184185static CvDC1394 dc1394;186187class CvCaptureCAM_DC1394_v2_CPP : public CvCapture188{189public:190static int dc1394properties[CV_CAP_PROP_MAX_DC1394];191CvCaptureCAM_DC1394_v2_CPP();192virtual ~CvCaptureCAM_DC1394_v2_CPP()193{194close();195}196197virtual bool open(int index);198virtual void close();199200virtual double getProperty(int) const CV_OVERRIDE;201virtual bool setProperty(int, double) CV_OVERRIDE;202virtual bool grabFrame() CV_OVERRIDE;203virtual IplImage* retrieveFrame(int) CV_OVERRIDE;204virtual int getCaptureDomain() CV_OVERRIDE { return CV_CAP_DC1394; }205206207protected:208virtual bool startCapture();209210uint64_t guid;211dc1394camera_t* dcCam;212int isoSpeed;213int videoMode;214int frameWidth, frameHeight;215double fps;216int nDMABufs;217bool started;218int userMode;219220enum { VIDERE = 0x5505 };221222int cameraId;223bool colorStereo;224dc1394bayer_method_t bayer;225dc1394color_filter_t bayerFilter;226227enum { NIMG = 2 };228IplImage *img[NIMG];229dc1394video_frame_t* frameC;230int nimages;231232dc1394featureset_t feature_set;233};234//mapping CV_CAP_PROP_ to DC1394_FEATUREs235int CvCaptureCAM_DC1394_v2_CPP::dc1394properties[CV_CAP_PROP_MAX_DC1394] = {236-1, //no corresponding feature for CV_CAP_PROP_POS_MSEC237-1,-1,-1,-1,238DC1394_FEATURE_FRAME_RATE, //CV_CAP_PROP_FPS - fps can be set for format 7 only!239-1,-1,-1,-1,240DC1394_FEATURE_BRIGHTNESS, //CV_CAP_PROP_BRIGHTNESS 10241-1,242DC1394_FEATURE_SATURATION, //CV_CAP_PROP_SATURATION243DC1394_FEATURE_HUE,244DC1394_FEATURE_GAIN,245DC1394_FEATURE_SHUTTER, //CV_CAP_PROP_EXPOSURE246-1, //CV_CAP_PROP_CONVERT_RGB247DC1394_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 set248-1,-1,249DC1394_FEATURE_SHARPNESS, //20250DC1394_FEATURE_EXPOSURE, //CV_CAP_PROP_AUTO_EXPOSURE - this is auto exposure according to the IIDC standard251DC1394_FEATURE_GAMMA, //CV_CAP_PROP_GAMMA252DC1394_FEATURE_TEMPERATURE, //CV_CAP_PROP_TEMPERATURE253DC1394_FEATURE_TRIGGER, //CV_CAP_PROP_TRIGGER254DC1394_FEATURE_TRIGGER_DELAY, //CV_CAP_PROP_TRIGGER_DELAY255DC1394_FEATURE_WHITE_BALANCE, //CV_CAP_PROP_WHITE_BALANCE_RED_V256DC1394_FEATURE_ZOOM, //CV_CAP_PROP_ZOOM257DC1394_FEATURE_FOCUS, //CV_CAP_PROP_FOCUS258-1 //CV_CAP_PROP_GUID259};260CvCaptureCAM_DC1394_v2_CPP::CvCaptureCAM_DC1394_v2_CPP()261{262guid = 0;263dcCam = 0;264isoSpeed = 400;265fps = 15;266// Reset the value here to 1 in order to ensure only a single frame is stored in the buffer!267nDMABufs = 8;268started = false;269cameraId = 0;270colorStereo = false;271bayer = DC1394_BAYER_METHOD_BILINEAR;272bayerFilter = DC1394_COLOR_FILTER_GRBG;273frameWidth = 640;274frameHeight = 480;275276for (int i = 0; i < NIMG; i++)277img[i] = 0;278frameC = 0;279nimages = 1;280userMode = -1;281}282283284bool CvCaptureCAM_DC1394_v2_CPP::startCapture()285{286int i;287int code = 0;288if (!dcCam)289return false;290if (isoSpeed > 0)291{292// if capable set operation mode to 1394b for iso speeds above 400293if (isoSpeed > 400 && dcCam->bmode_capable == DC1394_TRUE)294{295dc1394_video_set_operation_mode(dcCam, DC1394_OPERATION_MODE_1394B);296}297code = dc1394_video_set_iso_speed(dcCam,298isoSpeed <= 100 ? DC1394_ISO_SPEED_100 :299isoSpeed <= 200 ? DC1394_ISO_SPEED_200 :300isoSpeed <= 400 ? DC1394_ISO_SPEED_400 :301isoSpeed <= 800 ? DC1394_ISO_SPEED_800 :302isoSpeed == 1600 ? DC1394_ISO_SPEED_1600 :303DC1394_ISO_SPEED_3200);304}305306// should a specific mode be used307if (userMode >= 0)308309{310dc1394video_mode_t wantedMode;311dc1394video_modes_t videoModes;312dc1394_video_get_supported_modes(dcCam, &videoModes);313314//set mode from number, for example the second supported mode, i.e userMode = 1315316if (userMode < (int)videoModes.num)317{318wantedMode = videoModes.modes[userMode];319}320321//set modes directly from DC134 constants (from dc1394video_mode_t)322else if ((userMode >= DC1394_VIDEO_MODE_MIN) && (userMode <= DC1394_VIDEO_MODE_MAX ))323{324//search for wanted mode, to check if camera supports it325int j = 0;326while ((j< (int)videoModes.num) && videoModes.modes[j]!=userMode)327{328j++;329}330331if ((int)videoModes.modes[j]==userMode)332{333wantedMode = videoModes.modes[j];334}335else336{337userMode = -1; // wanted mode not supported, search for best mode338}339}340else341{342userMode = -1; // wanted mode not supported, search for best mode343}344//if userMode is available: set it and update size345if (userMode != -1)346{347code = dc1394_video_set_mode(dcCam, wantedMode);348uint32_t width, height;349dc1394_get_image_size_from_video_mode(dcCam, wantedMode, &width, &height);350frameWidth = (int)width;351frameHeight = (int)height;352}353}354355if (userMode == -1 && (frameWidth > 0 || frameHeight > 0))356{357dc1394video_mode_t bestMode = (dc1394video_mode_t) - 1;358dc1394video_modes_t videoModes;359dc1394_video_get_supported_modes(dcCam, &videoModes);360for (i = 0; i < (int)videoModes.num; i++)361{362dc1394video_mode_t mode = videoModes.modes[i];363if (mode >= DC1394_VIDEO_MODE_FORMAT7_MIN && mode <= DC1394_VIDEO_MODE_FORMAT7_MAX)364continue;365int pref = -1;366dc1394color_coding_t colorCoding;367dc1394_get_color_coding_from_video_mode(dcCam, mode, &colorCoding);368369uint32_t width, height;370dc1394_get_image_size_from_video_mode(dcCam, mode, &width, &height);371if ((int)width == frameWidth || (int)height == frameHeight)372{373if (colorCoding == DC1394_COLOR_CODING_RGB8 ||374colorCoding == DC1394_COLOR_CODING_RAW8)375{376bestMode = mode;377break;378}379380if (colorCoding == DC1394_COLOR_CODING_YUV411 ||381colorCoding == DC1394_COLOR_CODING_YUV422 ||382(colorCoding == DC1394_COLOR_CODING_YUV444 &&383pref < 1))384{385bestMode = mode;386pref = 1;387break;388}389390if (colorCoding == DC1394_COLOR_CODING_MONO8)391{392bestMode = mode;393pref = 0;394}395}396}397if ((int)bestMode >= 0)398code = dc1394_video_set_mode(dcCam, bestMode);399}400401if (fps > 0)402{403dc1394video_mode_t mode;404dc1394framerates_t framerates;405double minDiff = DBL_MAX;406dc1394framerate_t bestFps = (dc1394framerate_t) - 1;407408dc1394_video_get_mode(dcCam, &mode);409dc1394_video_get_supported_framerates(dcCam, mode, &framerates);410411for (i = 0; i < (int)framerates.num; i++)412{413dc1394framerate_t ifps = framerates.framerates[i];414double fps1 = (1 << (ifps - DC1394_FRAMERATE_1_875)) * 1.875;415double diff = fabs(fps1 - fps);416if (diff < minDiff)417{418minDiff = diff;419bestFps = ifps;420}421}422if ((int)bestFps >= 0)423code = dc1394_video_set_framerate(dcCam, bestFps);424}425426if (cameraId == VIDERE)427{428bayerFilter = DC1394_COLOR_FILTER_GBRG;429nimages = 2;430uint32_t value = 0;431dc1394_get_control_register(dcCam, 0x50c, &value);432colorStereo = (value & 0x80000000) != 0;433}434435code = dc1394_capture_setup(dcCam, nDMABufs, DC1394_CAPTURE_FLAGS_DEFAULT);436if (code >= 0)437{438FD_SET(dc1394_capture_get_fileno(dcCam), &dc1394.camFds);439dc1394_video_set_transmission(dcCam, DC1394_ON);440started = true;441}442443return code >= 0;444}445446bool CvCaptureCAM_DC1394_v2_CPP::open(int index)447{448bool result = false;449dc1394camera_list_t* cameraList = 0;450dc1394error_t err;451452close();453454if (!dc1394.dc)455goto _exit_;456457err = dc1394_camera_enumerate(dc1394.dc, &cameraList);458if (err < 0 || !cameraList || (unsigned)index >= (unsigned)cameraList->num)459goto _exit_;460461guid = cameraList->ids[index].guid;462dcCam = dc1394_camera_new(dc1394.dc, guid);463if (!dcCam)464goto _exit_;465466cameraId = dcCam->vendor_id;467//get all features468if (dc1394_feature_get_all(dcCam,&feature_set) == DC1394_SUCCESS)469result = true;470else471result = false;472473_exit_:474if (cameraList)475dc1394_camera_free_list(cameraList);476477return result;478}479480void CvCaptureCAM_DC1394_v2_CPP::close()481{482if (dcCam)483{484// check for fileno valid before using485int fileno=dc1394_capture_get_fileno(dcCam);486487if (fileno>=0 && FD_ISSET(fileno, &dc1394.camFds))488FD_CLR(fileno, &dc1394.camFds);489dc1394_video_set_transmission(dcCam, DC1394_OFF);490dc1394_capture_stop(dcCam);491dc1394_camera_free(dcCam);492dcCam = 0;493started = false;494}495496for (int i = 0; i < NIMG; i++)497{498cvReleaseImage(&img[i]);499}500if (frameC)501{502if (frameC->image)503free(frameC->image);504free(frameC);505frameC = 0;506}507}508509510bool CvCaptureCAM_DC1394_v2_CPP::grabFrame()511{512dc1394capture_policy_t policy = DC1394_CAPTURE_POLICY_WAIT;513bool code = false, isColor;514dc1394video_frame_t *dcFrame = 0, *fs = 0;515int i, nch;516517if (!dcCam || (!started && !startCapture()))518return false;519520dc1394_capture_dequeue(dcCam, policy, &dcFrame);521522if (!dcFrame)523return false;524525if (/*dcFrame->frames_behind > 1 ||*/ dc1394_capture_is_frame_corrupt(dcCam, dcFrame) == DC1394_TRUE)526{527goto _exit_;528}529530isColor = dcFrame->color_coding != DC1394_COLOR_CODING_MONO8 &&531dcFrame->color_coding != DC1394_COLOR_CODING_MONO16 &&532dcFrame->color_coding != DC1394_COLOR_CODING_MONO16S;533534if (nimages == 2)535{536fs = (dc1394video_frame_t*)calloc(1, sizeof(*fs));537538//dc1394_deinterlace_stereo_frames(dcFrame, fs, DC1394_STEREO_METHOD_INTERLACED);539dc1394_deinterlace_stereo_frames_fixed(dcFrame, fs, DC1394_STEREO_METHOD_INTERLACED);540541dc1394_capture_enqueue(dcCam, dcFrame); // release the captured frame as soon as possible542dcFrame = 0;543if (!fs->image)544goto _exit_;545isColor = colorStereo;546}547nch = isColor ? 3 : 1;548549for (i = 0; i < nimages; i++)550{551IplImage fhdr;552dc1394video_frame_t f = fs ? *fs : *dcFrame, *fc = &f;553f.size[1] /= nimages;554f.image += f.size[0] * f.size[1] * i; // TODO: make it more universal555if (isColor)556{557if (!frameC)558frameC = (dc1394video_frame_t*)calloc(1, sizeof(*frameC));559frameC->color_coding = nch == 3 ? DC1394_COLOR_CODING_RGB8 : DC1394_COLOR_CODING_MONO8;560if (nimages == 1)561{562dc1394_convert_frames(&f, frameC);563dc1394_capture_enqueue(dcCam, dcFrame);564dcFrame = 0;565}566else567{568f.color_filter = bayerFilter;569dc1394_debayer_frames(&f, frameC, bayer);570}571fc = frameC;572}573if (!img[i])574img[i] = cvCreateImage(cvSize(fc->size[0], fc->size[1]), 8, nch);575cvInitImageHeader(&fhdr, cvSize(fc->size[0], fc->size[1]), 8, nch);576cvSetData(&fhdr, fc->image, fc->size[0]*nch);577578// Swap R&B channels:579if (nch==3)580cvConvertImage(&fhdr,&fhdr,CV_CVTIMG_SWAP_RB);581582cvCopy(&fhdr, img[i]);583}584585code = true;586587_exit_:588if (dcFrame)589dc1394_capture_enqueue(dcCam, dcFrame);590if (fs)591{592if (fs->image)593free(fs->image);594free(fs);595}596597return code;598}599600IplImage* CvCaptureCAM_DC1394_v2_CPP::retrieveFrame(int idx)601{602return 0 <= idx && idx < nimages ? img[idx] : 0;603}604605double CvCaptureCAM_DC1394_v2_CPP::getProperty(int propId) const606{607// Simulate mutable (C++11-like) member variable608dc1394featureset_t& fs = const_cast<dc1394featureset_t&>(feature_set);609610switch (propId)611{612case CV_CAP_PROP_FRAME_WIDTH:613return frameWidth ? frameWidth : frameHeight*4 / 3;614case CV_CAP_PROP_FRAME_HEIGHT:615return frameHeight ? frameHeight : frameWidth*3 / 4;616case CV_CAP_PROP_FPS:617return fps;618case CV_CAP_PROP_RECTIFICATION:619CV_LOG_WARNING(NULL, "cap_dc1394: rectification support has been removed from videoio module");620return 0;621case CV_CAP_PROP_WHITE_BALANCE_BLUE_U:622if (dc1394_feature_whitebalance_get_value(dcCam,623&fs.feature[DC1394_FEATURE_WHITE_BALANCE-DC1394_FEATURE_MIN].BU_value,624&fs.feature[DC1394_FEATURE_WHITE_BALANCE-DC1394_FEATURE_MIN].RV_value) == DC1394_SUCCESS)625return feature_set.feature[DC1394_FEATURE_WHITE_BALANCE-DC1394_FEATURE_MIN].BU_value;626break;627case CV_CAP_PROP_WHITE_BALANCE_RED_V:628if (dc1394_feature_whitebalance_get_value(dcCam,629&fs.feature[DC1394_FEATURE_WHITE_BALANCE-DC1394_FEATURE_MIN].BU_value,630&fs.feature[DC1394_FEATURE_WHITE_BALANCE-DC1394_FEATURE_MIN].RV_value) == DC1394_SUCCESS)631return feature_set.feature[DC1394_FEATURE_WHITE_BALANCE-DC1394_FEATURE_MIN].RV_value;632break;633case CV_CAP_PROP_GUID:634//the least 32 bits are enough to identify the camera635return (double) (guid & 0x00000000FFFFFFFF);636break;637case CV_CAP_PROP_MODE:638return (double) userMode;639break;640case CV_CAP_PROP_ISO_SPEED:641return (double) isoSpeed;642case CV_CAP_PROP_BUFFERSIZE:643return (double) nDMABufs;644default:645if (propId<CV_CAP_PROP_MAX_DC1394 && dc1394properties[propId]!=-1646&& dcCam)647//&& feature_set.feature[dc1394properties[propId]-DC1394_FEATURE_MIN].on_off_capable)648if (dc1394_feature_get_value(dcCam,(dc1394feature_t)dc1394properties[propId],649&fs.feature[dc1394properties[propId]-DC1394_FEATURE_MIN].value) == DC1394_SUCCESS)650return feature_set.feature[dc1394properties[propId]-DC1394_FEATURE_MIN].value;651}652return -1; // the value of the feature can be 0, so returning 0 as an error is wrong653}654655bool CvCaptureCAM_DC1394_v2_CPP::setProperty(int propId, double value)656{657switch (propId)658{659case CV_CAP_PROP_FRAME_WIDTH:660if(started)661return false;662frameWidth = cvRound(value);663frameHeight = 0;664break;665case CV_CAP_PROP_FRAME_HEIGHT:666if(started)667return false;668frameWidth = 0;669frameHeight = cvRound(value);670break;671case CV_CAP_PROP_FPS:672if(started)673return false;674fps = value;675break;676case CV_CAP_PROP_RECTIFICATION:677CV_LOG_WARNING(NULL, "cap_dc1394: rectification support has been removed from videoio module");678return false;679case CV_CAP_PROP_MODE:680if(started)681return false;682userMode = cvRound(value);683break;684case CV_CAP_PROP_ISO_SPEED:685if(started)686return false;687isoSpeed = cvRound(value);688break;689case CV_CAP_PROP_BUFFERSIZE:690if(started)691return false;692nDMABufs = value;693break;694//The code below is based on coriander, callbacks.c:795, refer to case RANGE_MENU_MAN :695default:696if (propId<CV_CAP_PROP_MAX_DC1394 && dc1394properties[propId]!=-1697&& dcCam)698{699//get the corresponding feature from property-id700dc1394feature_info_t *act_feature = &feature_set.feature[dc1394properties[propId]-DC1394_FEATURE_MIN];701702if (cvRound(value) == CV_CAP_PROP_DC1394_OFF)703{704if ( (act_feature->on_off_capable)705&& (dc1394_feature_set_power(dcCam, act_feature->id, DC1394_OFF) == DC1394_SUCCESS))706{707act_feature->is_on=DC1394_OFF;708return true;709}710return false;711}712//try to turn the feature ON, feature can be ON and at the same time it can be not capable to change state to OFF713if ( (act_feature->is_on == DC1394_OFF) && (act_feature->on_off_capable == DC1394_TRUE))714{715if (dc1394_feature_set_power(dcCam, act_feature->id, DC1394_ON) == DC1394_SUCCESS)716feature_set.feature[dc1394properties[propId]-DC1394_FEATURE_MIN].is_on=DC1394_ON;717}718//turn off absolute mode - the actual value will be stored in the value field,719//otherwise it would be stored into CSR (control and status register) absolute value720if (act_feature->absolute_capable721&& dc1394_feature_set_absolute_control(dcCam, act_feature->id, DC1394_OFF) !=DC1394_SUCCESS)722return false;723else724act_feature->abs_control=DC1394_OFF;725//set AUTO726if (cvRound(value) == CV_CAP_PROP_DC1394_MODE_AUTO)727{728if (dc1394_feature_set_mode(dcCam, act_feature->id, DC1394_FEATURE_MODE_AUTO)!=DC1394_SUCCESS)729return false;730act_feature->current_mode=DC1394_FEATURE_MODE_AUTO;731return true;732}733//set ONE PUSH734if (cvRound(value) == CV_CAP_PROP_DC1394_MODE_ONE_PUSH_AUTO)735{736//have to set to manual first, otherwise one push will be ignored (AVT manual 4.3.0 p. 115)737if (dc1394_feature_set_mode(dcCam, act_feature->id, DC1394_FEATURE_MODE_ONE_PUSH_AUTO)!=DC1394_SUCCESS)738return false;739//will change to740act_feature->current_mode=DC1394_FEATURE_MODE_ONE_PUSH_AUTO;741return true;742}743//set the feature to MANUAL mode,744if (dc1394_feature_set_mode(dcCam, act_feature->id, DC1394_FEATURE_MODE_MANUAL)!=DC1394_SUCCESS)745return false;746else747act_feature->current_mode=DC1394_FEATURE_MODE_MANUAL;748// if property is one of the white balance features treat it in different way749if (propId == CV_CAP_PROP_WHITE_BALANCE_BLUE_U)750{751if (dc1394_feature_whitebalance_set_value(dcCam,cvRound(value), act_feature->RV_value)!=DC1394_SUCCESS)752return false;753else754{755act_feature->BU_value = cvRound(value);756return true;757}758}759if (propId == CV_CAP_PROP_WHITE_BALANCE_RED_V)760{761if (dc1394_feature_whitebalance_set_value(dcCam, act_feature->BU_value, cvRound(value))!=DC1394_SUCCESS)762return false;763else764{765act_feature->RV_value = cvRound(value);766return true;767}768}769770//first: check boundaries771if (value < act_feature->min)772{773value = act_feature->min;774}775else if (value > act_feature->max)776{777value = act_feature->max;778}779780if (dc1394_feature_set_value(dcCam, act_feature->id, cvRound(value)) == DC1394_SUCCESS)781{782act_feature->value = value;783return true;784}785}786return false;787}788return true;789}790791792CvCapture* cvCreateCameraCapture_DC1394_2(int index)793{794CvCaptureCAM_DC1394_v2_CPP* capture = new CvCaptureCAM_DC1394_v2_CPP;795796if (capture->open(index))797return capture;798799delete capture;800return 0;801}802803#endif804805806