-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPyCapture2.pyx
More file actions
2969 lines (2452 loc) · 106 KB
/
PyCapture2.pyx
File metadata and controls
2969 lines (2452 loc) · 106 KB
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
from _FlyCapture2_C cimport *
cimport numpy as np
from cpython cimport PyObject, Py_INCREF, Py_DECREF
from libc.stdlib cimport malloc, free
cdef extern from "numpy/arrayobject.h":
object PyArray_NewFromDescr(object subtype, np.dtype descr,
int nd, np.npy_intp* dims,
np.npy_intp* strides,
void* data, int flags, object obj)
cdef extern from "Python.h":
void PyEval_InitThreads()
np.import_array()
cdef class IMAGE_FILE_FORMAT:
"""File formats to be used for saving images to disk.
RAW: Raw data.
"""
FROM_FILE_EXT = FC2_FROM_FILE_EXT
PGM = FC2_PGM
PPM = FC2_PPM
BMP = FC2_BMP
JPEG = FC2_JPEG
JPEG2000 = FC2_JPEG2000
TIFF = FC2_TIFF
PNG = FC2_PNG
RAW = FC2_RAW
cdef class PIXEL_FORMAT:
"""Pixel formats available for Format7 modes.
UNSPECIFIED_PIXEL_FORMAT: Unspecified pixel format.
"""
MONO8 = FC2_PIXEL_FORMAT_MONO8
YUV8_411 = FC2_PIXEL_FORMAT_411YUV8
YUV8_422 = FC2_PIXEL_FORMAT_422YUV8
YUV8_444 = FC2_PIXEL_FORMAT_444YUV8
RGB8 = FC2_PIXEL_FORMAT_RGB8
MONO16 = FC2_PIXEL_FORMAT_MONO16
RGB16 = FC2_PIXEL_FORMAT_RGB16
S_MONO16 = FC2_PIXEL_FORMAT_S_MONO16
S_RGB16 = FC2_PIXEL_FORMAT_S_RGB16
RAW8 = FC2_PIXEL_FORMAT_RAW8
RAW16 = FC2_PIXEL_FORMAT_RAW16
MONO12 = FC2_PIXEL_FORMAT_MONO12
RAW12 = FC2_PIXEL_FORMAT_RAW12
BGR = FC2_PIXEL_FORMAT_BGR
BGRU = FC2_PIXEL_FORMAT_BGRU
RGB = FC2_PIXEL_FORMAT_RGB
RGBU = FC2_PIXEL_FORMAT_RGBU
BGR16 = FC2_PIXEL_FORMAT_BGR16
BGRU16 = FC2_PIXEL_FORMAT_BGRU16
YUV8_JPEG_422 = FC2_PIXEL_FORMAT_422YUV8_JPEG
NUM_PIXEL_FORMATS = FC2_NUM_PIXEL_FORMATS
UNSPECIFIED_PIXEL_FORMAT = FC2_UNSPECIFIED_PIXEL_FORMAT
cdef class INTERFACE_TYPE:
"""Interfaces that a camera may use to communicate with a host.
UNKNOWN: Unknown interface.
"""
IEEE1394 = FC2_INTERFACE_IEEE1394
USB_2 = FC2_INTERFACE_USB_2
USB_3 = FC2_INTERFACE_USB_3
GIGE = FC2_INTERFACE_GIGE
UNKNOWN = FC2_INTERFACE_UNKNOWN
cdef class DRIVER_TYPE:
"""Types of low level drivers that FlyCapture uses.
UNKNOWN: Unknown driver type.
"""
CAM_1394 = FC2_DRIVER_1394_CAM
PRO_1394 = FC2_DRIVER_1394_PRO
JUJU_1394 = FC2_DRIVER_1394_JUJU
VIDEO1394 = FC2_DRIVER_1394_VIDEO1394
RAW1394 = FC2_DRIVER_1394_RAW1394
USB_NONE = FC2_DRIVER_USB_NONE
USB_CAM = FC2_DRIVER_USB_CAM
USB3_PRO = FC2_DRIVER_USB3_PRO
GIGE_NONE = FC2_DRIVER_GIGE_NONE
GIGE_FILTER = FC2_DRIVER_GIGE_FILTER
GIGE_PRO = FC2_DRIVER_GIGE_PRO
GIGE_LWF = FC2_DRIVER_GIGE_LWF
UNKNOWN = FC2_DRIVER_UNKNOWN
cdef class BANDWIDTH_ALLOCATION:
"""Bandwidth allocation options for 1394 devices.
UNSPECIFIED: Not specified. This leaves the current setting unchanged.
"""
OFF = FC2_BANDWIDTH_ALLOCATION_OFF
ON = FC2_BANDWIDTH_ALLOCATION_ON
UNSUPPORTED = FC2_BANDWIDTH_ALLOCATION_UNSUPPORTED
UNSPECIFIED = FC2_BANDWIDTH_ALLOCATION_UNSPECIFIED
cdef class GRAB_MODE:
"""The grab strategy employed during image transfer.
UNSPECIFIED_GRAB_MODE Unspecified grab mode.
"""
DROP_FRAMES = FC2_DROP_FRAMES
BUFFER_FRAMES = FC2_BUFFER_FRAMES
UNSPECIFIED_GRAB_MODE = FC2_UNSPECIFIED_GRAB_MODE
cdef class BUS_SPEED:
"""Bus speeds.
SPEED_UNKNOWN: Unknown bus speed.
"""
S100 = FC2_BUSSPEED_S100
S200 = FC2_BUSSPEED_S200
S400 = FC2_BUSSPEED_S400
S480 = FC2_BUSSPEED_S480
S800 = FC2_BUSSPEED_S800
S1600 = FC2_BUSSPEED_S1600
S3200 = FC2_BUSSPEED_S3200
S5000 = FC2_BUSSPEED_S5000
BASE_T_10 = FC2_BUSSPEED_10BASE_T
BASE_T_100 = FC2_BUSSPEED_100BASE_T
BASE_T_1000 = FC2_BUSSPEED_1000BASE_T
BASE_T_10000 = FC2_BUSSPEED_10000BASE_T
S_FASTEST = FC2_BUSSPEED_S_FASTEST
ANY = FC2_BUSSPEED_ANY
SPEED_UNKNOWN = FC2_BUSSPEED_SPEED_UNKNOWN
cdef class PROPERTY_TYPE:
"""Camera properties.
UNSPECIFIED_PROPERTY_TYPE
"""
BRIGHTNESS = FC2_BRIGHTNESS
AUTO_EXPOSURE = FC2_AUTO_EXPOSURE
SHARPNESS = FC2_SHARPNESS
WHITE_BALANCE = FC2_WHITE_BALANCE
HUE = FC2_HUE
SATURATION = FC2_SATURATION
GAMMA = FC2_GAMMA
IRIS = FC2_IRIS
FOCUS = FC2_FOCUS
ZOOM = FC2_ZOOM
PAN = FC2_PAN
TILT = FC2_TILT
SHUTTER = FC2_SHUTTER
GAIN = FC2_GAIN
TRIGGER_MODE = FC2_TRIGGER_MODE
TRIGGER_DELAY = FC2_TRIGGER_DELAY
FRAME_RATE = FC2_FRAME_RATE
TEMPERATURE = FC2_TEMPERATURE
UNSPECIFIED_PROPERTY_TYPE = FC2_UNSPECIFIED_PROPERTY_TYPE
cdef class VIDEO_MODE:
"""DCAM video modes.
NUM_VIDEOMODES: Number of possible video modes
"""
VM_160x120YUV444 = FC2_VIDEOMODE_160x120YUV444
VM_320x240YUV422 = FC2_VIDEOMODE_320x240YUV422
VM_640x480YUV411 = FC2_VIDEOMODE_640x480YUV411
VM_640x480YUV422 = FC2_VIDEOMODE_640x480YUV422
VM_640x480RGB = FC2_VIDEOMODE_640x480RGB
VM_640x480Y8 = FC2_VIDEOMODE_640x480Y8
VM_640x480Y16 = FC2_VIDEOMODE_640x480Y16
VM_800x600YUV422 = FC2_VIDEOMODE_800x600YUV422
VM_800x600RGB = FC2_VIDEOMODE_800x600RGB
VM_800x600Y8 = FC2_VIDEOMODE_800x600Y8
VM_800x600Y16 = FC2_VIDEOMODE_800x600Y16
VM_1024x768YUV422 = FC2_VIDEOMODE_1024x768YUV422
VM_1024x768RGB = FC2_VIDEOMODE_1024x768RGB
VM_1024x768Y8 = FC2_VIDEOMODE_1024x768Y8
VM_1024x768Y16 = FC2_VIDEOMODE_1024x768Y16
VM_1280x960YUV422 = FC2_VIDEOMODE_1280x960YUV422
VM_1280x960RGB = FC2_VIDEOMODE_1280x960RGB
VM_1280x960Y8 = FC2_VIDEOMODE_1280x960Y8
VM_1280x960Y16 = FC2_VIDEOMODE_1280x960Y16
VM_1600x1200YUV422 = FC2_VIDEOMODE_1600x1200YUV422
VM_1600x1200RGB = FC2_VIDEOMODE_1600x1200RGB
VM_1600x1200Y8 = FC2_VIDEOMODE_1600x1200Y8
VM_1600x1200Y16 = FC2_VIDEOMODE_1600x1200Y16
FORMAT7 = FC2_VIDEOMODE_FORMAT7
NUM_VIDEOMODES = FC2_NUM_VIDEOMODES
cdef class FRAMERATE:
"""Frame rates in frames per second.
FORMAT7: Custom frame rate for Format7 functionality.
"""
FR_1_875 = FC2_FRAMERATE_1_875
FR_3_75 = FC2_FRAMERATE_3_75
FR_7_5 = FC2_FRAMERATE_7_5
FR_15 = FC2_FRAMERATE_15
FR_30 = FC2_FRAMERATE_30
FR_60 = FC2_FRAMERATE_60
FR_120 = FC2_FRAMERATE_120
FR_240 = FC2_FRAMERATE_240
FORMAT7 = FC2_FRAMERATE_FORMAT7
cdef class MODE:
"""Camera modes for DCAM formats as well as Format7.
FC2_NUM_MODES: Number of modes.
"""
MODE_0 = FC2_MODE_0
MODE_1 = FC2_MODE_1
MODE_2 = FC2_MODE_2
MODE_3 = FC2_MODE_3
MODE_4 = FC2_MODE_4
MODE_5 = FC2_MODE_5
MODE_6 = FC2_MODE_6
MODE_7 = FC2_MODE_7
MODE_8 = FC2_MODE_8
MODE_9 = FC2_MODE_9
MODE_10 = FC2_MODE_10
MODE_11 = FC2_MODE_11
MODE_12 = FC2_MODE_12
MODE_13 = FC2_MODE_13
MODE_14 = FC2_MODE_14
MODE_15 = FC2_MODE_15
MODE_16 = FC2_MODE_16
MODE_17 = FC2_MODE_17
MODE_18 = FC2_MODE_18
MODE_19 = FC2_MODE_19
MODE_20 = FC2_MODE_20
MODE_21 = FC2_MODE_21
MODE_22 = FC2_MODE_22
MODE_23 = FC2_MODE_23
MODE_24 = FC2_MODE_24
MODE_25 = FC2_MODE_25
MODE_26 = FC2_MODE_26
MODE_27 = FC2_MODE_27
MODE_28 = FC2_MODE_28
MODE_29 = FC2_MODE_29
MODE_30 = FC2_MODE_30
MODE_31 = FC2_MODE_31
NUM_MODES = FC2_NUM_MODES
cdef class GIGE_PROPERTY_TYPE:
"""Possible properties that can be queried from the camera.
GIGE_PACKET_DELAY
"""
GIGE_HEARTBEAT = FC2_HEARTBEAT
GIGE_HEARTBEAT_TIMEOUT = FC2_HEARTBEAT_TIMEOUT
GIGE_PACKET_SIZE = PACKET_SIZE
GIGE_PACKET_DELAY = PACKET_DELAY
cdef class PCIE_BUS_SPEED:
"""Speed of PCIE busses.
FC2_PCIE_BUSSPEED_UNKNOWN: Speed is unknown
"""
PCIE_2_5 = FC2_PCIE_BUSSPEED_2_5
PCIE_5_0 = FC2_PCIE_BUSSPEED_5_0
UNKNOWN = FC2_PCIE_BUSSPEED_UNKNOWN
cdef class BAYER_FORMAT:
"""Bayer tile formats.
BGGR; Blue-Green-Green-Red.
"""
NONE = FC2_BT_NONE
RGGB = FC2_BT_RGGB
GRBG = FC2_BT_GRBG
GBRG = FC2_BT_GBRG
BGGR = FC2_BT_BGGR
cdef class COLOR_PROCESSING:
"""Color processing algorithms.
DIRECTIONAL: Best quality but much faster than rigorous
"""
DEFAULT = FC2_DEFAULT
NO_COLOR_PROCESSING = FC2_NO_COLOR_PROCESSING
NEAREST_NEIGHBOR_FAST = FC2_NEAREST_NEIGHBOR_FAST
EDGE_SENSING = FC2_EDGE_SENSING
HQ_LINEAR = FC2_HQ_LINEAR
RIGOROUS = FC2_RIGOROUS
IPP = FC2_IPP
DIRECTIONAL = FC2_DIRECTIONAL
cdef class STATISTICS_CHANNEL:
"""Channels that allow statistics to be calculated.
LIGHTNESS
"""
GREY = FC2_STATISTICS_GREY
RED = FC2_STATISTICS_RED
GREEN = FC2_STATISTICS_GREEN
BLUE = FC2_STATISTICS_BLUE
HUE = FC2_STATISTICS_HUE
SATURATION = FC2_STATISTICS_SATURATION
LIGHTNESS = FC2_STATISTICS_LIGHTNESS
cdef class TIFF_COMPRESSION:
"""TIFF compression method.
JPEG: Save using JPEG compression. This is only valid for 8-bit
greyscale and 24-bit only. Default to LZW for other bit depths.
"""
NONE = FC2_TIFF_NONE
PACKBITS = FC2_TIFF_PACKBITS
DEFLATE = FC2_TIFF_DEFLATE
ADOBE_DEFLATE = FC2_TIFF_ADOBE_DEFLATE
CCITTFAX3 = FC2_TIFF_CCITTFAX3
CCITTFAX4 = FC2_TIFF_CCITTFAX4
JPEG = FC2_TIFF_JPEG
cdef class OS_TYPE:
"""Possible operating systems.
UNKNOWN_OS: Unknown operating system
"""
WINDOWS_X86 = FC2_WINDOWS_X86
WINDOWS_X64 = FC2_WINDOWS_X64
LINUX_X86 = FC2_LINUX_X86
LINUX_X64 = FC2_LINUX_X64
MAC = FC2_MAC
UNKNOWN_OS = FC2_UNKNOWN_OS
cdef class BYTE_ORDER:
"""Possible byte order.
BIG_ENDIAN
"""
LITTLE_ENDIAN = FC2_BYTE_ORDER_LITTLE_ENDIAN
BIG_ENDIAN = FC2_BYTE_ORDER_BIG_ENDIAN
cdef class NODE_TYPE:
"""Type of node.
NODE_NODE: Unknown node type.
"""
NODE_COMPUTER = COMPUTER
NODE_BUS = BUS
NODE_CAMERA = CAMERA
NODE_NODE = NODE
cdef class PORT_TYPE:
"""Possible states of a port on a node.
PORT_CONNECTED_TO_CHILD
"""
PORT_NOT_CONNECTED = NOT_CONNECTED
PORT_CONNECTED_TO_PARENT = CONNECTED_TO_PARENT
PORT_CONNECTED_TO_CHILD = CONNECTED_TO_CHILD
cdef class BUS_CALLBACK_TYPE:
"""The type of bus callback to register a callback function for.
REMOVAL: Register for removals only.
"""
BUS_RESET = FC2_BUS_RESET
ARRIVAL = FC2_ARRIVAL
REMOVAL = FC2_REMOVAL
# classes
class Fc2error(Exception):
"""An error raised by the PyCapture2 library."""
def __init__(self, errorNum):
"""Initialize the error with the index of the error."""
self.errorNum = errorNum
def __str__(self):
"""Get the name of the error from the error index."""
errorStr = fc2ErrorToDescription(self.errorNum)
return repr(errorStr)
class ConfigROM:
"""camera configuration ROM class.
pszKeyword (str): keyword.
"""
def __init__(self, nodeVendorId=0, chipIdHi=0, chipIdLo=0, unitSpecId=0,
unitSWVer=0, unitSubSWVer=0, vendorUniqueInfo_0=0,
vendorUniqueInfo_1=0, vendorUniqueInfo_2=0,
vendorUniqueInfo_3=0, pszKeyword="", ):
self.nodeVendorId = nodeVendorId
self.chipIdHi = chipIdHi
self.chipIdLo = chipIdLo
self.unitSpecId = unitSpecId
self.unitSWVer = unitSWVer
self.unitSubSWVer = unitSubSWVer
self.vendorUniqueInfo_0 = vendorUniqueInfo_0
self.vendorUniqueInfo_1 = vendorUniqueInfo_1
self.vendorUniqueInfo_2 = vendorUniqueInfo_2
self.vendorUniqueInfo_3 = vendorUniqueInfo_3
self.pszKeyword = pszKeyword
class CameraInfo:
"""camera information class.
"""
def __init__(self, serialNumber=0, interfaceType=0, driverType=0,
isColorCamera=0, modelName="", vendorName="", sensorInfo="",
sensorResolution="", driverName="", firmwareVersion="",
firmwareBuildTime="", maximumBusSpeed=0, pcieBusSpeed=0,
bayerTileFormat=0, busNumber=0, nodeNumber=0, iidcVer=0,
configROM=ConfigROM(), gigEMajorVersion=0, gigEMinorVersion=0,
userDefinedName="", xmlURL1="", xmlURL2="",
macAddress=(0, 0, 0, 0, 0, 0), ipAddress=(0, 0, 0, 0),
subnetMask=(0, 0, 0, 0), defaultGateway=(0, 0, 0, 0),
ccpStatus=0, applicationIPAddress=0, applicationPort=0):
self.serialNumber = serialNumber
self.interfaceType = interfaceType
self.driverType = driverType
self.isColorCamera = isColorCamera
self.modelName = modelName
self.vendorName = vendorName
self.sensorInfo = sensorInfo
self.sensorResolution = sensorResolution
self.driverName = driverName
self.firmwareVersion = firmwareVersion
self.firmwareBuildTime = firmwareBuildTime
self.maximumBusSpeed = maximumBusSpeed
self.pcieBusSpeed = pcieBusSpeed
self.bayerTileFormat = bayerTileFormat
self.busNumber = busNumber
self.nodeNumber = nodeNumber
self.iidcVer = iidcVer
self.configROM = configROM
self.gigEMajorVersion = gigEMajorVersion
self.gigEMinorVersion = gigEMinorVersion
self.userDefinedName = userDefinedName
self.xmlURL1 = xmlURL1
self.xmlURL2 = xmlURL2
self.macAddress = macAddress
self.ipAddress = ipAddress
self.subnetMask = subnetMask
self.defaultGateway = defaultGateway
self.ccpStatus = ccpStatus
self.applicationIPAddress = applicationIPAddress
self.applicationPort = applicationPort
class AvailableImageInfo:
"""Structure containing the availability of image properties, for use in
EmbeddedImageInfo class.
ROIPosition (bool): Whether specifying the region of interest is
specified by the camera.
"""
def __init__(self, timestamp=False, gain=False, shutter=False,
brightness=False, exposure=False, whiteBalance=False,
frameCounter=False, strobePattern=False, ROIPosition=False):
self.timestamp = timestamp
self.gain = gain
self.shutter = shutter
self.brightness = brightness
self.exposure = exposure
self.whiteBalance = whiteBalance
self.frameCounter = frameCounter
self.strobePattern = strobePattern
self.ROIPosition = ROIPosition
class EmbeddedImageInfo:
"""Structure containing the current status and availability (via the
"available" attribute) of image properties.
available (PyCapture2.availableImageInfo): Whether these properties are
available for modification. See AvailableImageInfo for reference.
"""
def __init__(self, timestamp=False, gain=False, shutter=False,
brightness=False, exposure=False, whiteBalance=False,
frameCounter=False, strobePattern=False, GPIOPinState=False,
ROIPosition=False, available=AvailableImageInfo()):
self.timestamp = timestamp
self.gain = gain
self.shutter = shutter
self.brightness = brightness
self.exposure = exposure
self.whiteBalance = whiteBalance
self.frameCounter = frameCounter
self.strobePattern = strobePattern
self.GPIOPinState = GPIOPinState
self.ROIPosition = ROIPosition
self.available = available
class Config:
"""Structure containing the configuration for a camera.
registerTimeout (int): Register read/write timeout value (in
microseconds).
"""
def __init__(self, numBuffers=0, numImageNotifications=0,
minNumImageNotifications=0, grabTimeout=0, grabMode=0,
isochBusSpeed=0, asyncBusSpeed=0, bandwidthAllocation=0,
registerTimeoutRetries=0, registerTimeout=0, ):
self.numBuffers = numBuffers
self.numImageNotifications = numImageNotifications
self.minNumImageNotifications = minNumImageNotifications
self.grabTimeout = grabTimeout
self.grabMode = grabMode
self.isochBusSpeed = isochBusSpeed
self.asyncBusSpeed = asyncBusSpeed
self.bandwidthAllocation = bandwidthAllocation
self.registerTimeoutRetries = registerTimeoutRetries
self.registerTimeout = registerTimeout
class TriggerMode:
"""Properties of a camera trigger.
parameter (int): The parameter value.
"""
def __init__(self, onOff=False, polarity=0, source=0, mode=0, parameter=0,
):
self.onOff = onOff
self.polarity = polarity
self.source = source
self.mode = mode
self.parameter = parameter
class PropertyInfo:
"""Information about a specific camera property.
unitAbbr (str): Abbreviated textual description of units.
"""
def __init__(self, type=0, present=False, autoSupported=False,
manualSupported=False, onOffSupported=False,
onePushSupported=False, absValSupported=False,
readOutSupported=False, min=0, max=0, absMin=0.0, absMax=0.0,
units="", unitAbbr="", ):
self.type = type
self.present = present
self.autoSupported = autoSupported
self.manualSupported = manualSupported
self.onOffSupported = onOffSupported
self.onePushSupported = onePushSupported
self.absValSupported = absValSupported
self.readOutSupported = readOutSupported
self.min = min
self.max = max
self.absMin = absMin
self.absMax = absMax
self.units = units
self.unitAbbr = unitAbbr
class Property:
"""Data from a specific camera property.
absValue (float): Floating point value.
"""
def __init__(self, propType=0, present=False, absControl=False,
onePush=False, onOff=False, autoManualMode=False, valueA=0,
valueB=0, absValue=0.0, ):
self.type = propType
self.present = present
self.absControl = absControl
self.onePush = onePush
self.onOff = onOff
self.autoManualMode = autoManualMode
self.valueA = valueA
self.valueB = valueB
self.absValue = absValue
class StrobeInfo:
"""Information about the camera's strobe settings and capabilities.
maxValue (float): Maximum value.
"""
def __init__(self, source=0, present=False, readOutSupported=False,
onOffSupported=False, polaritySupported=False, minValue=0.0,
maxValue=0.0, ):
self.source = source
self.present = present
self.readOutSupported = readOutSupported
self.onOffSupported = onOffSupported
self.polaritySupported = polaritySupported
self.minValue = minValue
self.maxValue = maxValue
class StrobeControl:
"""Data about the camera strobe.
duration (float): Signal duration (in ms)
"""
def __init__(self, source=0, onOff=False, polarity=0, delay=0.0,
duration=0.0, ):
self.source = source
self.onOff = onOff
self.polarity = polarity
self.delay = delay
self.duration = duration
class LUTData:
"""Information about the camera's lookup table.
numEntries (int): The number of entries in the LUT.
"""
def __init__(self, supported=False, enabled=False, numBanks=0,
numChannels=0, inputBitDepth=0, outputBitDepth=0,
numEntries=0, ):
self.supported = supported
self.enabled = enabled
self.numBanks = numBanks
self.numChannels = numChannels
self.inputBitDepth = inputBitDepth
self.outputBitDepth = outputBitDepth
self.numEntries = numEntries
class TimeStamp:
"""Information detailing the time an image was taken.
cycleOffset (int): 1394 cycle time offset.
"""
def __init__(self, seconds=0, microSeconds=0, cycleSeconds=0,
cycleCount=0, cycleOffset=0, ):
self.seconds = seconds
self.microSeconds = microSeconds
self.cycleSeconds = cycleSeconds
self.cycleCount = cycleCount
self.cycleOffset = cycleOffset
class CameraStats:
"""Diagnostic information about the camera.
"""
def __init__(self, imageDropped=0, imageCorrupt=0, imageXmitFailed=0,
imageDriverDropped=0, regReadFailed=0, regWriteFailed=0,
portErrors=0, cameraPowerUp=False, cameraVoltages=(0.0,),
cameraCurrents=(0.0,), temperature=0,
timeSinceInitialization=0, timeSinceBusReset=0, timeStamp=0,
numResendPacketsRequested=0, numResendPacketsReceived=0, ):
self.imageDropped = imageDropped
self.imageCorrupt = imageCorrupt
self.imageXmitFailed = imageXmitFailed
self.imageDriverDropped = imageDriverDropped
self.regReadFailed = regReadFailed
self.regWriteFailed = regWriteFailed
self.portErrors = portErrors
self.cameraPowerUp = cameraPowerUp
self.cameraVoltages = cameraVoltages
self.cameraCurrents = cameraCurrents
self.temperature = temperature
self.timeSinceInitialization = timeSinceInitialization
self.timeSinceBusReset = timeSinceBusReset
self.timeStamp = timeStamp
self.numResendPacketsRequested = numResendPacketsRequested
self.numResendPacketsReceived = numResendPacketsReceived
class Format7Info:
"""Format 7 information for a single mode.
percentage (float): Current packet size as a percentage of maximum.
"""
def __init__(self, mode=0, maxWidth=0, maxHeight=0, offsetHStepSize=0,
offsetVStepSize=0, imageHStepSize=0, imageVStepSize=0,
pixelFormatBitField=0, vendorPixelFormatBitField=0,
packetSize=0, minPacketSize=0, maxPacketSize=0,
percentage=0.0, ):
self.mode = mode
self.maxWidth = maxWidth
self.maxHeight = maxHeight
self.offsetHStepSize = offsetHStepSize
self.offsetVStepSize = offsetVStepSize
self.imageHStepSize = imageHStepSize
self.imageVStepSize = imageVStepSize
self.pixelFormatBitField = pixelFormatBitField
self.vendorPixelFormatBitField = vendorPixelFormatBitField
self.packetSize = packetSize
self.minPacketSize = minPacketSize
self.maxPacketSize = maxPacketSize
self.percentage = percentage
class Format7ImageSettings:
"""Format 7 image settings.
PixelFormat (int): Pixel format of image. Use PIXEL_FORMAT to set
correctly.
"""
def __init__(self, mode=0, offsetX=0, offsetY=0, width=0, height=0,
pixelFormat=0):
self.mode = mode
self.offsetX = offsetX
self.offsetY = offsetY
self.width = width
self.height = height
self.pixelFormat = pixelFormat
class Format7PacketInfo:
"""Format 7 packet information.
minBytesPerPacket (int): Minimum bytes per packet.
"""
def __init__(self, recommendedBytesPerPacket=0, maxBytesPerPacket=0,
unitBytesPerPacket=0, ):
self.recommendedBytesPerPacket = recommendedBytesPerPacket
self.maxBytesPerPacket = maxBytesPerPacket
self.unitBytesPerPacket = unitBytesPerPacket
class GigEProperty:
"""A property specific to GigE cameras.
value (int): Current value of the property.
"""
def __init__(self, propType=0, isReadable=False, isWritable=False, min=0,
max=0, value=0, ):
self.propType = propType
self.isReadable = isReadable
self.isWritable = isWritable
self.min = min
self.max = max
self.value = value
class GigEImageSettingsInfo:
"""Format 7 information for a single mode.
vendorPixelFormatBitField (int): Vendor unique pixel formats in a bit
field.
"""
def __init__(self, maxWidth=0, maxHeight=0, offsetHStepSize=0,
offsetVStepSize=0, imageHStepSize=0, imageVStepSize=0,
pixelFormatBitField=0, vendorPixelFormatBitField=0, ):
self.maxWidth = maxWidth
self.maxHeight = maxHeight
self.offsetHStepSize = offsetHStepSize
self.offsetVStepSize = offsetVStepSize
self.imageHStepSize = imageHStepSize
self.imageVStepSize = imageVStepSize
self.pixelFormatBitField = pixelFormatBitField
self.vendorPixelFormatBitField = vendorPixelFormatBitField
class GigEImageSettings:
"""Image settings for a GigE camera.
pixelFormat (int): Pixel format of image. Use PyCapture2.PIXEL_FORMAT
to set correctly.
"""
def __init__(self, offsetX=0, offsetY=0, width=0, height=0, pixelFormat=0,
):
self.offsetX = offsetX
self.offsetY = offsetY
self.width = width
self.height = height
self.pixelFormat = pixelFormat
class GigEStreamChannel:
"""Information about a single GigE stream channel.
sourcePort (int): Source UDP port of the stream channel.
"""
def __init__(self, networkInterfaceIndex=0, hostPort=0,
doNotFragment=False, packetSize=0, interPacketDelay=0,
destinationIpAddress=(0, 0, 0, 0), sourcePort=0, ):
self.networkInterfaceIndex = networkInterfaceIndex
self.hostPort = hostPort
self.doNotFragment = doNotFragment
self.packetSize = packetSize
self.interPacketDelay = interPacketDelay
self.destinationIpAddress = destinationIpAddress
self.sourcePort = sourcePort
class GigEConfig:
"""Configuration for a GigE camera.
registerTimeout (int): Register read/write timeout value (in
microseconds).
"""
def __init__(self, enablePacketResend=False, registerTimeoutRetries=0,
registerTimeout=0, ):
self.enablePacketResend = enablePacketResend
self.registerTimeoutRetries = registerTimeoutRetries
self.registerTimeout = registerTimeout
class SystemInfo:
"""Description of the system connected to the camera.
screenHeight (int): Screen resolution height, in pixels.
"""
def __init__(self, osType=0, osDescription="", byteOrder=0, sysMemSize=0,
cpuDescription="", numCpuCores=0, driverList="",
libraryList="", gpuDescription="", screenWidth=0,
screenHeight=0, ):
self.osType = osType
self.osDescription = osDescription
self.byteOrder = byteOrder
self.sysMemSize = sysMemSize
self.cpuDescription = cpuDescription
self.numCpuCores = numCpuCores
self.driverList = driverList
self.libraryList = libraryList
self.gpuDescription = gpuDescription
self.screenWidth = screenWidth
self.screenHeight = screenHeight
class CallbackData:
"""Data returned from an event callback.
eventTimestamp (long): Time as reported by the camera at which the
exposure operation completed. Please note this is NOT a
PyCapture2.TimeStamp object!
"""
def __init__(self, eventName="", eventID=0, eventTimestamp=0, ):
self.eventName = eventName
self.eventID = eventID
self.eventTimestamp = eventTimestamp
class PNGOption:
"""Structure containing options for saving PNG images.
compressionLevel (int): Level of compression for the image, on the
range (0-9)
"""
def __init__(self, interlaced=False, compressionLevel=0, ):
self.interlaced = interlaced
self.compressionLevel = compressionLevel
class PPMOption:
"""Structure containing options for saving PPM images.
binaryFile (bool): Whether to save the PPM as a binary file.
"""
def __init__(self, binaryFile=False, ):
self.binaryFile = binaryFile
class PGMOption:
"""Structure containing options for saving PGM images.
binaryFile (bool): Whether to save the PGM as a binary file.
"""
def __init__(self, binaryFile=False, ):
self.binaryFile = binaryFile
class TIFFOption:
"""Structure containing options for saving TIFF images.
compression (int): Compression method to use for encoding. Use
TIFF_COMPRESSION to set correctly.
"""
def __init__(self, compression=0, ):
self.compression = compression
class JPEGOption:
"""Structure containing options for saving JPEG images.
quality (int): JPEG image quality in range (0-100)
"""
def __init__(self, progressive=False, quality=0, ):
self.progressive = progressive
self.quality = quality
class JPG2Option:
"""Structure containing options for saving JPEG2000 images.
quality (int): JPEG saving quality in range (1-512)
"""
def __init__(self, quality=0, ):
self.quality = quality
class BMPOption:
"""Structure containing options for saving Bitmap images.
indexedColor_8bit (bool): WHether to save with 8bit indexed color.
"""
def __init__(self, indexedColor_8bit=False, ):
self.indexedColor_8bit = indexedColor_8bit
cdef class BaseCamera:
"""Base camera class. This class exists only for camera and GigECamera
classes to inherit from it."""
cdef fc2Context c
cdef public bint isConnected
cdef fc2EventOptions evntOpts
cdef tuple callbackArgs
cdef dict eventArgs
def __init__(self):
"""camera() -> Camera object
Initialize and return a Camera object.
This function takes no arguments.
"""
self.eventArgs = {}
self.callbackArgs = ()
def __dealloc__(self):
fc2DestroyContext(self.c)
def connect(self, tuple IDTup):
"""camera.connect(guid) -> None
"""
cdef fc2PGRGuid camID
self.isConnected = True
camID.value[0], camID.value[1], camID.value[2], camID.value[3] = IDTup
checkError(fc2Connect(self.c, &camID))
def disconnect(self):
"""camera.disconnect() -> None
Disconnect the camera object from a physical camera.
"""
checkError(fc2Disconnect(self.c))
self.isConnected = False
def startCapture(self, func=None, *extraArgs):
"""camera.startCapture(function = None, *arguments) -> None
arguments: The rest of the arguments are the arguments for the
callback function.
"""
if func:
self.callbackArgs = (func, extraArgs)
checkError(fc2StartCaptureCallback(self.c,
<fc2ImageEventCallback>&imageCallbackBridge,
<void*>self.callbackArgs))
else:
checkError(fc2StartCapture(self.c))
def stopCapture(self):
"""camera.stopCapture() -> None
Stop capturing data from camera.
"""
checkError(fc2StopCapture(self.c))
def retrieveBuffer(self):
"""camera.retrieveBuffer() -> image
image (PyCapture2.Image): The image object crabbed from the camera.
"""
img = Image()
checkError(fc2RetrieveBuffer(self.c, &img.i))
return img
def getCameraInfo(self):
"""camera.getCameraInfo() -> cameraInfo
"""
cdef fc2CameraInfo camInfo
checkError(fc2GetCameraInfo(self.c, &camInfo))
returnVal = CameraInfo()
returnVal.__dict__ = {
"serialNumber": camInfo.serialNumber,
"interfaceType": camInfo.interfaceType,
"driverType": camInfo.driverType,
"isColorCamera": camInfo.isColorCamera,
"modelName": camInfo.modelName,
"vendorName": camInfo.vendorName,
"sensorInfo": camInfo.sensorInfo,
"sensorResolution": camInfo.sensorResolution,
"driverName": camInfo.driverName,
"firmwareVersion": camInfo.firmwareVersion,
"firmwareBuildTime": camInfo.firmwareBuildTime,
"maximumBusSpeed": camInfo.maximumBusSpeed,
"pcieBusSpeed": camInfo.pcieBusSpeed,
"bayerTileFormat": camInfo.bayerTileFormat,
"busNumber": camInfo.busNumber,
"nodeNumber": camInfo.nodeNumber,
"iidcVer": camInfo.iidcVer,
"configROM": {
"nodeVendorId": camInfo.configROM.nodeVendorId,
"chipIdHi": camInfo.configROM.chipIdHi,
"chipIdLo": camInfo.configROM.chipIdLo,
"unitSpecId": camInfo.configROM.unitSpecId,
"unitSWVer": camInfo.configROM.unitSWVer,
"unitSubSWVer": camInfo.configROM.unitSubSWVer,
"vendorUniqueInfo_0": camInfo.configROM.vendorUniqueInfo_0,
"vendorUniqueInfo_1": camInfo.configROM.vendorUniqueInfo_1,
"vendorUniqueInfo_2": camInfo.configROM.vendorUniqueInfo_2,
"vendorUniqueInfo_3": camInfo.configROM.vendorUniqueInfo_3,
"pszKeyword": camInfo.configROM.pszKeyword
},