Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/videoio/src/cap_dc1394_v2.cpp
16339 views
1
/*M///////////////////////////////////////////////////////////////////////////////////////
2
//
3
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4
//
5
// By downloading, copying, installing or using the software you agree to this license.
6
// If you do not agree to this license, do not download, install,
7
// copy or use the software.
8
//
9
//
10
// Intel License Agreement
11
// For Open Source Computer Vision Library
12
//
13
// Copyright (C) 2000, Intel Corporation, all rights reserved.
14
// Third party copyrights are property of their respective owners.
15
//
16
// Redistribution and use in source and binary forms, with or without modification,
17
// are permitted provided that the following conditions are met:
18
//
19
// * Redistribution's of source code must retain the above copyright notice,
20
// this list of conditions and the following disclaimer.
21
//
22
// * Redistribution's in binary form must reproduce the above copyright notice,
23
// this list of conditions and the following disclaimer in the documentation
24
// and/or other materials provided with the distribution.
25
//
26
// * The name of Intel Corporation may not be used to endorse or promote products
27
// derived from this software without specific prior written permission.
28
//
29
// This software is provided by the copyright holders and contributors "as is" and
30
// any express or implied warranties, including, but not limited to, the implied
31
// warranties of merchantability and fitness for a particular purpose are disclaimed.
32
// In no event shall the Intel Corporation or contributors be liable for any direct,
33
// indirect, incidental, special, exemplary, or consequential damages
34
// (including, but not limited to, procurement of substitute goods or services;
35
// loss of use, data, or profits; or business interruption) however caused
36
// and on any theory of liability, whether in contract, strict liability,
37
// or tort (including negligence or otherwise) arising in any way out of
38
// the use of this software, even if advised of the possibility of such damage.
39
//
40
//M*/
41
42
#include "precomp.hpp"
43
44
#ifdef HAVE_DC1394_2
45
46
#include <unistd.h>
47
#include <stdint.h>
48
#ifdef _WIN32
49
// On Windows, we have no sys/select.h, but we need to pick up
50
// select() which is in winsock2.
51
#ifndef __SYS_SELECT_H__
52
#define __SYS_SELECT_H__ 1
53
#include <winsock2.h>
54
#endif
55
#else
56
#include <sys/select.h>
57
#endif /*_WIN32*/
58
#include <dc1394/dc1394.h>
59
#include <stdlib.h>
60
#include <string.h>
61
62
static dc1394error_t adaptBufferStereoLocal(dc1394video_frame_t *in, dc1394video_frame_t *out)
63
{
64
uint32_t bpp;
65
66
// buffer position is not changed. Size is boubled in Y
67
out->size[0] = in->size[0];
68
out->size[1] = in->size[1] * 2;
69
out->position[0] = in->position[0];
70
out->position[1] = in->position[1];
71
72
// color coding is set to mono8 or raw8.
73
switch (in->color_coding)
74
{
75
case DC1394_COLOR_CODING_RAW16:
76
out->color_coding = DC1394_COLOR_CODING_RAW8;
77
break;
78
case DC1394_COLOR_CODING_MONO16:
79
case DC1394_COLOR_CODING_YUV422:
80
out->color_coding = DC1394_COLOR_CODING_MONO8;
81
break;
82
default:
83
return DC1394_INVALID_COLOR_CODING;
84
}
85
86
// keep the color filter value in all cases. if the format is not raw it will not be further used anyway
87
out->color_filter = in->color_filter;
88
89
// the output YUV byte order must be already set if the buffer is YUV422 at the output
90
// if the output is not YUV we don't care about this field.
91
// Hence nothing to do.
92
// we always convert to 8bits (at this point) we can safely set this value to 8.
93
out->data_depth = 8;
94
95
// don't know what to do with stride... >>>> TODO: STRIDE SHOULD BE TAKEN INTO ACCOUNT... <<<<
96
// out->stride=??
97
// the video mode should not change. Color coding and other stuff can be accessed in specific fields of this struct
98
out->video_mode = in->video_mode;
99
100
// padding is kept:
101
out->padding_bytes = in->padding_bytes;
102
103
// image bytes changes: >>>> TODO: STRIDE SHOULD BE TAKEN INTO ACCOUNT... <<<<
104
dc1394_get_color_coding_bit_size(out->color_coding, &bpp);
105
out->image_bytes = (out->size[0] * out->size[1] * bpp) / 8;
106
107
// total is image_bytes + padding_bytes
108
out->total_bytes = out->image_bytes + out->padding_bytes;
109
110
// bytes-per-packet and packets_per_frame are internal data that can be kept as is.
111
out->packet_size = in->packet_size;
112
out->packets_per_frame = in->packets_per_frame;
113
114
// timestamp, frame_behind, id and camera are copied too:
115
out->timestamp = in->timestamp;
116
out->frames_behind = in->frames_behind;
117
out->camera = in->camera;
118
out->id = in->id;
119
120
// verify memory allocation:
121
if (out->total_bytes > out->allocated_image_bytes)
122
{
123
free(out->image);
124
out->image = (uint8_t*)malloc(out->total_bytes * sizeof(uint8_t));
125
out->allocated_image_bytes = out->total_bytes;
126
}
127
128
// Copy padding bytes:
129
memcpy(&(out->image[out->image_bytes]), &(in->image[in->image_bytes]), out->padding_bytes);
130
out->little_endian = DC1394_FALSE; // not used before 1.32 is out.
131
out->data_in_padding = DC1394_FALSE; // not used before 1.32 is out.
132
return DC1394_SUCCESS;
133
}
134
135
static dc1394error_t dc1394_deinterlace_stereo_frames_fixed(dc1394video_frame_t *in,
136
dc1394video_frame_t *out, dc1394stereo_method_t method)
137
{
138
if((in->color_coding == DC1394_COLOR_CODING_RAW16) ||
139
(in->color_coding == DC1394_COLOR_CODING_MONO16) ||
140
(in->color_coding == DC1394_COLOR_CODING_YUV422))
141
{
142
switch (method)
143
{
144
145
case DC1394_STEREO_METHOD_INTERLACED:
146
adaptBufferStereoLocal(in, out);
147
//FIXED by AB:
148
// dc1394_deinterlace_stereo(in->image, out->image, in->size[0], in->size[1]);
149
dc1394_deinterlace_stereo(in->image, out->image, out->size[0], out->size[1]);
150
break;
151
152
case DC1394_STEREO_METHOD_FIELD:
153
adaptBufferStereoLocal(in, out);
154
memcpy(out->image, in->image, out->image_bytes);
155
break;
156
}
157
158
return DC1394_INVALID_STEREO_METHOD;
159
}
160
else
161
return DC1394_FUNCTION_NOT_SUPPORTED;
162
}
163
164
struct CvDC1394
165
{
166
CvDC1394();
167
~CvDC1394();
168
169
dc1394_t* dc;
170
fd_set camFds;
171
};
172
173
CvDC1394::CvDC1394()
174
{
175
dc = dc1394_new();
176
FD_ZERO(&camFds);
177
}
178
179
CvDC1394::~CvDC1394()
180
{
181
if (dc)
182
dc1394_free(dc);
183
dc = 0;
184
}
185
186
static CvDC1394 dc1394;
187
188
class CvCaptureCAM_DC1394_v2_CPP : public CvCapture
189
{
190
public:
191
static int dc1394properties[CV_CAP_PROP_MAX_DC1394];
192
CvCaptureCAM_DC1394_v2_CPP();
193
virtual ~CvCaptureCAM_DC1394_v2_CPP()
194
{
195
close();
196
}
197
198
virtual bool open(int index);
199
virtual void close();
200
201
virtual double getProperty(int) const CV_OVERRIDE;
202
virtual bool setProperty(int, double) CV_OVERRIDE;
203
virtual bool grabFrame() CV_OVERRIDE;
204
virtual IplImage* retrieveFrame(int) CV_OVERRIDE;
205
virtual int getCaptureDomain() CV_OVERRIDE { return CV_CAP_DC1394; }
206
207
208
protected:
209
virtual bool startCapture();
210
211
uint64_t guid;
212
dc1394camera_t* dcCam;
213
int isoSpeed;
214
int videoMode;
215
int frameWidth, frameHeight;
216
double fps;
217
int nDMABufs;
218
bool started;
219
int userMode;
220
221
enum { VIDERE = 0x5505 };
222
223
int cameraId;
224
bool colorStereo;
225
dc1394bayer_method_t bayer;
226
dc1394color_filter_t bayerFilter;
227
228
enum { NIMG = 2 };
229
IplImage *img[NIMG];
230
dc1394video_frame_t* frameC;
231
int nimages;
232
233
dc1394featureset_t feature_set;
234
};
235
//mapping CV_CAP_PROP_ to DC1394_FEATUREs
236
int CvCaptureCAM_DC1394_v2_CPP::dc1394properties[CV_CAP_PROP_MAX_DC1394] = {
237
-1, //no corresponding feature for CV_CAP_PROP_POS_MSEC
238
-1,-1,-1,-1,
239
DC1394_FEATURE_FRAME_RATE, //CV_CAP_PROP_FPS - fps can be set for format 7 only!
240
-1,-1,-1,-1,
241
DC1394_FEATURE_BRIGHTNESS, //CV_CAP_PROP_BRIGHTNESS 10
242
-1,
243
DC1394_FEATURE_SATURATION, //CV_CAP_PROP_SATURATION
244
DC1394_FEATURE_HUE,
245
DC1394_FEATURE_GAIN,
246
DC1394_FEATURE_SHUTTER, //CV_CAP_PROP_EXPOSURE
247
-1, //CV_CAP_PROP_CONVERT_RGB
248
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
249
-1,-1,
250
DC1394_FEATURE_SHARPNESS, //20
251
DC1394_FEATURE_EXPOSURE, //CV_CAP_PROP_AUTO_EXPOSURE - this is auto exposure according to the IIDC standard
252
DC1394_FEATURE_GAMMA, //CV_CAP_PROP_GAMMA
253
DC1394_FEATURE_TEMPERATURE, //CV_CAP_PROP_TEMPERATURE
254
DC1394_FEATURE_TRIGGER, //CV_CAP_PROP_TRIGGER
255
DC1394_FEATURE_TRIGGER_DELAY, //CV_CAP_PROP_TRIGGER_DELAY
256
DC1394_FEATURE_WHITE_BALANCE, //CV_CAP_PROP_WHITE_BALANCE_RED_V
257
DC1394_FEATURE_ZOOM, //CV_CAP_PROP_ZOOM
258
DC1394_FEATURE_FOCUS, //CV_CAP_PROP_FOCUS
259
-1 //CV_CAP_PROP_GUID
260
};
261
CvCaptureCAM_DC1394_v2_CPP::CvCaptureCAM_DC1394_v2_CPP()
262
{
263
guid = 0;
264
dcCam = 0;
265
isoSpeed = 400;
266
fps = 15;
267
// Reset the value here to 1 in order to ensure only a single frame is stored in the buffer!
268
nDMABufs = 8;
269
started = false;
270
cameraId = 0;
271
colorStereo = false;
272
bayer = DC1394_BAYER_METHOD_BILINEAR;
273
bayerFilter = DC1394_COLOR_FILTER_GRBG;
274
frameWidth = 640;
275
frameHeight = 480;
276
277
for (int i = 0; i < NIMG; i++)
278
img[i] = 0;
279
frameC = 0;
280
nimages = 1;
281
userMode = -1;
282
}
283
284
285
bool CvCaptureCAM_DC1394_v2_CPP::startCapture()
286
{
287
int i;
288
int code = 0;
289
if (!dcCam)
290
return false;
291
if (isoSpeed > 0)
292
{
293
// if capable set operation mode to 1394b for iso speeds above 400
294
if (isoSpeed > 400 && dcCam->bmode_capable == DC1394_TRUE)
295
{
296
dc1394_video_set_operation_mode(dcCam, DC1394_OPERATION_MODE_1394B);
297
}
298
code = dc1394_video_set_iso_speed(dcCam,
299
isoSpeed <= 100 ? DC1394_ISO_SPEED_100 :
300
isoSpeed <= 200 ? DC1394_ISO_SPEED_200 :
301
isoSpeed <= 400 ? DC1394_ISO_SPEED_400 :
302
isoSpeed <= 800 ? DC1394_ISO_SPEED_800 :
303
isoSpeed == 1600 ? DC1394_ISO_SPEED_1600 :
304
DC1394_ISO_SPEED_3200);
305
}
306
307
// should a specific mode be used
308
if (userMode >= 0)
309
310
{
311
dc1394video_mode_t wantedMode;
312
dc1394video_modes_t videoModes;
313
dc1394_video_get_supported_modes(dcCam, &videoModes);
314
315
//set mode from number, for example the second supported mode, i.e userMode = 1
316
317
if (userMode < (int)videoModes.num)
318
{
319
wantedMode = videoModes.modes[userMode];
320
}
321
322
//set modes directly from DC134 constants (from dc1394video_mode_t)
323
else if ((userMode >= DC1394_VIDEO_MODE_MIN) && (userMode <= DC1394_VIDEO_MODE_MAX ))
324
{
325
//search for wanted mode, to check if camera supports it
326
int j = 0;
327
while ((j< (int)videoModes.num) && videoModes.modes[j]!=userMode)
328
{
329
j++;
330
}
331
332
if ((int)videoModes.modes[j]==userMode)
333
{
334
wantedMode = videoModes.modes[j];
335
}
336
else
337
{
338
userMode = -1; // wanted mode not supported, search for best mode
339
}
340
}
341
else
342
{
343
userMode = -1; // wanted mode not supported, search for best mode
344
}
345
//if userMode is available: set it and update size
346
if (userMode != -1)
347
{
348
code = dc1394_video_set_mode(dcCam, wantedMode);
349
uint32_t width, height;
350
dc1394_get_image_size_from_video_mode(dcCam, wantedMode, &width, &height);
351
frameWidth = (int)width;
352
frameHeight = (int)height;
353
}
354
}
355
356
if (userMode == -1 && (frameWidth > 0 || frameHeight > 0))
357
{
358
dc1394video_mode_t bestMode = (dc1394video_mode_t) - 1;
359
dc1394video_modes_t videoModes;
360
dc1394_video_get_supported_modes(dcCam, &videoModes);
361
for (i = 0; i < (int)videoModes.num; i++)
362
{
363
dc1394video_mode_t mode = videoModes.modes[i];
364
if (mode >= DC1394_VIDEO_MODE_FORMAT7_MIN && mode <= DC1394_VIDEO_MODE_FORMAT7_MAX)
365
continue;
366
int pref = -1;
367
dc1394color_coding_t colorCoding;
368
dc1394_get_color_coding_from_video_mode(dcCam, mode, &colorCoding);
369
370
uint32_t width, height;
371
dc1394_get_image_size_from_video_mode(dcCam, mode, &width, &height);
372
if ((int)width == frameWidth || (int)height == frameHeight)
373
{
374
if (colorCoding == DC1394_COLOR_CODING_RGB8 ||
375
colorCoding == DC1394_COLOR_CODING_RAW8)
376
{
377
bestMode = mode;
378
break;
379
}
380
381
if (colorCoding == DC1394_COLOR_CODING_YUV411 ||
382
colorCoding == DC1394_COLOR_CODING_YUV422 ||
383
(colorCoding == DC1394_COLOR_CODING_YUV444 &&
384
pref < 1))
385
{
386
bestMode = mode;
387
pref = 1;
388
break;
389
}
390
391
if (colorCoding == DC1394_COLOR_CODING_MONO8)
392
{
393
bestMode = mode;
394
pref = 0;
395
}
396
}
397
}
398
if ((int)bestMode >= 0)
399
code = dc1394_video_set_mode(dcCam, bestMode);
400
}
401
402
if (fps > 0)
403
{
404
dc1394video_mode_t mode;
405
dc1394framerates_t framerates;
406
double minDiff = DBL_MAX;
407
dc1394framerate_t bestFps = (dc1394framerate_t) - 1;
408
409
dc1394_video_get_mode(dcCam, &mode);
410
dc1394_video_get_supported_framerates(dcCam, mode, &framerates);
411
412
for (i = 0; i < (int)framerates.num; i++)
413
{
414
dc1394framerate_t ifps = framerates.framerates[i];
415
double fps1 = (1 << (ifps - DC1394_FRAMERATE_1_875)) * 1.875;
416
double diff = fabs(fps1 - fps);
417
if (diff < minDiff)
418
{
419
minDiff = diff;
420
bestFps = ifps;
421
}
422
}
423
if ((int)bestFps >= 0)
424
code = dc1394_video_set_framerate(dcCam, bestFps);
425
}
426
427
if (cameraId == VIDERE)
428
{
429
bayerFilter = DC1394_COLOR_FILTER_GBRG;
430
nimages = 2;
431
uint32_t value = 0;
432
dc1394_get_control_register(dcCam, 0x50c, &value);
433
colorStereo = (value & 0x80000000) != 0;
434
}
435
436
code = dc1394_capture_setup(dcCam, nDMABufs, DC1394_CAPTURE_FLAGS_DEFAULT);
437
if (code >= 0)
438
{
439
FD_SET(dc1394_capture_get_fileno(dcCam), &dc1394.camFds);
440
dc1394_video_set_transmission(dcCam, DC1394_ON);
441
started = true;
442
}
443
444
return code >= 0;
445
}
446
447
bool CvCaptureCAM_DC1394_v2_CPP::open(int index)
448
{
449
bool result = false;
450
dc1394camera_list_t* cameraList = 0;
451
dc1394error_t err;
452
453
close();
454
455
if (!dc1394.dc)
456
goto _exit_;
457
458
err = dc1394_camera_enumerate(dc1394.dc, &cameraList);
459
if (err < 0 || !cameraList || (unsigned)index >= (unsigned)cameraList->num)
460
goto _exit_;
461
462
guid = cameraList->ids[index].guid;
463
dcCam = dc1394_camera_new(dc1394.dc, guid);
464
if (!dcCam)
465
goto _exit_;
466
467
cameraId = dcCam->vendor_id;
468
//get all features
469
if (dc1394_feature_get_all(dcCam,&feature_set) == DC1394_SUCCESS)
470
result = true;
471
else
472
result = false;
473
474
_exit_:
475
if (cameraList)
476
dc1394_camera_free_list(cameraList);
477
478
return result;
479
}
480
481
void CvCaptureCAM_DC1394_v2_CPP::close()
482
{
483
if (dcCam)
484
{
485
// check for fileno valid before using
486
int fileno=dc1394_capture_get_fileno(dcCam);
487
488
if (fileno>=0 && FD_ISSET(fileno, &dc1394.camFds))
489
FD_CLR(fileno, &dc1394.camFds);
490
dc1394_video_set_transmission(dcCam, DC1394_OFF);
491
dc1394_capture_stop(dcCam);
492
dc1394_camera_free(dcCam);
493
dcCam = 0;
494
started = false;
495
}
496
497
for (int i = 0; i < NIMG; i++)
498
{
499
cvReleaseImage(&img[i]);
500
}
501
if (frameC)
502
{
503
if (frameC->image)
504
free(frameC->image);
505
free(frameC);
506
frameC = 0;
507
}
508
}
509
510
511
bool CvCaptureCAM_DC1394_v2_CPP::grabFrame()
512
{
513
dc1394capture_policy_t policy = DC1394_CAPTURE_POLICY_WAIT;
514
bool code = false, isColor;
515
dc1394video_frame_t *dcFrame = 0, *fs = 0;
516
int i, nch;
517
518
if (!dcCam || (!started && !startCapture()))
519
return false;
520
521
dc1394_capture_dequeue(dcCam, policy, &dcFrame);
522
523
if (!dcFrame)
524
return false;
525
526
if (/*dcFrame->frames_behind > 1 ||*/ dc1394_capture_is_frame_corrupt(dcCam, dcFrame) == DC1394_TRUE)
527
{
528
goto _exit_;
529
}
530
531
isColor = dcFrame->color_coding != DC1394_COLOR_CODING_MONO8 &&
532
dcFrame->color_coding != DC1394_COLOR_CODING_MONO16 &&
533
dcFrame->color_coding != DC1394_COLOR_CODING_MONO16S;
534
535
if (nimages == 2)
536
{
537
fs = (dc1394video_frame_t*)calloc(1, sizeof(*fs));
538
539
//dc1394_deinterlace_stereo_frames(dcFrame, fs, DC1394_STEREO_METHOD_INTERLACED);
540
dc1394_deinterlace_stereo_frames_fixed(dcFrame, fs, DC1394_STEREO_METHOD_INTERLACED);
541
542
dc1394_capture_enqueue(dcCam, dcFrame); // release the captured frame as soon as possible
543
dcFrame = 0;
544
if (!fs->image)
545
goto _exit_;
546
isColor = colorStereo;
547
}
548
nch = isColor ? 3 : 1;
549
550
for (i = 0; i < nimages; i++)
551
{
552
IplImage fhdr;
553
dc1394video_frame_t f = fs ? *fs : *dcFrame, *fc = &f;
554
f.size[1] /= nimages;
555
f.image += f.size[0] * f.size[1] * i; // TODO: make it more universal
556
if (isColor)
557
{
558
if (!frameC)
559
frameC = (dc1394video_frame_t*)calloc(1, sizeof(*frameC));
560
frameC->color_coding = nch == 3 ? DC1394_COLOR_CODING_RGB8 : DC1394_COLOR_CODING_MONO8;
561
if (nimages == 1)
562
{
563
dc1394_convert_frames(&f, frameC);
564
dc1394_capture_enqueue(dcCam, dcFrame);
565
dcFrame = 0;
566
}
567
else
568
{
569
f.color_filter = bayerFilter;
570
dc1394_debayer_frames(&f, frameC, bayer);
571
}
572
fc = frameC;
573
}
574
if (!img[i])
575
img[i] = cvCreateImage(cvSize(fc->size[0], fc->size[1]), 8, nch);
576
cvInitImageHeader(&fhdr, cvSize(fc->size[0], fc->size[1]), 8, nch);
577
cvSetData(&fhdr, fc->image, fc->size[0]*nch);
578
579
// Swap R&B channels:
580
if (nch==3)
581
cvConvertImage(&fhdr,&fhdr,CV_CVTIMG_SWAP_RB);
582
583
cvCopy(&fhdr, img[i]);
584
}
585
586
code = true;
587
588
_exit_:
589
if (dcFrame)
590
dc1394_capture_enqueue(dcCam, dcFrame);
591
if (fs)
592
{
593
if (fs->image)
594
free(fs->image);
595
free(fs);
596
}
597
598
return code;
599
}
600
601
IplImage* CvCaptureCAM_DC1394_v2_CPP::retrieveFrame(int idx)
602
{
603
return 0 <= idx && idx < nimages ? img[idx] : 0;
604
}
605
606
double CvCaptureCAM_DC1394_v2_CPP::getProperty(int propId) const
607
{
608
// Simulate mutable (C++11-like) member variable
609
dc1394featureset_t& fs = const_cast<dc1394featureset_t&>(feature_set);
610
611
switch (propId)
612
{
613
case CV_CAP_PROP_FRAME_WIDTH:
614
return frameWidth ? frameWidth : frameHeight*4 / 3;
615
case CV_CAP_PROP_FRAME_HEIGHT:
616
return frameHeight ? frameHeight : frameWidth*3 / 4;
617
case CV_CAP_PROP_FPS:
618
return fps;
619
case CV_CAP_PROP_RECTIFICATION:
620
CV_LOG_WARNING(NULL, "cap_dc1394: rectification support has been removed from videoio module");
621
return 0;
622
case CV_CAP_PROP_WHITE_BALANCE_BLUE_U:
623
if (dc1394_feature_whitebalance_get_value(dcCam,
624
&fs.feature[DC1394_FEATURE_WHITE_BALANCE-DC1394_FEATURE_MIN].BU_value,
625
&fs.feature[DC1394_FEATURE_WHITE_BALANCE-DC1394_FEATURE_MIN].RV_value) == DC1394_SUCCESS)
626
return feature_set.feature[DC1394_FEATURE_WHITE_BALANCE-DC1394_FEATURE_MIN].BU_value;
627
break;
628
case CV_CAP_PROP_WHITE_BALANCE_RED_V:
629
if (dc1394_feature_whitebalance_get_value(dcCam,
630
&fs.feature[DC1394_FEATURE_WHITE_BALANCE-DC1394_FEATURE_MIN].BU_value,
631
&fs.feature[DC1394_FEATURE_WHITE_BALANCE-DC1394_FEATURE_MIN].RV_value) == DC1394_SUCCESS)
632
return feature_set.feature[DC1394_FEATURE_WHITE_BALANCE-DC1394_FEATURE_MIN].RV_value;
633
break;
634
case CV_CAP_PROP_GUID:
635
//the least 32 bits are enough to identify the camera
636
return (double) (guid & 0x00000000FFFFFFFF);
637
break;
638
case CV_CAP_PROP_MODE:
639
return (double) userMode;
640
break;
641
case CV_CAP_PROP_ISO_SPEED:
642
return (double) isoSpeed;
643
case CV_CAP_PROP_BUFFERSIZE:
644
return (double) nDMABufs;
645
default:
646
if (propId<CV_CAP_PROP_MAX_DC1394 && dc1394properties[propId]!=-1
647
&& dcCam)
648
//&& feature_set.feature[dc1394properties[propId]-DC1394_FEATURE_MIN].on_off_capable)
649
if (dc1394_feature_get_value(dcCam,(dc1394feature_t)dc1394properties[propId],
650
&fs.feature[dc1394properties[propId]-DC1394_FEATURE_MIN].value) == DC1394_SUCCESS)
651
return feature_set.feature[dc1394properties[propId]-DC1394_FEATURE_MIN].value;
652
}
653
return -1; // the value of the feature can be 0, so returning 0 as an error is wrong
654
}
655
656
bool CvCaptureCAM_DC1394_v2_CPP::setProperty(int propId, double value)
657
{
658
switch (propId)
659
{
660
case CV_CAP_PROP_FRAME_WIDTH:
661
if(started)
662
return false;
663
frameWidth = cvRound(value);
664
frameHeight = 0;
665
break;
666
case CV_CAP_PROP_FRAME_HEIGHT:
667
if(started)
668
return false;
669
frameWidth = 0;
670
frameHeight = cvRound(value);
671
break;
672
case CV_CAP_PROP_FPS:
673
if(started)
674
return false;
675
fps = value;
676
break;
677
case CV_CAP_PROP_RECTIFICATION:
678
CV_LOG_WARNING(NULL, "cap_dc1394: rectification support has been removed from videoio module");
679
return false;
680
case CV_CAP_PROP_MODE:
681
if(started)
682
return false;
683
userMode = cvRound(value);
684
break;
685
case CV_CAP_PROP_ISO_SPEED:
686
if(started)
687
return false;
688
isoSpeed = cvRound(value);
689
break;
690
case CV_CAP_PROP_BUFFERSIZE:
691
if(started)
692
return false;
693
nDMABufs = value;
694
break;
695
//The code below is based on coriander, callbacks.c:795, refer to case RANGE_MENU_MAN :
696
default:
697
if (propId<CV_CAP_PROP_MAX_DC1394 && dc1394properties[propId]!=-1
698
&& dcCam)
699
{
700
//get the corresponding feature from property-id
701
dc1394feature_info_t *act_feature = &feature_set.feature[dc1394properties[propId]-DC1394_FEATURE_MIN];
702
703
if (cvRound(value) == CV_CAP_PROP_DC1394_OFF)
704
{
705
if ( (act_feature->on_off_capable)
706
&& (dc1394_feature_set_power(dcCam, act_feature->id, DC1394_OFF) == DC1394_SUCCESS))
707
{
708
act_feature->is_on=DC1394_OFF;
709
return true;
710
}
711
return false;
712
}
713
//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
714
if ( (act_feature->is_on == DC1394_OFF) && (act_feature->on_off_capable == DC1394_TRUE))
715
{
716
if (dc1394_feature_set_power(dcCam, act_feature->id, DC1394_ON) == DC1394_SUCCESS)
717
feature_set.feature[dc1394properties[propId]-DC1394_FEATURE_MIN].is_on=DC1394_ON;
718
}
719
//turn off absolute mode - the actual value will be stored in the value field,
720
//otherwise it would be stored into CSR (control and status register) absolute value
721
if (act_feature->absolute_capable
722
&& dc1394_feature_set_absolute_control(dcCam, act_feature->id, DC1394_OFF) !=DC1394_SUCCESS)
723
return false;
724
else
725
act_feature->abs_control=DC1394_OFF;
726
//set AUTO
727
if (cvRound(value) == CV_CAP_PROP_DC1394_MODE_AUTO)
728
{
729
if (dc1394_feature_set_mode(dcCam, act_feature->id, DC1394_FEATURE_MODE_AUTO)!=DC1394_SUCCESS)
730
return false;
731
act_feature->current_mode=DC1394_FEATURE_MODE_AUTO;
732
return true;
733
}
734
//set ONE PUSH
735
if (cvRound(value) == CV_CAP_PROP_DC1394_MODE_ONE_PUSH_AUTO)
736
{
737
//have to set to manual first, otherwise one push will be ignored (AVT manual 4.3.0 p. 115)
738
if (dc1394_feature_set_mode(dcCam, act_feature->id, DC1394_FEATURE_MODE_ONE_PUSH_AUTO)!=DC1394_SUCCESS)
739
return false;
740
//will change to
741
act_feature->current_mode=DC1394_FEATURE_MODE_ONE_PUSH_AUTO;
742
return true;
743
}
744
//set the feature to MANUAL mode,
745
if (dc1394_feature_set_mode(dcCam, act_feature->id, DC1394_FEATURE_MODE_MANUAL)!=DC1394_SUCCESS)
746
return false;
747
else
748
act_feature->current_mode=DC1394_FEATURE_MODE_MANUAL;
749
// if property is one of the white balance features treat it in different way
750
if (propId == CV_CAP_PROP_WHITE_BALANCE_BLUE_U)
751
{
752
if (dc1394_feature_whitebalance_set_value(dcCam,cvRound(value), act_feature->RV_value)!=DC1394_SUCCESS)
753
return false;
754
else
755
{
756
act_feature->BU_value = cvRound(value);
757
return true;
758
}
759
}
760
if (propId == CV_CAP_PROP_WHITE_BALANCE_RED_V)
761
{
762
if (dc1394_feature_whitebalance_set_value(dcCam, act_feature->BU_value, cvRound(value))!=DC1394_SUCCESS)
763
return false;
764
else
765
{
766
act_feature->RV_value = cvRound(value);
767
return true;
768
}
769
}
770
771
//first: check boundaries
772
if (value < act_feature->min)
773
{
774
value = act_feature->min;
775
}
776
else if (value > act_feature->max)
777
{
778
value = act_feature->max;
779
}
780
781
if (dc1394_feature_set_value(dcCam, act_feature->id, cvRound(value)) == DC1394_SUCCESS)
782
{
783
act_feature->value = value;
784
return true;
785
}
786
}
787
return false;
788
}
789
return true;
790
}
791
792
793
CvCapture* cvCreateCameraCapture_DC1394_2(int index)
794
{
795
CvCaptureCAM_DC1394_v2_CPP* capture = new CvCaptureCAM_DC1394_v2_CPP;
796
797
if (capture->open(index))
798
return capture;
799
800
delete capture;
801
return 0;
802
}
803
804
#endif
805
806