forked from jmercier/PyDC1394
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvideo1394.pyx
1270 lines (998 loc) · 50.3 KB
/
video1394.pyx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import threading
import sys
import select
import thread
import time
from dc1394 cimport *
import codebench.events as events
import numpy as np
cimport numpy as np
from cpython cimport Py_INCREF, Py_DECREF
cdef dict color_coding = {
DC1394_COLOR_CODING_MONO8 : "MONO8",
DC1394_COLOR_CODING_YUV411 : "YUV411",
DC1394_COLOR_CODING_YUV422 : "YUV422",
DC1394_COLOR_CODING_YUV444 : "YUV444",
DC1394_COLOR_CODING_RGB8 : "RGB8",
DC1394_COLOR_CODING_MONO16 : "MONO16",
DC1394_COLOR_CODING_RGB16 : "RGB16",
DC1394_COLOR_CODING_MONO16S : "MONO16S",
DC1394_COLOR_CODING_RGB16S : "RGB16S",
DC1394_COLOR_CODING_RAW8 : "RAW8",
DC1394_COLOR_CODING_RAW16 : "RAW16" }
VIDEO_MODE_1600x1200_RGB8 = DC1394_VIDEO_MODE_1600x1200_RGB8
VIDEO_MODE_1280x960_RGB8 = DC1394_VIDEO_MODE_1280x960_RGB8
VIDEO_MODE_1024x768_RGB8 = DC1394_VIDEO_MODE_1024x768_RGB8
VIDEO_MODE_800x600_RGB8 = DC1394_VIDEO_MODE_800x600_RGB8
VIDEO_MODE_640x480_RGB8 = DC1394_VIDEO_MODE_640x480_RGB8
VIDEO_MODE_1600x1200_YUV422 = DC1394_VIDEO_MODE_1600x1200_YUV422
VIDEO_MODE_1280x960_YUV422 = DC1394_VIDEO_MODE_1280x960_YUV422
VIDEO_MODE_1024x768_YUV422 = DC1394_VIDEO_MODE_1024x768_YUV422
VIDEO_MODE_800x600_YUV422 = DC1394_VIDEO_MODE_800x600_YUV422
VIDEO_MODE_640x480_YUV422 = DC1394_VIDEO_MODE_640x480_YUV422
VIDEO_MODE_640x480_YUV411 = DC1394_VIDEO_MODE_640x480_YUV411
VIDEO_MODE_1280x960_MONO8 = DC1394_VIDEO_MODE_1280x960_MONO8
VIDEO_MODE_1024x768_MONO8 = DC1394_VIDEO_MODE_1024x768_MONO8
VIDEO_MODE_800x600_MONO8 = DC1394_VIDEO_MODE_800x600_MONO8
VIDEO_MODE_640x480_MONO8 = DC1394_VIDEO_MODE_640x480_MONO8
VIDEO_MODE_1600x1200_MONO16 = DC1394_VIDEO_MODE_1600x1200_MONO16
VIDEO_MODE_1280x960_MONO16 = DC1394_VIDEO_MODE_1280x960_MONO16
VIDEO_MODE_1600x1200_MONO8 = DC1394_VIDEO_MODE_1600x1200_MONO8
VIDEO_MODE_1024x768_MONO16 = DC1394_VIDEO_MODE_1024x768_MONO16
VIDEO_MODE_800x600_MONO16 = DC1394_VIDEO_MODE_800x600_MONO16
VIDEO_MODE_640x480_MONO16 = DC1394_VIDEO_MODE_640x480_MONO16
FRAMERATE_1_875 = DC1394_FRAMERATE_1_875
FRAMERATE_3_75 = DC1394_FRAMERATE_3_75
FRAMERATE_7_5 = DC1394_FRAMERATE_7_5
FRAMERATE_15 = DC1394_FRAMERATE_15
FRAMERATE_30 = DC1394_FRAMERATE_30
FRAMERATE_60 = DC1394_FRAMERATE_60
FRAMERATE_120 = DC1394_FRAMERATE_120
FRAMERATE_240 = DC1394_FRAMERATE_240
ISO_SPEED_100 = DC1394_ISO_SPEED_100
ISO_SPEED_200 = DC1394_ISO_SPEED_200
ISO_SPEED_400 = DC1394_ISO_SPEED_400
ISO_SPEED_800 = DC1394_ISO_SPEED_800
ISO_SPEED_1600 = DC1394_ISO_SPEED_1600
ISO_SPEED_3200 = DC1394_ISO_SPEED_3200
OPERATION_MODE_LEGACY = DC1394_OPERATION_MODE_LEGACY
OPERATION_MODE_1394B = DC1394_OPERATION_MODE_1394B
cdef list DC1394ISOSpeedTable = [
DC1394_ISO_SPEED_100,
DC1394_ISO_SPEED_200,
DC1394_ISO_SPEED_400,
DC1394_ISO_SPEED_800,
DC1394_ISO_SPEED_1600,
DC1394_ISO_SPEED_3200 ]
cdef dict DC1394NumpyColorCoding = {
DC1394_COLOR_CODING_MONO8 : np.uint8(),
DC1394_COLOR_CODING_YUV411 : np.uint8(),
DC1394_COLOR_CODING_YUV422 : np.uint8(),
DC1394_COLOR_CODING_YUV444 : np.uint8(),
DC1394_COLOR_CODING_RGB8 : np.dtype([("R", np.uint8), ("G", np.uint8), ("B", np.uint8)]),
DC1394_COLOR_CODING_MONO16 : np.uint16(),
DC1394_COLOR_CODING_RGB16 : np.dtype([("R", np.uint16), ("G", np.uint16), ("B", np.uint16)]),
DC1394_COLOR_CODING_MONO16S : np.int16(),
DC1394_COLOR_CODING_RGB16S : np.int16(),
DC1394_COLOR_CODING_RAW8 : np.uint8(),
DC1394_COLOR_CODING_RAW16 : np.uint16(),
}
cdef dict DC1394NumpyColorCoding2 = {
DC1394_COLOR_CODING_MONO8 : ("u8", 1),
DC1394_COLOR_CODING_YUV411 : ("u8", 1),
DC1394_COLOR_CODING_YUV422 : ("u8", 3),
DC1394_COLOR_CODING_YUV444 : ("u8", 1),
DC1394_COLOR_CODING_RGB8 : ("u8", 3),
DC1394_COLOR_CODING_MONO16 : ("u16", 1),
DC1394_COLOR_CODING_RGB16 : ("u16", 3),
DC1394_COLOR_CODING_MONO16S : ("i16", 1),
DC1394_COLOR_CODING_RGB16S : ("i16", 3),
DC1394_COLOR_CODING_RAW8 : ("u8", 1),
DC1394_COLOR_CODING_RAW16 : ("u16", 1),
}
class DC1394Error(Exception): pass
cdef inline bint DC1394SafeCall(dc1394error_t error, bint raise_event=True) except -1:
cdef const_char_ptr errstr
cdef bint status = True
if DC1394_SUCCESS != error:
errstr = dc1394_error_get_string(error)
if raise_event:
raise DC1394Error("%s - no %d" % (errstr, error))
status = False
return status
cdef inline dict __dc1394_array_interface__(dc1394video_frame_t * frame):
cdef str dtype
cdef uint8_t nbytes
(dtype, nbytes) = DC1394NumpyColorCoding2[frame.color_coding]
cdef str endianess = ">%s" % dtype
if (frame.little_endian == DC1394_TRUE):
endianess = "%s%s" % ("<", dtype)
return dict(data= < np.intp_t > frame.image,
shape=(frame.size[1], frame.size[0], nbytes),
strides=(frame.stride, nbytes, 1),
version=3,
typestr=endianess)
cdef class FrameObject(object):
def __init__(self, interface):
self.__array_interface__ = interface
cdef class DC1394Context(object):
"""
This object represent a DC1394 context which is needed for further calling
of dc1394 function
"""
cdef dc1394_t * dc1394
def __cinit__(self):
self.dc1394 = dc1394_new()
def __dealloc__(self):
dc1394_free(self.dc1394)
def __get_number_of_devices__(self):
cdef dc1394camera_list_t * camera_list
DC1394SafeCall(dc1394_camera_enumerate(self.dc1394, & camera_list))
return camera_list.num
numberOfDevices = property(__get_number_of_devices__)
cpdef list enumerateCameras(self):
cdef dc1394camera_list_t * camera_lst
cdef list return_value
DC1394SafeCall(dc1394_camera_enumerate(self.dc1394, & camera_lst))
return_value = [camera_lst.ids[i] for i in xrange(camera_lst.num)]
dc1394_camera_free_list(camera_lst)
return return_value
cpdef createCamera(self, int cid= -1, int64_t guid= -1):
camdesc = None
enumCam = self.enumerateCameras()
if not enumCam:
return None
if cid >= len(enumCam):
return None
if guid > 0:
for cam in enumCam:
if cam['guid'] == guid:
camdesc = cam
break
if not camdesc:
return None
if not camdesc:
camdesc = enumCam[cid]
cam = None
try:
cam = DC1394Camera(self, camdesc['guid'], unit=camdesc['unit'])
except BaseException as e:
print("Error: %s" % e)
print("The list of camera %s" % self.enumerateCameras())
return cam
cdef class DC1394Camera(object):
cdef dc1394camera_t * cam
cdef DC1394Context ctx
cdef dict available_modes
cdef bint stop_event
cdef bint running
cdef bint force_rgb8
cdef object __grab_event__
cdef object __init_event__
cdef object __stop_event__
cdef object capture_loop
cdef object cam_server
cdef object sem_capture
cdef dict available_features
cdef dict unavailable_features
cdef dict available_features_string
# TODO be dynamic buffer about pixel conversion
cdef uint8_t pixel_convert[480000 * 3]
cdef np.ndarray arr
cdef char *orig_ptr
def __cinit__(self, DC1394Context ctx, uint64_t guid, int unit= -1):
self.ctx = ctx
if unit != -1:
self.cam = dc1394_camera_new_unit(ctx.dc1394, guid, unit)
else:
self.cam = dc1394_camera_new(ctx.dc1394, guid);
if not self.cam:
raise DC1394Error("No camera detected, guid %d." % guid)
self.populate_capabilities()
self.force_rgb8 = False
self.running = False
self.stop_event = False
self.sem_capture = threading.Semaphore()
self.__grab_event__ = events.Event()
self.__init_event__ = events.Event()
self.__stop_event__ = events.Event()
def __dealloc__(self):
self.arr.data = self.orig_ptr
self.arr = None
def safe_clean(self, free_camera=True):
if not self.cam:
return True
if self.running:
self.stop()
if free_camera:
dc1394_camera_free(self.cam)
self.cam = NULL
def resetBus(self):
if self.cam:
DC1394SafeCall(dc1394_reset_bus(self.cam));
def resetToFactoryDefault(self):
if self.cam:
DC1394SafeCall(dc1394_camera_reset(self.cam))
def initialize(self, reset_bus=False, mode=None, framerate=None, iso_speed=None,
operation_mode=None):
# initialize the camera
# reset bus stop all camera!
if reset_bus:
self.resetBus()
self.resetToFactoryDefault()
time.sleep(0.25)
#DC1394SafeCall(dc1394_capture_stop(self.cam))
#time.sleep(0.25)
self.transmission = DC1394_OFF
time.sleep(0.25)
DC1394SafeCall(dc1394_iso_release_all(self.cam))
time.sleep(0.25)
if operation_mode is not None:
self.operationMode = operation_mode
else:
try:
self.operationMode = DC1394_OPERATION_MODE_1394B
self.isoSpeed = DC1394_ISO_SPEED_800
except:
self.operationMode = DC1394_OPERATION_MODE_LEGACY
self.isoSpeed = DC1394_ISO_SPEED_400
if iso_speed is not None:
self.isoSpeed = iso_speed
if framerate is not None:
self.framerate = framerate
if mode is not None:
self.mode = mode
return True
def start(self, force_rgb8=False, flags_dc1394=DC1394_CAPTURE_FLAGS_CHANNEL_ALLOC):
cdef dc1394video_frame_t * frame
if self.running:
raise RuntimeError("Camera Already Running")
try:
self.running = True
self.force_rgb8 = force_rgb8
self.stop_event = False
self.transmission = DC1394_OFF
# Comments from cc1394Setup : Capture - We currently allocate the channel and not
# the iso bandwidth. Program crashes may leave a channel occupied.
num_buffer = 5
if not DC1394SafeCall(dc1394_capture_setup(self.cam, num_buffer, flags_dc1394), raise_event=False):
DC1394SafeCall(dc1394_iso_release_all(self.cam))
time.sleep(1)
DC1394SafeCall(dc1394_capture_setup(self.cam, num_buffer, flags_dc1394))
self.transmission = DC1394_ON
DC1394SafeCall(dc1394_capture_dequeue(self.cam, DC1394_CAPTURE_POLICY_WAIT, & frame))
if self.force_rgb8:
dtype = DC1394NumpyColorCoding[DC1394_COLOR_CODING_RGB8]
else:
dtype = DC1394NumpyColorCoding[frame.color_coding]
self.arr = np.ndarray(shape=(frame.size[1], frame.size[0], dtype.itemsize) , dtype=np.uint8)
self.arr.dtype = dtype
self.orig_ptr = self.arr.data
self.capture_loop = threading.Thread(target = self.run, name = "DC1394 capture loop")
self.capture_loop.start()
self.__init_event__()
except:
self.running = False
raise
def run(self):
fileno = self.fileno
while self.running:
# with timeout of 1 second
rlist, wlist, xlist = select.select([fileno], [], [], 1)
if not rlist:
continue
if self.capture_image() is False:
return
def capture_image(self):
cdef dc1394video_frame_t * frame
if not self.running:
return
status = self.sem_capture.acquire(False)
if not status:
print("DEBUG: drop the capture_image, another execution already use it")
self.sem_capture.release()
return
if not DC1394SafeCall(dc1394_capture_dequeue(self.cam, DC1394_CAPTURE_POLICY_POLL, & frame), raise_event=False):
self.sem_capture.release()
return False
if not frame:
self.sem_capture.release()
return
if dc1394_capture_is_frame_corrupt(self.cam, frame) == DC1394_TRUE:
print("Debug: frame is corrupt on camera.")
self.sem_capture.release()
return
self.format_image(frame)
self.__grab_event__(self.arr, frame.timestamp)
DC1394SafeCall(dc1394_capture_enqueue(self.cam, frame))
self.sem_capture.release()
cdef void format_image(self, dc1394video_frame_t * frame):
# cdef uint8_t jo = frame.size[0] * frame.size[1] * dtype.itemsize
# TODO do a malloc and be dynamic
# 600 * 800 * 3
if self.force_rgb8 and frame.color_coding == DC1394_COLOR_CODING_YUV422:
DC1394SafeCall(dc1394_convert_to_RGB8(frame.image, self.pixel_convert, frame.size[1], frame.size[0],
DC1394_BYTE_ORDER_UYVY, DC1394_COLOR_CODING_YUV422, 8));
self.arr.data = < char *> self.pixel_convert
return
self.arr.data = < char *> frame.image
def stop(self):
# capture semaphore blocking
self.running = False
status = self.sem_capture.acquire()
if not status:
self.sem_capture.release()
return
if self.capture_loop:
self.capture_loop.join()
self.capture_loop = None
try:
self.transmission = DC1394_OFF
DC1394SafeCall(dc1394_iso_release_all(self.cam))
print("before capture stop")
#DC1394SafeCall(dc1394_capture_stop(self.cam))
print("after capture stop")
except:
# ignore error, if camera crash, just stop the event
pass
self.__stop_event__()
self.sem_capture.release()
########################################
## PROPERTY
########################################
cdef void populate_capabilities(self):
cdef dc1394video_modes_t modes
cdef dc1394framerates_t framerates
cdef float framerate
self.available_features = {}
self.available_features_string = {}
self.unavailable_features = {}
self.available_modes = {}
cdef dc1394featureset_t featureset
DC1394SafeCall(dc1394_feature_get_all(self.cam, & featureset))
cdef dc1394feature_info_t featureinfo
cdef const_char_ptr feature_name
for i in range(DC1394_FEATURE_NUM):
featureinfo = featureset.feature[i]
if (featureinfo.available == DC1394_TRUE):
self.available_features[featureinfo.id] = featureinfo
feature_name = dc1394_feature_get_string(featureinfo.id)
self.available_features_string[feature_name] = featureinfo
else:
self.unavailable_features[featureinfo.id] = featureinfo
DC1394SafeCall(dc1394_video_get_supported_modes(self.cam, & modes))
for m in [modes.modes[i] for i in xrange(modes.num)]:
try:
DC1394SafeCall(dc1394_video_get_supported_framerates (self.cam, m, & framerates))
except:
break
fmlist = []
for j in range(framerates.num):
fmlist.append(framerates.framerates[j])
self.available_modes[m] = fmlist
def get_dict_available_features(self):
return self.available_features_string
def get_property(self, name):
cdef uint32_t ret_value
feature = self.available_features_string.get(name, None)
if not feature:
raise DC1394Error("[%s] not available" % name)
id = feature["id"]
DC1394SafeCall(dc1394_feature_get_value(self.cam, id, & ret_value))
return ret_value
def get_property_is_auto(self, name):
cdef dc1394feature_mode_t value
feature = self.available_features_string.get(name, None)
if not feature:
raise DC1394Error("[%s] not available" % name)
id = feature["id"]
DC1394SafeCall(dc1394_feature_get_mode(self.cam, id, & value))
return value == DC1394_FEATURE_MODE_AUTO
def set_property(self, name, value):
feature = self.available_features_string.get(name, None)
if not feature:
raise DC1394Error("[%s] not available" % name)
id = feature["id"]
# set section
DC1394SafeCall(dc1394_feature_set_mode(self.cam, id, DC1394_FEATURE_MODE_MANUAL))
if id == DC1394_FEATURE_WHITE_BALANCE:
raise DC1394Error("[%s] cannot change value of white balance. Use set_whitebalance" % name)
if value < feature['min'] or value > feature['max']:
raise DC1394Error("[%s] value out of range" % name)
DC1394SafeCall(dc1394_feature_set_value(self.cam, id, value))
def set_property_auto(self, name, value):
feature = self.available_features_string.get(name, None)
if not feature:
raise DC1394Error("[%s] not available" % name)
id = feature["id"]
if value:
DC1394SafeCall(dc1394_feature_set_mode(self.cam, id, DC1394_FEATURE_MODE_AUTO))
else:
DC1394SafeCall(dc1394_feature_set_mode(self.cam, id, DC1394_FEATURE_MODE_MANUAL))
def get_whitebalance(self):
# return tuple of value (blue, red)
cdef uint32_t actual_rv_value
cdef uint32_t actual_bu_value
name = "White Balance"
feature = self.available_features_string.get(name, None)
if not feature:
raise DC1394Error("[%s] not available" % name)
id = feature["id"]
if id != DC1394_FEATURE_WHITE_BALANCE:
raise DC1394Error("[%s] wrong feature, use get_property" % name)
DC1394SafeCall(dc1394_feature_whitebalance_get_value(self.cam, & actual_bu_value, & actual_rv_value))
return (actual_bu_value, actual_rv_value)
def set_whitebalance(self, RV_value=None, BU_value=None):
cdef uint32_t actual_rv_value
cdef uint32_t actual_bu_value
name = "White Balance"
feature = self.available_features_string.get(name, None)
if not feature:
raise DC1394Error("[%s] not available" % name)
id = feature["id"]
if id != DC1394_FEATURE_WHITE_BALANCE:
raise DC1394Error("[%s] wrong feature, use set_property" % name)
DC1394SafeCall(dc1394_feature_set_mode(self.cam, id, DC1394_FEATURE_MODE_MANUAL))
DC1394SafeCall(dc1394_feature_whitebalance_get_value(self.cam, & actual_bu_value, & actual_rv_value))
if RV_value is not None:
if RV_value < feature['min'] or RV_value > feature['max']:
raise DC1394Error("[%s] RV_value out of range" % name)
else:
RV_value = actual_rv_value
if BU_value is not None:
if BU_value < feature['min'] or BU_value > feature['max']:
raise DC1394Error("[%s] BU_value out of range" % name)
else:
BU_value = actual_bu_value
DC1394SafeCall(dc1394_feature_whitebalance_set_value(self.cam, BU_value, RV_value))
property fileno:
def __get__(self):
return dc1394_capture_get_fileno(self.cam)
property available_features:
def __get__(self):
return self.available_features
property available_features_string:
def __get__(self):
return self.available_features_string
# -------------------------------------------------------------------------
def __repr__(self):
return '<DC1394Camera vendor="%s" model="%s"/>' % (self.cam.vendor, self.cam.model)
# -------------------------------------------------------------------------
property grabEvent:
def __get__(self):
return self.__grab_event__
property initEvent:
def __get__(self):
return self.__init_event__
property stopEvent:
def __get__(self):
return self.__stop_event__
# -------------------------------------------------------------------------
property bandwitdh:
def __get__(self):
cdef uint32_t bandwidth
DC1394SafeCall(dc1394_video_get_bandwidth_usage(self.cam, & bandwidth))
return bandwidth
# -------------------------------------------------------------------------
property multishot:
def __get__(self):
cdef dc1394bool_t pwr
cdef uint32_t frames
DC1394SafeCall(dc1394_video_get_multi_shot(self.cam, & pwr, & frames))
return frames if (pwr == DC1394_TRUE) else 0
def __set__(self, uint32_t frames):
cdef dc1394bool_t pwr = DC1394_TRUE if (frames > 0) else DC1394_FALSE
DC1394SafeCall(dc1394_video_set_multi_shot(self.cam, frames, pwr))
# -------------------------------------------------------------------------
property brightness:
def __get__(self):
if DC1394_FEATURE_BRIGHTNESS not in self.available_features:
raise DC1394Error("[brightness] not available")
cdef uint32_t value
DC1394SafeCall(dc1394_feature_get_value(self.cam, DC1394_FEATURE_BRIGHTNESS, & value))
return value
def __set__(self, uint32_t value):
if DC1394_FEATURE_BRIGHTNESS not in self.available_features:
raise DC1394Error("[brightness] not available")
feature = self.available_features[DC1394_FEATURE_BRIGHTNESS]
if feature['current_mode'] == DC1394_FEATURE_MODE_AUTO:
raise DC1394Error("[brightness] Currently In Auto Mode")
if value < feature['min'] or value > feature['max']:
raise DC1394Error("[brightness] value out of range")
DC1394SafeCall(dc1394_feature_set_value(self.cam, DC1394_FEATURE_BRIGHTNESS, value))
# -------------------------------------------------------------------------
property exposure:
def __get__(self):
if DC1394_FEATURE_EXPOSURE not in self.available_features:
raise DC1394Error("[exposure] not available")
cdef uint32_t value
DC1394SafeCall(dc1394_feature_get_value(self.cam, DC1394_FEATURE_EXPOSURE, & value))
return value
def __set__(self, uint32_t value):
if DC1394_FEATURE_EXPOSURE not in self.available_features:
raise DC1394Error("[exposure not available")
feature = self.available_features[DC1394_FEATURE_EXPOSURE]
if feature['current_mode'] == DC1394_FEATURE_MODE_AUTO:
raise DC1394Error("[exposure] Currently In Auto Mode")
if value < feature['min'] or value > feature['max']:
raise DC1394Error("[exposure] value out of range")
DC1394SafeCall(dc1394_feature_set_value(self.cam, DC1394_FEATURE_EXPOSURE, value))
# -------------------------------------------------------------------------
property sharpness:
def __get__(self):
if DC1394_FEATURE_SHARPNESS not in self.available_features:
raise DC1394Error("[sharpness] not available")
cdef uint32_t value
DC1394SafeCall(dc1394_feature_get_value(self.cam, DC1394_FEATURE_SHARPNESS, & value))
return value
def __set__(self, uint32_t value):
if DC1394_FEATURE_SHARPNESS not in self.available_features:
raise DC1394Error("[sharpness not available")
feature = self.available_features[DC1394_FEATURE_SHARPNESS]
if feature['current_mode'] == DC1394_FEATURE_MODE_AUTO:
raise DC1394Error("[sharpness] Currently In Auto Mode")
if value < feature['min'] or value > feature['max']:
raise DC1394Error("[sharpness] value out of range")
DC1394SafeCall(dc1394_feature_set_value(self.cam, DC1394_FEATURE_SHARPNESS, value))
# -------------------------------------------------------------------------
property hue:
def __get__(self):
if DC1394_FEATURE_HUE not in self.available_features:
raise DC1394Error("[hue] not available")
cdef uint32_t value
DC1394SafeCall(dc1394_feature_get_value(self.cam, DC1394_FEATURE_HUE, & value))
return value
def __set__(self, uint32_t value):
if DC1394_FEATURE_HUE not in self.available_features:
raise DC1394Error("[hue not available")
feature = self.available_features[DC1394_FEATURE_HUE]
if feature['current_mode'] == DC1394_FEATURE_MODE_AUTO:
raise DC1394Error("[hue] Currently In Auto Mode")
if value < feature['min'] or value > feature['max']:
raise DC1394Error("[hue] value out of range")
DC1394SafeCall(dc1394_feature_set_value(self.cam, DC1394_FEATURE_HUE, value))
# -------------------------------------------------------------------------
property saturation:
def __get__(self):
if DC1394_FEATURE_SATURATION not in self.available_features:
raise DC1394Error("[saturation] not available")
cdef uint32_t value
DC1394SafeCall(dc1394_feature_get_value(self.cam, DC1394_FEATURE_SATURATION, & value))
return value
def __set__(self, uint32_t value):
if DC1394_FEATURE_SATURATION not in self.available_features:
raise DC1394Error("[saturation not available")
feature = self.available_features[DC1394_FEATURE_SATURATION]
if feature['current_mode'] == DC1394_FEATURE_MODE_AUTO:
raise DC1394Error("[saturation] Currently In Auto Mode")
if value < feature['min'] or value > feature['max']:
raise DC1394Error("[saturation] value out of range")
DC1394SafeCall(dc1394_feature_set_value(self.cam, DC1394_FEATURE_SATURATION, value))
# -------------------------------------------------------------------------
property gamma:
def __get__(self):
if DC1394_FEATURE_GAMMA not in self.available_features:
raise DC1394Error("[gamma] not available")
cdef uint32_t value
DC1394SafeCall(dc1394_feature_get_value(self.cam, DC1394_FEATURE_GAMMA, & value))
return value
def __set__(self, uint32_t value):
if DC1394_FEATURE_GAMMA not in self.available_features:
raise DC1394Error("[gamma not available")
feature = self.available_features[DC1394_FEATURE_GAMMA]
if feature['current_mode'] == DC1394_FEATURE_MODE_AUTO:
raise DC1394Error("[gamma] Currently In Auto Mode")
if value < feature['min'] or value > feature['max']:
raise DC1394Error("[gamma] value out of range")
DC1394SafeCall(dc1394_feature_set_value(self.cam, DC1394_FEATURE_GAMMA, value))
# -------------------------------------------------------------------------
property shutter:
def __get__(self):
if DC1394_FEATURE_SHUTTER not in self.available_features:
raise DC1394Error("[shutter] not available")
cdef uint32_t value
DC1394SafeCall(dc1394_feature_get_value(self.cam, DC1394_FEATURE_SHUTTER, & value))
return value
def __set__(self, uint32_t value):
if DC1394_FEATURE_SHUTTER not in self.available_features:
raise DC1394Error("[shutter not available")
feature = self.available_features[DC1394_FEATURE_SHUTTER]
if feature['current_mode'] == DC1394_FEATURE_MODE_AUTO:
raise DC1394Error("[shutter] Currently In Auto Mode")
if value < feature['min'] or value > feature['max']:
raise DC1394Error("[shutter] value out of range")
DC1394SafeCall(dc1394_feature_set_value(self.cam, DC1394_FEATURE_SHUTTER, value))
# -------------------------------------------------------------------------
property gain:
def __get__(self):
if DC1394_FEATURE_GAIN not in self.available_features:
raise DC1394Error("[gain] not available")
cdef uint32_t value
DC1394SafeCall(dc1394_feature_get_value(self.cam, DC1394_FEATURE_GAIN, & value))
return value
def __set__(self, uint32_t value):
if DC1394_FEATURE_GAIN not in self.available_features:
raise DC1394Error("[gain not available")
feature = self.available_features[DC1394_FEATURE_GAIN]
if feature['current_mode'] == DC1394_FEATURE_MODE_AUTO:
raise DC1394Error("[gain] Currently In Auto Mode")
if value < feature['min'] or value > feature['max']:
raise DC1394Error("[gain] value out of range")
DC1394SafeCall(dc1394_feature_set_value(self.cam, DC1394_FEATURE_GAIN, value))
# -------------------------------------------------------------------------
property iris:
def __get__(self):
if DC1394_FEATURE_IRIS not in self.available_features:
raise DC1394Error("[iris] not available")
cdef uint32_t value
DC1394SafeCall(dc1394_feature_get_value(self.cam, DC1394_FEATURE_IRIS, & value))
return value
def __set__(self, uint32_t value):
if DC1394_FEATURE_IRIS not in self.available_features:
raise DC1394Error("[iris not available")
feature = self.available_features[DC1394_FEATURE_IRIS]
if feature['current_mode'] == DC1394_FEATURE_MODE_AUTO:
raise DC1394Error("[iris] Currently In Auto Mode")
if value < feature['min'] or value > feature['max']:
raise DC1394Error("[iris] value out of range")
DC1394SafeCall(dc1394_feature_set_value(self.cam, DC1394_FEATURE_IRIS, value))
# -------------------------------------------------------------------------
property focus:
def __get__(self):
if DC1394_FEATURE_FOCUS not in self.available_features:
raise DC1394Error("[focus] not available")
cdef uint32_t value
DC1394SafeCall(dc1394_feature_get_value(self.cam, DC1394_FEATURE_FOCUS, & value))
return value
def __set__(self, uint32_t value):
if DC1394_FEATURE_FOCUS not in self.available_features:
raise DC1394Error("[focus not available")
feature = self.available_features[DC1394_FEATURE_FOCUS]
if feature['current_mode'] == DC1394_FEATURE_MODE_AUTO:
raise DC1394Error("[focus] Currently In Auto Mode")
if value < feature['min'] or value > feature['max']:
raise DC1394Error("[focus] value out of range")
DC1394SafeCall(dc1394_feature_set_value(self.cam, DC1394_FEATURE_FOCUS, value))
# -------------------------------------------------------------------------
property temperature:
def __get__(self):
if DC1394_FEATURE_TEMPERATURE not in self.available_features:
raise DC1394Error("[temperature] not available")
cdef uint32_t value
DC1394SafeCall(dc1394_feature_get_value(self.cam, DC1394_FEATURE_TEMPERATURE, & value))
return value
def __set__(self, uint32_t value):
if DC1394_FEATURE_TEMPERATURE not in self.available_features:
raise DC1394Error("[temperature not available")
feature = self.available_features[DC1394_FEATURE_TEMPERATURE]
if feature['current_mode'] == DC1394_FEATURE_MODE_AUTO:
raise DC1394Error("[temperature] Currently In Auto Mode")
if value < feature['min'] or value > feature['max']:
raise DC1394Error("[temperature] value out of range")
DC1394SafeCall(dc1394_feature_set_value(self.cam, DC1394_FEATURE_TEMPERATURE, value))
# -------------------------------------------------------------------------
property trigger:
def __get__(self):
if DC1394_FEATURE_TRIGGER not in self.available_features:
raise DC1394Error("[trigger] not available")
cdef uint32_t value
DC1394SafeCall(dc1394_feature_get_value(self.cam, DC1394_FEATURE_TRIGGER, & value))
return value
def __set__(self, uint32_t value):
if DC1394_FEATURE_TRIGGER not in self.available_features:
raise DC1394Error("[trigger not available")
feature = self.available_features[DC1394_FEATURE_TRIGGER]
if feature['current_mode'] == DC1394_FEATURE_MODE_AUTO:
raise DC1394Error("[trigger] Currently In Auto Mode")
if value < feature['min'] or value > feature['max']:
raise DC1394Error("[trigger] value out of range")
DC1394SafeCall(dc1394_feature_set_value(self.cam, DC1394_FEATURE_TRIGGER, value))
# -------------------------------------------------------------------------
property triggerDelay:
def __get__(self):
if DC1394_FEATURE_TRIGGER_DELAY not in self.available_features:
raise DC1394Error("[triggerDelay] not available")
cdef uint32_t value
DC1394SafeCall(dc1394_feature_get_value(self.cam, DC1394_FEATURE_TRIGGER_DELAY, & value))
return value
def __set__(self, uint32_t value):
if DC1394_FEATURE_TRIGGER_DELAY not in self.available_features:
raise DC1394Error("[triggerDelay not available")
feature = self.available_features[DC1394_FEATURE_TRIGGER_DELAY]
if feature['current_mode'] == DC1394_FEATURE_MODE_AUTO:
raise DC1394Error("[triggerDelay] Currently In Auto Mode")
if value < feature['min'] or value > feature['max']:
raise DC1394Error("[triggerDelay] value out of range")
DC1394SafeCall(dc1394_feature_set_value(self.cam, DC1394_FEATURE_TRIGGER_DELAY, value))
# -------------------------------------------------------------------------
property whiteShading:
def __get__(self):
if DC1394_FEATURE_WHITE_SHADING not in self.available_features:
raise DC1394Error("[whiteShading] not available")
cdef uint32_t value
DC1394SafeCall(dc1394_feature_get_value(self.cam, DC1394_FEATURE_WHITE_SHADING, & value))
return value
def __set__(self, uint32_t value):
if DC1394_FEATURE_WHITE_SHADING not in self.available_features:
raise DC1394Error("[whiteShading not available")
feature = self.available_features[DC1394_FEATURE_WHITE_SHADING]
if feature['current_mode'] == DC1394_FEATURE_MODE_AUTO:
raise DC1394Error("[whiteShading] Currently In Auto Mode")
if value < feature['min'] or value > feature['max']:
raise DC1394Error("[whiteShading] value out of range")
DC1394SafeCall(dc1394_feature_set_value(self.cam, DC1394_FEATURE_WHITE_SHADING, value))
# -------------------------------------------------------------------------
property frameRate:
def __get__(self):
if DC1394_FEATURE_FRAME_RATE not in self.available_features:
raise DC1394Error("[frameRate] not available")
cdef uint32_t value
DC1394SafeCall(dc1394_feature_get_value(self.cam, DC1394_FEATURE_FRAME_RATE, & value))
return value
def __set__(self, uint32_t value):
if DC1394_FEATURE_FRAME_RATE not in self.available_features:
raise DC1394Error("[frameRate not available")
feature = self.available_features[DC1394_FEATURE_FRAME_RATE]
if feature['current_mode'] == DC1394_FEATURE_MODE_AUTO:
raise DC1394Error("[frameRate] Currently In Auto Mode")
if value < feature['min'] or value > feature['max']:
raise DC1394Error("[frameRate] value out of range")
DC1394SafeCall(dc1394_feature_set_value(self.cam, DC1394_FEATURE_FRAME_RATE, value))
# -------------------------------------------------------------------------
property zoom:
def __get__(self):
if DC1394_FEATURE_ZOOM not in self.available_features:
raise DC1394Error("[zoom] not available")
cdef uint32_t value
DC1394SafeCall(dc1394_feature_get_value(self.cam, DC1394_FEATURE_ZOOM, & value))
return value
def __set__(self, uint32_t value):
if DC1394_FEATURE_ZOOM not in self.available_features:
raise DC1394Error("[zoom not available")
feature = self.available_features[DC1394_FEATURE_ZOOM]
if feature['current_mode'] == DC1394_FEATURE_MODE_AUTO:
raise DC1394Error("[zoom] Currently In Auto Mode")
if value < feature['min'] or value > feature['max']:
raise DC1394Error("[zoom] value out of range")
DC1394SafeCall(dc1394_feature_set_value(self.cam, DC1394_FEATURE_ZOOM, value))
# -------------------------------------------------------------------------
property pan:
def __get__(self):
if DC1394_FEATURE_PAN not in self.available_features:
raise DC1394Error("[pan] not available")
cdef uint32_t value
DC1394SafeCall(dc1394_feature_get_value(self.cam, DC1394_FEATURE_PAN, & value))
return value
def __set__(self, uint32_t value):
if DC1394_FEATURE_PAN not in self.available_features:
raise DC1394Error("[pan not available")
feature = self.available_features[DC1394_FEATURE_PAN]
if feature['current_mode'] == DC1394_FEATURE_MODE_AUTO:
raise DC1394Error("[pan] Currently In Auto Mode")
if value < feature['min'] or value > feature['max']:
raise DC1394Error("[pan] value out of range")
DC1394SafeCall(dc1394_feature_set_value(self.cam, DC1394_FEATURE_PAN, value))
# -------------------------------------------------------------------------
property tilt:
def __get__(self):
if DC1394_FEATURE_TILT not in self.available_features:
raise DC1394Error("[tilt] not available")
cdef uint32_t value
DC1394SafeCall(dc1394_feature_get_value(self.cam, DC1394_FEATURE_TILT, & value))
return value
def __set__(self, uint32_t value):
if DC1394_FEATURE_TILT not in self.available_features:
raise DC1394Error("[tilt not available")
feature = self.available_features[DC1394_FEATURE_TILT]
if feature['current_mode'] == DC1394_FEATURE_MODE_AUTO:
raise DC1394Error("[tilt] Currently In Auto Mode")