-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmvsdk.py
2394 lines (2016 loc) · 89.3 KB
/
mvsdk.py
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
#coding=utf-8
import platform
from ctypes import *
from threading import local
# 回调函数类型
CALLBACK_FUNC_TYPE = None
# SDK动态库
_sdk = None
def _Init():
global _sdk
global CALLBACK_FUNC_TYPE
is_win = (platform.system() == "Windows")
is_x86 = (platform.architecture()[0] == '32bit')
if is_win:
_sdk = windll.MVCAMSDK if is_x86 else windll.MVCAMSDK_X64
CALLBACK_FUNC_TYPE = WINFUNCTYPE
else:
_sdk = cdll.LoadLibrary("./DLL/libMVSDK.so")
CALLBACK_FUNC_TYPE = CFUNCTYPE
_Init()
#-------------------------------------------类型定义--------------------------------------------------
# 状态码定义
CAMERA_STATUS_SUCCESS = 0 # 操作成功
CAMERA_STATUS_FAILED = -1 # 操作失败
CAMERA_STATUS_INTERNAL_ERROR = -2 # 内部错误
CAMERA_STATUS_UNKNOW = -3 # 未知错误
CAMERA_STATUS_NOT_SUPPORTED = -4 # 不支持该功能
CAMERA_STATUS_NOT_INITIALIZED = -5 # 初始化未完成
CAMERA_STATUS_PARAMETER_INVALID = -6 # 参数无效
CAMERA_STATUS_PARAMETER_OUT_OF_BOUND = -7 # 参数越界
CAMERA_STATUS_UNENABLED = -8 # 未使能
CAMERA_STATUS_USER_CANCEL = -9 # 用户手动取消了,比如roi面板点击取消,返回
CAMERA_STATUS_PATH_NOT_FOUND = -10 # 注册表中没有找到对应的路径
CAMERA_STATUS_SIZE_DISMATCH = -11 # 获得图像数据长度和定义的尺寸不匹配
CAMERA_STATUS_TIME_OUT = -12 # 超时错误
CAMERA_STATUS_IO_ERROR = -13 # 硬件IO错误
CAMERA_STATUS_COMM_ERROR = -14 # 通讯错误
CAMERA_STATUS_BUS_ERROR = -15 # 总线错误
CAMERA_STATUS_NO_DEVICE_FOUND = -16 # 没有发现设备
CAMERA_STATUS_NO_LOGIC_DEVICE_FOUND = -17 # 未找到逻辑设备
CAMERA_STATUS_DEVICE_IS_OPENED = -18 # 设备已经打开
CAMERA_STATUS_DEVICE_IS_CLOSED = -19 # 设备已经关闭
CAMERA_STATUS_DEVICE_VEDIO_CLOSED = -20 # 没有打开设备视频,调用录像相关的函数时,如果相机视频没有打开,则回返回该错误。
CAMERA_STATUS_NO_MEMORY = -21 # 没有足够系统内存
CAMERA_STATUS_FILE_CREATE_FAILED = -22 # 创建文件失败
CAMERA_STATUS_FILE_INVALID = -23 # 文件格式无效
CAMERA_STATUS_WRITE_PROTECTED = -24 # 写保护,不可写
CAMERA_STATUS_GRAB_FAILED = -25 # 数据采集失败
CAMERA_STATUS_LOST_DATA = -26 # 数据丢失,不完整
CAMERA_STATUS_EOF_ERROR = -27 # 未接收到帧结束符
CAMERA_STATUS_BUSY = -28 # 正忙(上一次操作还在进行中),此次操作不能进行
CAMERA_STATUS_WAIT = -29 # 需要等待(进行操作的条件不成立),可以再次尝试
CAMERA_STATUS_IN_PROCESS = -30 # 正在进行,已经被操作过
CAMERA_STATUS_IIC_ERROR = -31 # IIC传输错误
CAMERA_STATUS_SPI_ERROR = -32 # SPI传输错误
CAMERA_STATUS_USB_CONTROL_ERROR = -33 # USB控制传输错误
CAMERA_STATUS_USB_BULK_ERROR = -34 # USB BULK传输错误
CAMERA_STATUS_SOCKET_INIT_ERROR = -35 # 网络传输套件初始化失败
CAMERA_STATUS_GIGE_FILTER_INIT_ERROR = -36 # 网络相机内核过滤驱动初始化失败,请检查是否正确安装了驱动,或者重新安装。
CAMERA_STATUS_NET_SEND_ERROR = -37 # 网络数据发送错误
CAMERA_STATUS_DEVICE_LOST = -38 # 与网络相机失去连接,心跳检测超时
CAMERA_STATUS_DATA_RECV_LESS = -39 # 接收到的字节数比请求的少
CAMERA_STATUS_FUNCTION_LOAD_FAILED = -40 # 从文件中加载程序失败
CAMERA_STATUS_CRITICAL_FILE_LOST = -41 # 程序运行所必须的文件丢失。
CAMERA_STATUS_SENSOR_ID_DISMATCH = -42 # 固件和程序不匹配,原因是下载了错误的固件。
CAMERA_STATUS_OUT_OF_RANGE = -43 # 参数超出有效范围。
CAMERA_STATUS_REGISTRY_ERROR = -44 # 安装程序注册错误。请重新安装程序,或者运行安装目录Setup/Installer.exe
CAMERA_STATUS_ACCESS_DENY = -45 # 禁止访问。指定相机已经被其他程序占用时,再申请访问该相机,会返回该状态。(一个相机不能被多个程序同时访问)
#AIA的标准兼容的错误码
CAMERA_AIA_PACKET_RESEND = 0x0100 #该帧需要重传
CAMERA_AIA_NOT_IMPLEMENTED = 0x8001 #设备不支持的命令
CAMERA_AIA_INVALID_PARAMETER = 0x8002 #命令参数非法
CAMERA_AIA_INVALID_ADDRESS = 0x8003 #不可访问的地址
CAMERA_AIA_WRITE_PROTECT = 0x8004 #访问的对象不可写
CAMERA_AIA_BAD_ALIGNMENT = 0x8005 #访问的地址没有按照要求对齐
CAMERA_AIA_ACCESS_DENIED = 0x8006 #没有访问权限
CAMERA_AIA_BUSY = 0x8007 #命令正在处理中
CAMERA_AIA_DEPRECATED = 0x8008 #0x8008-0x0800B 0x800F 该指令已经废弃
CAMERA_AIA_PACKET_UNAVAILABLE = 0x800C #包无效
CAMERA_AIA_DATA_OVERRUN = 0x800D #数据溢出,通常是收到的数据比需要的多
CAMERA_AIA_INVALID_HEADER = 0x800E #数据包头部中某些区域与协议不匹配
CAMERA_AIA_PACKET_NOT_YET_AVAILABLE = 0x8010 #图像分包数据还未准备好,多用于触发模式,应用程序访问超时
CAMERA_AIA_PACKET_AND_PREV_REMOVED_FROM_MEMORY = 0x8011 #需要访问的分包已经不存在。多用于重传时数据已经不在缓冲区中
CAMERA_AIA_PACKET_REMOVED_FROM_MEMORY = 0x8012 #CAMERA_AIA_PACKET_AND_PREV_REMOVED_FROM_MEMORY
CAMERA_AIA_NO_REF_TIME = 0x0813 #没有参考时钟源。多用于时间同步的命令执行时
CAMERA_AIA_PACKET_TEMPORARILY_UNAVAILABLE = 0x0814 #由于信道带宽问题,当前分包暂时不可用,需稍后进行访问
CAMERA_AIA_OVERFLOW = 0x0815 #设备端数据溢出,通常是队列已满
CAMERA_AIA_ACTION_LATE = 0x0816 #命令执行已经超过有效的指定时间
CAMERA_AIA_ERROR = 0x8FFF #错误
# 图像格式定义
CAMERA_MEDIA_TYPE_MONO = 0x01000000
CAMERA_MEDIA_TYPE_RGB = 0x02000000
CAMERA_MEDIA_TYPE_COLOR = 0x02000000
CAMERA_MEDIA_TYPE_OCCUPY1BIT = 0x00010000
CAMERA_MEDIA_TYPE_OCCUPY2BIT = 0x00020000
CAMERA_MEDIA_TYPE_OCCUPY4BIT = 0x00040000
CAMERA_MEDIA_TYPE_OCCUPY8BIT = 0x00080000
CAMERA_MEDIA_TYPE_OCCUPY10BIT = 0x000A0000
CAMERA_MEDIA_TYPE_OCCUPY12BIT = 0x000C0000
CAMERA_MEDIA_TYPE_OCCUPY16BIT = 0x00100000
CAMERA_MEDIA_TYPE_OCCUPY24BIT = 0x00180000
CAMERA_MEDIA_TYPE_OCCUPY32BIT = 0x00200000
CAMERA_MEDIA_TYPE_OCCUPY36BIT = 0x00240000
CAMERA_MEDIA_TYPE_OCCUPY48BIT = 0x00300000
CAMERA_MEDIA_TYPE_EFFECTIVE_PIXEL_SIZE_MASK = 0x00FF0000
CAMERA_MEDIA_TYPE_EFFECTIVE_PIXEL_SIZE_SHIFT = 16
CAMERA_MEDIA_TYPE_ID_MASK = 0x0000FFFF
CAMERA_MEDIA_TYPE_COUNT = 0x46
#mono
CAMERA_MEDIA_TYPE_MONO1P = (CAMERA_MEDIA_TYPE_MONO | CAMERA_MEDIA_TYPE_OCCUPY1BIT | 0x0037)
CAMERA_MEDIA_TYPE_MONO2P = (CAMERA_MEDIA_TYPE_MONO | CAMERA_MEDIA_TYPE_OCCUPY2BIT | 0x0038)
CAMERA_MEDIA_TYPE_MONO4P = (CAMERA_MEDIA_TYPE_MONO | CAMERA_MEDIA_TYPE_OCCUPY4BIT | 0x0039)
CAMERA_MEDIA_TYPE_MONO8 = (CAMERA_MEDIA_TYPE_MONO | CAMERA_MEDIA_TYPE_OCCUPY8BIT | 0x0001)
CAMERA_MEDIA_TYPE_MONO8S = (CAMERA_MEDIA_TYPE_MONO | CAMERA_MEDIA_TYPE_OCCUPY8BIT | 0x0002)
CAMERA_MEDIA_TYPE_MONO10 = (CAMERA_MEDIA_TYPE_MONO | CAMERA_MEDIA_TYPE_OCCUPY16BIT | 0x0003)
CAMERA_MEDIA_TYPE_MONO10_PACKED = (CAMERA_MEDIA_TYPE_MONO | CAMERA_MEDIA_TYPE_OCCUPY12BIT | 0x0004)
CAMERA_MEDIA_TYPE_MONO12 = (CAMERA_MEDIA_TYPE_MONO | CAMERA_MEDIA_TYPE_OCCUPY16BIT | 0x0005)
CAMERA_MEDIA_TYPE_MONO12_PACKED = (CAMERA_MEDIA_TYPE_MONO | CAMERA_MEDIA_TYPE_OCCUPY12BIT | 0x0006)
CAMERA_MEDIA_TYPE_MONO14 = (CAMERA_MEDIA_TYPE_MONO | CAMERA_MEDIA_TYPE_OCCUPY16BIT | 0x0025)
CAMERA_MEDIA_TYPE_MONO16 = (CAMERA_MEDIA_TYPE_MONO | CAMERA_MEDIA_TYPE_OCCUPY16BIT | 0x0007)
# Bayer
CAMERA_MEDIA_TYPE_BAYGR8 = (CAMERA_MEDIA_TYPE_MONO | CAMERA_MEDIA_TYPE_OCCUPY8BIT | 0x0008)
CAMERA_MEDIA_TYPE_BAYRG8 = (CAMERA_MEDIA_TYPE_MONO | CAMERA_MEDIA_TYPE_OCCUPY8BIT | 0x0009)
CAMERA_MEDIA_TYPE_BAYGB8 = (CAMERA_MEDIA_TYPE_MONO | CAMERA_MEDIA_TYPE_OCCUPY8BIT | 0x000A)
CAMERA_MEDIA_TYPE_BAYBG8 = (CAMERA_MEDIA_TYPE_MONO | CAMERA_MEDIA_TYPE_OCCUPY8BIT | 0x000B)
CAMERA_MEDIA_TYPE_BAYGR10_MIPI = (CAMERA_MEDIA_TYPE_MONO | CAMERA_MEDIA_TYPE_OCCUPY10BIT | 0x0026)
CAMERA_MEDIA_TYPE_BAYRG10_MIPI = (CAMERA_MEDIA_TYPE_MONO | CAMERA_MEDIA_TYPE_OCCUPY10BIT | 0x0027)
CAMERA_MEDIA_TYPE_BAYGB10_MIPI = (CAMERA_MEDIA_TYPE_MONO | CAMERA_MEDIA_TYPE_OCCUPY10BIT | 0x0028)
CAMERA_MEDIA_TYPE_BAYBG10_MIPI = (CAMERA_MEDIA_TYPE_MONO | CAMERA_MEDIA_TYPE_OCCUPY10BIT | 0x0029)
CAMERA_MEDIA_TYPE_BAYGR10 = (CAMERA_MEDIA_TYPE_MONO | CAMERA_MEDIA_TYPE_OCCUPY16BIT | 0x000C)
CAMERA_MEDIA_TYPE_BAYRG10 = (CAMERA_MEDIA_TYPE_MONO | CAMERA_MEDIA_TYPE_OCCUPY16BIT | 0x000D)
CAMERA_MEDIA_TYPE_BAYGB10 = (CAMERA_MEDIA_TYPE_MONO | CAMERA_MEDIA_TYPE_OCCUPY16BIT | 0x000E)
CAMERA_MEDIA_TYPE_BAYBG10 = (CAMERA_MEDIA_TYPE_MONO | CAMERA_MEDIA_TYPE_OCCUPY16BIT | 0x000F)
CAMERA_MEDIA_TYPE_BAYGR12 = (CAMERA_MEDIA_TYPE_MONO | CAMERA_MEDIA_TYPE_OCCUPY16BIT | 0x0010)
CAMERA_MEDIA_TYPE_BAYRG12 = (CAMERA_MEDIA_TYPE_MONO | CAMERA_MEDIA_TYPE_OCCUPY16BIT | 0x0011)
CAMERA_MEDIA_TYPE_BAYGB12 = (CAMERA_MEDIA_TYPE_MONO | CAMERA_MEDIA_TYPE_OCCUPY16BIT | 0x0012)
CAMERA_MEDIA_TYPE_BAYBG12 = (CAMERA_MEDIA_TYPE_MONO | CAMERA_MEDIA_TYPE_OCCUPY16BIT | 0x0013)
CAMERA_MEDIA_TYPE_BAYGR10_PACKED = (CAMERA_MEDIA_TYPE_MONO | CAMERA_MEDIA_TYPE_OCCUPY12BIT | 0x0026)
CAMERA_MEDIA_TYPE_BAYRG10_PACKED = (CAMERA_MEDIA_TYPE_MONO | CAMERA_MEDIA_TYPE_OCCUPY12BIT | 0x0027)
CAMERA_MEDIA_TYPE_BAYGB10_PACKED = (CAMERA_MEDIA_TYPE_MONO | CAMERA_MEDIA_TYPE_OCCUPY12BIT | 0x0028)
CAMERA_MEDIA_TYPE_BAYBG10_PACKED = (CAMERA_MEDIA_TYPE_MONO | CAMERA_MEDIA_TYPE_OCCUPY12BIT | 0x0029)
CAMERA_MEDIA_TYPE_BAYGR12_PACKED = (CAMERA_MEDIA_TYPE_MONO | CAMERA_MEDIA_TYPE_OCCUPY12BIT | 0x002A)
CAMERA_MEDIA_TYPE_BAYRG12_PACKED = (CAMERA_MEDIA_TYPE_MONO | CAMERA_MEDIA_TYPE_OCCUPY12BIT | 0x002B)
CAMERA_MEDIA_TYPE_BAYGB12_PACKED = (CAMERA_MEDIA_TYPE_MONO | CAMERA_MEDIA_TYPE_OCCUPY12BIT | 0x002C)
CAMERA_MEDIA_TYPE_BAYBG12_PACKED = (CAMERA_MEDIA_TYPE_MONO | CAMERA_MEDIA_TYPE_OCCUPY12BIT | 0x002D)
CAMERA_MEDIA_TYPE_BAYGR16 = (CAMERA_MEDIA_TYPE_MONO | CAMERA_MEDIA_TYPE_OCCUPY16BIT | 0x002E)
CAMERA_MEDIA_TYPE_BAYRG16 = (CAMERA_MEDIA_TYPE_MONO | CAMERA_MEDIA_TYPE_OCCUPY16BIT | 0x002F)
CAMERA_MEDIA_TYPE_BAYGB16 = (CAMERA_MEDIA_TYPE_MONO | CAMERA_MEDIA_TYPE_OCCUPY16BIT | 0x0030)
CAMERA_MEDIA_TYPE_BAYBG16 = (CAMERA_MEDIA_TYPE_MONO | CAMERA_MEDIA_TYPE_OCCUPY16BIT | 0x0031)
# RGB
CAMERA_MEDIA_TYPE_RGB8 = (CAMERA_MEDIA_TYPE_COLOR | CAMERA_MEDIA_TYPE_OCCUPY24BIT | 0x0014)
CAMERA_MEDIA_TYPE_BGR8 = (CAMERA_MEDIA_TYPE_COLOR | CAMERA_MEDIA_TYPE_OCCUPY24BIT | 0x0015)
CAMERA_MEDIA_TYPE_RGBA8 = (CAMERA_MEDIA_TYPE_COLOR | CAMERA_MEDIA_TYPE_OCCUPY32BIT | 0x0016)
CAMERA_MEDIA_TYPE_BGRA8 = (CAMERA_MEDIA_TYPE_COLOR | CAMERA_MEDIA_TYPE_OCCUPY32BIT | 0x0017)
CAMERA_MEDIA_TYPE_RGB10 = (CAMERA_MEDIA_TYPE_COLOR | CAMERA_MEDIA_TYPE_OCCUPY48BIT | 0x0018)
CAMERA_MEDIA_TYPE_BGR10 = (CAMERA_MEDIA_TYPE_COLOR | CAMERA_MEDIA_TYPE_OCCUPY48BIT | 0x0019)
CAMERA_MEDIA_TYPE_RGB12 = (CAMERA_MEDIA_TYPE_COLOR | CAMERA_MEDIA_TYPE_OCCUPY48BIT | 0x001A)
CAMERA_MEDIA_TYPE_BGR12 = (CAMERA_MEDIA_TYPE_COLOR | CAMERA_MEDIA_TYPE_OCCUPY48BIT | 0x001B)
CAMERA_MEDIA_TYPE_RGB16 = (CAMERA_MEDIA_TYPE_COLOR | CAMERA_MEDIA_TYPE_OCCUPY48BIT | 0x0033)
CAMERA_MEDIA_TYPE_RGB10V1_PACKED = (CAMERA_MEDIA_TYPE_COLOR | CAMERA_MEDIA_TYPE_OCCUPY32BIT | 0x001C)
CAMERA_MEDIA_TYPE_RGB10P32 = (CAMERA_MEDIA_TYPE_COLOR | CAMERA_MEDIA_TYPE_OCCUPY32BIT | 0x001D)
CAMERA_MEDIA_TYPE_RGB12V1_PACKED = (CAMERA_MEDIA_TYPE_COLOR | CAMERA_MEDIA_TYPE_OCCUPY36BIT | 0X0034)
CAMERA_MEDIA_TYPE_RGB565P = (CAMERA_MEDIA_TYPE_COLOR | CAMERA_MEDIA_TYPE_OCCUPY16BIT | 0x0035)
CAMERA_MEDIA_TYPE_BGR565P = (CAMERA_MEDIA_TYPE_COLOR | CAMERA_MEDIA_TYPE_OCCUPY16BIT | 0X0036)
# YUV and YCbCr
CAMERA_MEDIA_TYPE_YUV411_8_UYYVYY = (CAMERA_MEDIA_TYPE_COLOR | CAMERA_MEDIA_TYPE_OCCUPY12BIT | 0x001E)
CAMERA_MEDIA_TYPE_YUV422_8_UYVY = (CAMERA_MEDIA_TYPE_COLOR | CAMERA_MEDIA_TYPE_OCCUPY16BIT | 0x001F)
CAMERA_MEDIA_TYPE_YUV422_8 = (CAMERA_MEDIA_TYPE_COLOR | CAMERA_MEDIA_TYPE_OCCUPY16BIT | 0x0032)
CAMERA_MEDIA_TYPE_YUV8_UYV = (CAMERA_MEDIA_TYPE_COLOR | CAMERA_MEDIA_TYPE_OCCUPY24BIT | 0x0020)
CAMERA_MEDIA_TYPE_YCBCR8_CBYCR = (CAMERA_MEDIA_TYPE_COLOR | CAMERA_MEDIA_TYPE_OCCUPY24BIT | 0x003A)
#CAMERA_MEDIA_TYPE_YCBCR422_8 : YYYYCbCrCbCr
CAMERA_MEDIA_TYPE_YCBCR422_8 = (CAMERA_MEDIA_TYPE_COLOR | CAMERA_MEDIA_TYPE_OCCUPY16BIT | 0x003B)
CAMERA_MEDIA_TYPE_YCBCR422_8_CBYCRY = (CAMERA_MEDIA_TYPE_COLOR | CAMERA_MEDIA_TYPE_OCCUPY16BIT | 0x0043)
CAMERA_MEDIA_TYPE_YCBCR411_8_CBYYCRYY = (CAMERA_MEDIA_TYPE_COLOR | CAMERA_MEDIA_TYPE_OCCUPY12BIT | 0x003C)
CAMERA_MEDIA_TYPE_YCBCR601_8_CBYCR = (CAMERA_MEDIA_TYPE_COLOR | CAMERA_MEDIA_TYPE_OCCUPY24BIT | 0x003D)
CAMERA_MEDIA_TYPE_YCBCR601_422_8 = (CAMERA_MEDIA_TYPE_COLOR | CAMERA_MEDIA_TYPE_OCCUPY16BIT | 0x003E)
CAMERA_MEDIA_TYPE_YCBCR601_422_8_CBYCRY = (CAMERA_MEDIA_TYPE_COLOR | CAMERA_MEDIA_TYPE_OCCUPY16BIT | 0x0044)
CAMERA_MEDIA_TYPE_YCBCR601_411_8_CBYYCRYY = (CAMERA_MEDIA_TYPE_COLOR | CAMERA_MEDIA_TYPE_OCCUPY12BIT | 0x003F)
CAMERA_MEDIA_TYPE_YCBCR709_8_CBYCR = (CAMERA_MEDIA_TYPE_COLOR | CAMERA_MEDIA_TYPE_OCCUPY24BIT | 0x0040)
CAMERA_MEDIA_TYPE_YCBCR709_422_8 = (CAMERA_MEDIA_TYPE_COLOR | CAMERA_MEDIA_TYPE_OCCUPY16BIT | 0x0041)
CAMERA_MEDIA_TYPE_YCBCR709_422_8_CBYCRY = (CAMERA_MEDIA_TYPE_COLOR | CAMERA_MEDIA_TYPE_OCCUPY16BIT | 0x0045)
CAMERA_MEDIA_TYPE_YCBCR709_411_8_CBYYCRYY = (CAMERA_MEDIA_TYPE_COLOR | CAMERA_MEDIA_TYPE_OCCUPY12BIT | 0x0042)
# RGB Planar
CAMERA_MEDIA_TYPE_RGB8_PLANAR = (CAMERA_MEDIA_TYPE_COLOR | CAMERA_MEDIA_TYPE_OCCUPY24BIT | 0x0021)
CAMERA_MEDIA_TYPE_RGB10_PLANAR = (CAMERA_MEDIA_TYPE_COLOR | CAMERA_MEDIA_TYPE_OCCUPY48BIT | 0x0022)
CAMERA_MEDIA_TYPE_RGB12_PLANAR = (CAMERA_MEDIA_TYPE_COLOR | CAMERA_MEDIA_TYPE_OCCUPY48BIT | 0x0023)
CAMERA_MEDIA_TYPE_RGB16_PLANAR = (CAMERA_MEDIA_TYPE_COLOR | CAMERA_MEDIA_TYPE_OCCUPY48BIT | 0x0024)
# 保存格式
FILE_JPG = 1
FILE_BMP = 2
FILE_RAW = 4
FILE_PNG = 8
FILE_BMP_8BIT = 16
FILE_PNG_8BIT = 32
FILE_RAW_16BIT = 64
# 触发信号
EXT_TRIG_LEADING_EDGE = 0
EXT_TRIG_TRAILING_EDGE = 1
EXT_TRIG_HIGH_LEVEL = 2
EXT_TRIG_LOW_LEVEL = 3
EXT_TRIG_DOUBLE_EDGE = 4
# IO模式
IOMODE_TRIG_INPUT = 0
IOMODE_STROBE_OUTPUT = 1
IOMODE_GP_INPUT = 2
IOMODE_GP_OUTPUT = 3
IOMODE_PWM_OUTPUT = 4
# 相机操作异常信息
class CameraException(Exception):
"""docstring for CameraException"""
def __init__(self, error_code):
super(CameraException, self).__init__()
self.error_code = error_code
self.message = CameraGetErrorString(error_code)
def __str__(self):
return 'error_code:{} message:{}'.format(self.error_code, self.message)
class MvStructure(Structure):
def __str__(self):
strs = []
for field in self._fields_:
name = field[0]
value = getattr(self, name)
if isinstance(value, type(b'')):
value = _string_buffer_to_str(value)
strs.append("{}:{}".format(name, value))
return '\n'.join(strs)
def __repr__(self):
return self.__str__()
def clone(self):
obj = type(self)()
memmove(byref(obj), byref(self), sizeof(self))
return obj
# 相机的设备信息,只读信息,请勿修改
class tSdkCameraDevInfo(MvStructure):
_fields_ = [("acProductSeries", c_char * 32), #产品系列
("acProductName", c_char * 32), #产品名称
("acFriendlyName", c_char * 32), #产品昵称
("acLinkName", c_char * 32), #内核符号连接名,内部使用
("acDriverVersion", c_char * 32), #驱动版本
("acSensorType", c_char * 32), #sensor类型
("acPortType", c_char * 32), #接口类型
("acSn", c_char * 32), #产品唯一序列号
("uInstance", c_uint)] #该型号相机在该电脑上的实例索引号,用于区分同型号多相机
def GetProductSeries(self):
return _string_buffer_to_str(self.acProductSeries)
def GetProductName(self):
return _string_buffer_to_str(self.acProductName)
def GetFriendlyName(self):
return _string_buffer_to_str(self.acFriendlyName)
def GetLinkName(self):
return _string_buffer_to_str(self.acLinkName)
def GetDriverVersion(self):
return _string_buffer_to_str(self.acDriverVersion)
def GetSensorType(self):
return _string_buffer_to_str(self.acSensorType)
def GetPortType(self):
return _string_buffer_to_str(self.acPortType)
def GetSn(self):
return _string_buffer_to_str(self.acSn)
# 相机的分辨率设定范围
class tSdkResolutionRange(MvStructure):
_fields_ = [("iHeightMax", c_int), #图像最大高度
("iHeightMin", c_int), #图像最小高度
("iWidthMax", c_int), #图像最大宽度
("iWidthMin", c_int), #图像最小宽度
("uSkipModeMask", c_uint), #SKIP模式掩码,为0,表示不支持SKIP 。bit0为1,表示支持SKIP 2x2 bit1为1,表示支持SKIP 3x3....
("uBinSumModeMask", c_uint), #BIN(求和)模式掩码,为0,表示不支持BIN 。bit0为1,表示支持BIN 2x2 bit1为1,表示支持BIN 3x3....
("uBinAverageModeMask", c_uint),#BIN(求均值)模式掩码,为0,表示不支持BIN 。bit0为1,表示支持BIN 2x2 bit1为1,表示支持BIN 3x3....
("uResampleMask", c_uint)] #硬件重采样的掩码
#相机的分辨率描述
class tSdkImageResolution(MvStructure):
_fields_ = [
("iIndex", c_int), # 索引号,[0,N]表示预设的分辨率(N 为预设分辨率的最大个数,一般不超过20),OXFF 表示自定义分辨率(ROI)
("acDescription", c_char * 32), # 该分辨率的描述信息。仅预设分辨率时该信息有效。自定义分辨率可忽略该信息
("uBinSumMode", c_uint), # BIN(求和)的模式,范围不能超过tSdkResolutionRange中uBinSumModeMask
("uBinAverageMode", c_uint), # BIN(求均值)的模式,范围不能超过tSdkResolutionRange中uBinAverageModeMask
("uSkipMode", c_uint), # 是否SKIP的尺寸,为0表示禁止SKIP模式,范围不能超过tSdkResolutionRange中uSkipModeMask
("uResampleMask", c_uint), # 硬件重采样的掩码
("iHOffsetFOV", c_int), # 采集视场相对于Sensor最大视场左上角的垂直偏移
("iVOffsetFOV", c_int), # 采集视场相对于Sensor最大视场左上角的水平偏移
("iWidthFOV", c_int), # 采集视场的宽度
("iHeightFOV", c_int), # 采集视场的高度
("iWidth", c_int), # 相机最终输出的图像的宽度
("iHeight", c_int), # 相机最终输出的图像的高度
("iWidthZoomHd", c_int), # 硬件缩放的宽度,不需要进行此操作的分辨率,此变量设置为0.
("iHeightZoomHd", c_int), # 硬件缩放的高度,不需要进行此操作的分辨率,此变量设置为0.
("iWidthZoomSw", c_int), # 软件缩放的宽度,不需要进行此操作的分辨率,此变量设置为0.
("iHeightZoomSw", c_int), # 软件缩放的高度,不需要进行此操作的分辨率,此变量设置为0.
]
def GetDescription(self):
return _string_buffer_to_str(self.acDescription)
#相机白平衡模式描述信息
class tSdkColorTemperatureDes(MvStructure):
_fields_ = [
("iIndex", c_int), # 模式索引号
("acDescription", c_char * 32), # 描述信息
]
def GetDescription(self):
return _string_buffer_to_str(self.acDescription)
#相机帧率描述信息
class tSdkFrameSpeed(MvStructure):
_fields_ = [
("iIndex", c_int), # 帧率索引号,一般0对应于低速模式,1对应于普通模式,2对应于高速模式
("acDescription", c_char * 32), # 描述信息
]
def GetDescription(self):
return _string_buffer_to_str(self.acDescription)
#相机曝光功能范围定义
class tSdkExpose(MvStructure):
_fields_ = [
("uiTargetMin", c_uint), #自动曝光亮度目标最小值
("uiTargetMax", c_uint), #自动曝光亮度目标最大值
("uiAnalogGainMin", c_uint), #模拟增益的最小值,单位为fAnalogGainStep中定义
("uiAnalogGainMax", c_uint), #模拟增益的最大值,单位为fAnalogGainStep中定义
("fAnalogGainStep", c_float), #模拟增益每增加1,对应的增加的放大倍数。例如,uiAnalogGainMin一般为16,fAnalogGainStep一般为0.125,那么最小放大倍数就是16*0.125 = 2倍
("uiExposeTimeMin", c_uint), #手动模式下,曝光时间的最小值,单位:行。根据CameraGetExposureLineTime可以获得一行对应的时间(微秒),从而得到整帧的曝光时间
("uiExposeTimeMax", c_uint), #手动模式下,曝光时间的最大值,单位:行
]
#触发模式描述
class tSdkTrigger(MvStructure):
_fields_ = [
("iIndex", c_int), # 模式索引号
("acDescription", c_char * 32), # 描述信息
]
def GetDescription(self):
return _string_buffer_to_str(self.acDescription)
#传输分包大小描述(主要是针对网络相机有效)
class tSdkPackLength(MvStructure):
_fields_ = [
("iIndex", c_int), # 模式索引号
("acDescription", c_char * 32), # 描述信息
("iPackSize", c_uint),
]
def GetDescription(self):
return _string_buffer_to_str(self.acDescription)
#预设的LUT表描述
class tSdkPresetLut(MvStructure):
_fields_ = [
("iIndex", c_int), # 编号
("acDescription", c_char * 32), # 描述信息
]
def GetDescription(self):
return _string_buffer_to_str(self.acDescription)
#AE算法描述
class tSdkAeAlgorithm(MvStructure):
_fields_ = [
("iIndex", c_int), # 编号
("acDescription", c_char * 32), # 描述信息
]
def GetDescription(self):
return _string_buffer_to_str(self.acDescription)
#RAW转RGB算法描述
class tSdkBayerDecodeAlgorithm(MvStructure):
_fields_ = [
("iIndex", c_int), # 编号
("acDescription", c_char * 32), # 描述信息
]
def GetDescription(self):
return _string_buffer_to_str(self.acDescription)
#帧率统计信息
class tSdkFrameStatistic(MvStructure):
_fields_ = [
("iTotal", c_int), #当前采集的总帧数(包括错误帧)
("iCapture", c_int), #当前采集的有效帧的数量
("iLost", c_int), #当前丢帧的数量
]
#相机输出的图像数据格式
class tSdkMediaType(MvStructure):
_fields_ = [
("iIndex", c_int), # 格式种类编号
("acDescription", c_char * 32), # 描述信息
("iMediaType", c_uint), # 对应的图像格式编码,如CAMERA_MEDIA_TYPE_BAYGR8。
]
def GetDescription(self):
return _string_buffer_to_str(self.acDescription)
#伽马的设定范围
class tGammaRange(MvStructure):
_fields_ = [
("iMin", c_int), #最小值
("iMax", c_int), #最大值
]
#对比度的设定范围
class tContrastRange(MvStructure):
_fields_ = [
("iMin", c_int), #最小值
("iMax", c_int), #最大值
]
#RGB三通道数字增益的设定范围
class tRgbGainRange(MvStructure):
_fields_ = [
("iRGainMin", c_int), #红色增益的最小值
("iRGainMax", c_int), #红色增益的最大值
("iGGainMin", c_int), #绿色增益的最小值
("iGGainMax", c_int), #绿色增益的最大值
("iBGainMin", c_int), #蓝色增益的最小值
("iBGainMax", c_int), #蓝色增益的最大值
]
#饱和度设定的范围
class tSaturationRange(MvStructure):
_fields_ = [
("iMin", c_int), #最小值
("iMax", c_int), #最大值
]
#锐化的设定范围
class tSharpnessRange(MvStructure):
_fields_ = [
("iMin", c_int), #最小值
("iMax", c_int), #最大值
]
#ISP模块的使能信息
class tSdkIspCapacity(MvStructure):
_fields_ = [
("bMonoSensor", c_int), #表示该型号相机是否为黑白相机,如果是黑白相机,则颜色相关的功能都无法调节
("bWbOnce", c_int), #表示该型号相机是否支持手动白平衡功能
("bAutoWb", c_int), #表示该型号相机是否支持自动白平衡功能
("bAutoExposure", c_int), #表示该型号相机是否支持自动曝光功能
("bManualExposure", c_int), #表示该型号相机是否支持手动曝光功能
("bAntiFlick", c_int), #表示该型号相机是否支持抗频闪功能
("bDeviceIsp", c_int), #表示该型号相机是否支持硬件ISP功能
("bForceUseDeviceIsp", c_int), #bDeviceIsp和bForceUseDeviceIsp同时为TRUE时,表示强制只用硬件ISP,不可取消。
("bZoomHD", c_int), #相机硬件是否支持图像缩放输出(只能是缩小)。
]
# 定义整合的设备描述信息,这些信息可以用于动态构建UI
class tSdkCameraCapbility(MvStructure):
_fields_ = [
("pTriggerDesc", POINTER(tSdkTrigger)),
("iTriggerDesc", c_int), #触发模式的个数,即pTriggerDesc数组的大小
("pImageSizeDesc", POINTER(tSdkImageResolution)),
("iImageSizeDesc", c_int), #预设分辨率的个数,即pImageSizeDesc数组的大小
("pClrTempDesc", POINTER(tSdkColorTemperatureDes)),
("iClrTempDesc", c_int), #预设色温个数
("pMediaTypeDesc", POINTER(tSdkMediaType)),
("iMediaTypeDesc", c_int), #相机输出图像格式的种类个数,即pMediaTypeDesc数组的大小。
("pFrameSpeedDesc", POINTER(tSdkFrameSpeed)), #可调节帧速类型,对应界面上普通 高速 和超级三种速度设置
("iFrameSpeedDesc", c_int), #可调节帧速类型的个数,即pFrameSpeedDesc数组的大小。
("pPackLenDesc", POINTER(tSdkPackLength)), #传输包长度,一般用于网络设备
("iPackLenDesc", c_int), #可供选择的传输分包长度的个数,即pPackLenDesc数组的大小。
("iOutputIoCounts", c_int), #可编程输出IO的个数
("iInputIoCounts", c_int), #可编程输入IO的个数
("pPresetLutDesc", POINTER(tSdkPresetLut)), #相机预设的LUT表
("iPresetLut", c_int), #相机预设的LUT表的个数,即pPresetLutDesc数组的大小
("iUserDataMaxLen", c_int), #指示该相机中用于保存用户数据区的最大长度。为0表示无。
("bParamInDevice", c_int), #指示该设备是否支持从设备中读写参数组。1为支持,0不支持。
("pAeAlmSwDesc", POINTER(tSdkAeAlgorithm)),#软件自动曝光算法描述
("iAeAlmSwDesc", c_int), #软件自动曝光算法个数
("pAeAlmHdDesc", POINTER(tSdkAeAlgorithm)),#硬件自动曝光算法描述,为NULL表示不支持硬件自动曝光
("iAeAlmHdDesc", c_int), #硬件自动曝光算法个数,为0表示不支持硬件自动曝光
("pBayerDecAlmSwDesc", POINTER(tSdkBayerDecodeAlgorithm)),#软件Bayer转换为RGB数据的算法描述
("iBayerDecAlmSwDesc", c_int), #软件Bayer转换为RGB数据的算法个数
("pBayerDecAlmHdDesc", POINTER(tSdkBayerDecodeAlgorithm)),#硬件Bayer转换为RGB数据的算法描述,为NULL表示不支持
("iBayerDecAlmHdDesc", c_int), #硬件Bayer转换为RGB数据的算法个数,为0表示不支持
# 图像参数的调节范围定义,用于动态构建UI
("sExposeDesc", tSdkExpose), #曝光的范围值
("sResolutionRange", tSdkResolutionRange), #分辨率范围描述
("sRgbGainRange", tRgbGainRange), #图像数字增益范围描述
("sSaturationRange", tSaturationRange), #饱和度范围描述
("sGammaRange", tGammaRange), #伽马范围描述
("sContrastRange", tContrastRange), #对比度范围描述
("sSharpnessRange", tSharpnessRange), #锐化范围描述
("sIspCapacity", tSdkIspCapacity), #ISP能力描述
]
#图像帧头信息
class tSdkFrameHead(MvStructure):
_fields_ = [
("uiMediaType", c_uint), # 图像格式,Image Format
("uBytes", c_uint), # 图像数据字节数,Total bytes
("iWidth", c_int), # 宽度 Image height
("iHeight", c_int), # 高度 Image width
("iWidthZoomSw", c_int), # 软件缩放的宽度,不需要进行软件裁剪的图像,此变量设置为0.
("iHeightZoomSw", c_int), # 软件缩放的高度,不需要进行软件裁剪的图像,此变量设置为0.
("bIsTrigger", c_int), # 指示是否为触发帧 is trigger
("uiTimeStamp", c_uint), # 该帧的采集时间,单位0.1毫秒
("uiExpTime", c_uint), # 当前图像的曝光值,单位为微秒us
("fAnalogGain", c_float), # 当前图像的模拟增益倍数
("iGamma", c_int), # 该帧图像的伽马设定值,仅当LUT模式为动态参数生成时有效,其余模式下为-1
("iContrast", c_int), # 该帧图像的对比度设定值,仅当LUT模式为动态参数生成时有效,其余模式下为-1
("iSaturation", c_int), # 该帧图像的饱和度设定值,对于黑白相机无意义,为0
("fRgain", c_float), # 该帧图像处理的红色数字增益倍数,对于黑白相机无意义,为1
("fGgain", c_float), # 该帧图像处理的绿色数字增益倍数,对于黑白相机无意义,为1
("fBgain", c_float), # 该帧图像处理的蓝色数字增益倍数,对于黑白相机无意义,为1
]
# Grabber统计信息
class tSdkGrabberStat(MvStructure):
_fields_ = [
("Width", c_int), # 帧图像大小
("Height", c_int), # 帧图像大小
("Disp", c_int), # 显示帧数量
("Capture", c_int), # 采集的有效帧的数量
("Lost", c_int), # 丢帧的数量
("Error", c_int), # 错帧的数量
("DispFps", c_float), # 显示帧率
("CapFps", c_float), # 捕获帧率
]
# 方法回调辅助类
class method(object):
def __init__(self, FuncType):
super(method, self).__init__()
self.FuncType = FuncType
self.cache = {}
def __call__(self, cb):
self.cb = cb
return self
def __get__(self, obj, objtype):
try:
return self.cache[obj]
except KeyError as e:
def cl(*args):
return self.cb(obj, *args)
r = self.cache[obj] = self.FuncType(cl)
return r
# 图像捕获的回调函数定义
CAMERA_SNAP_PROC = CALLBACK_FUNC_TYPE(None, c_int, c_void_p, POINTER(tSdkFrameHead), c_void_p)
# 相机连接状态回调
CAMERA_CONNECTION_STATUS_CALLBACK = CALLBACK_FUNC_TYPE(None, c_int, c_uint, c_uint, c_void_p)
# 异步抓图完成回调
pfnCameraGrabberSaveImageComplete = CALLBACK_FUNC_TYPE(None, c_void_p, c_void_p, c_int, c_void_p)
# 帧监听回调
pfnCameraGrabberFrameListener = CALLBACK_FUNC_TYPE(c_int, c_void_p, c_int, c_void_p, POINTER(tSdkFrameHead), c_void_p)
# 采集器图像捕获的回调
pfnCameraGrabberFrameCallback = CALLBACK_FUNC_TYPE(None, c_void_p, c_void_p, POINTER(tSdkFrameHead), c_void_p)
#-----------------------------------函数接口------------------------------------------
# 线程局部存储
_tls = local()
# 存储最后一次SDK调用返回的错误码
def GetLastError():
try:
return _tls.last_error
except AttributeError as e:
_tls.last_error = 0
return 0
def SetLastError(err_code):
_tls.last_error = err_code
def _string_buffer_to_str(buf):
s = buf if isinstance(buf, type(b'')) else buf.value
for codec in ('gbk', 'utf-8'):
try:
s = s.decode(codec)
break
except UnicodeDecodeError as e:
continue
if isinstance(s, str):
return s
else:
return s.encode('utf-8')
def _str_to_string_buffer(str):
if type(str) is type(u''):
s = str.encode('gbk')
else:
s = str.decode('utf-8').encode('gbk')
return create_string_buffer(s)
def CameraSdkInit(iLanguageSel):
err_code = _sdk.CameraSdkInit(iLanguageSel)
SetLastError(err_code)
return err_code
def CameraEnumerateDevice(MaxCount = 32):
Nums = c_int(MaxCount)
pCameraList = (tSdkCameraDevInfo * Nums.value)()
err_code = _sdk.CameraEnumerateDevice(pCameraList, byref(Nums))
SetLastError(err_code)
return pCameraList[0:Nums.value]
def CameraEnumerateDeviceEx():
return _sdk.CameraEnumerateDeviceEx()
def CameraIsOpened(pCameraInfo):
pOpened = c_int()
err_code = _sdk.CameraIsOpened(byref(pCameraInfo), byref(pOpened) )
SetLastError(err_code)
return pOpened.value != 0
def CameraInit(pCameraInfo, emParamLoadMode = -1, emTeam = -1):
pCameraHandle = c_int()
err_code = _sdk.CameraInit(byref(pCameraInfo), emParamLoadMode, emTeam, byref(pCameraHandle))
SetLastError(err_code)
if err_code != 0:
raise CameraException(err_code)
return pCameraHandle.value
def CameraInitEx(iDeviceIndex, emParamLoadMode = -1, emTeam = -1):
pCameraHandle = c_int()
err_code = _sdk.CameraInitEx(iDeviceIndex, emParamLoadMode, emTeam, byref(pCameraHandle))
SetLastError(err_code)
if err_code != 0:
raise CameraException(err_code)
return pCameraHandle.value
def CameraInitEx2(CameraName):
pCameraHandle = c_int()
err_code = _sdk.CameraInitEx2(_str_to_string_buffer(CameraName), byref(pCameraHandle))
SetLastError(err_code)
if err_code != 0:
raise CameraException(err_code)
return pCameraHandle.value
def CameraSetCallbackFunction(hCamera, pCallBack, pContext = 0):
err_code = _sdk.CameraSetCallbackFunction(hCamera, pCallBack, c_void_p(pContext), None)
SetLastError(err_code)
return err_code
def CameraUnInit(hCamera):
err_code = _sdk.CameraUnInit(hCamera)
SetLastError(err_code)
return err_code
def CameraGetInformation(hCamera):
pbuffer = c_char_p()
err_code = _sdk.CameraGetInformation(hCamera, byref(pbuffer) )
SetLastError(err_code)
if err_code == 0 and pbuffer.value is not None:
return _string_buffer_to_str(pbuffer)
return ''
def CameraImageProcess(hCamera, pbyIn, pbyOut, pFrInfo):
err_code = _sdk.CameraImageProcess(hCamera, c_void_p(pbyIn), c_void_p(pbyOut), byref(pFrInfo))
SetLastError(err_code)
return err_code
def CameraImageProcessEx(hCamera, pbyIn, pbyOut, pFrInfo, uOutFormat, uReserved):
err_code = _sdk.CameraImageProcessEx(hCamera, c_void_p(pbyIn), c_void_p(pbyOut), byref(pFrInfo), uOutFormat, uReserved)
SetLastError(err_code)
return err_code
def CameraDisplayInit(hCamera, hWndDisplay):
err_code = _sdk.CameraDisplayInit(hCamera, hWndDisplay)
SetLastError(err_code)
return err_code
def CameraDisplayRGB24(hCamera, pFrameBuffer, pFrInfo):
err_code = _sdk.CameraDisplayRGB24(hCamera, c_void_p(pFrameBuffer), byref(pFrInfo) )
SetLastError(err_code)
return err_code
def CameraSetDisplayMode(hCamera, iMode):
err_code = _sdk.CameraSetDisplayMode(hCamera, iMode)
SetLastError(err_code)
return err_code
def CameraSetDisplayOffset(hCamera, iOffsetX, iOffsetY):
err_code = _sdk.CameraSetDisplayOffset(hCamera, iOffsetX, iOffsetY)
SetLastError(err_code)
return err_code
def CameraSetDisplaySize(hCamera, iWidth, iHeight):
err_code = _sdk.CameraSetDisplaySize(hCamera, iWidth, iHeight)
SetLastError(err_code)
return err_code
def CameraGetImageBuffer(hCamera, wTimes):
pbyBuffer = c_void_p()
pFrameInfo = tSdkFrameHead()
err_code = _sdk.CameraGetImageBuffer(hCamera, byref(pFrameInfo), byref(pbyBuffer), wTimes)
SetLastError(err_code)
if err_code != 0:
raise CameraException(err_code)
return (pbyBuffer.value, pFrameInfo)
def CameraGetImageBufferEx(hCamera, wTimes):
_sdk.CameraGetImageBufferEx.restype = c_void_p
piWidth = c_int()
piHeight = c_int()
pFrameBuffer = _sdk.CameraGetImageBufferEx(hCamera, byref(piWidth), byref(piHeight), wTimes)
err_code = CAMERA_STATUS_SUCCESS if pFrameBuffer else CAMERA_STATUS_TIME_OUT
SetLastError(err_code)
if pFrameBuffer:
return (pFrameBuffer, piWidth.value, piHeight.value)
else:
raise CameraException(err_code)
def CameraSnapToBuffer(hCamera, wTimes):
pbyBuffer = c_void_p()
pFrameInfo = tSdkFrameHead()
err_code = _sdk.CameraSnapToBuffer(hCamera, byref(pFrameInfo), byref(pbyBuffer), wTimes)
SetLastError(err_code)
if err_code != 0:
raise CameraException(err_code)
return (pbyBuffer.value, pFrameInfo)
def CameraReleaseImageBuffer(hCamera, pbyBuffer):
err_code = _sdk.CameraReleaseImageBuffer(hCamera, c_void_p(pbyBuffer) )
SetLastError(err_code)
return err_code
def CameraPlay(hCamera):
err_code = _sdk.CameraPlay(hCamera)
SetLastError(err_code)
return err_code
def CameraPause(hCamera):
err_code = _sdk.CameraPause(hCamera)
SetLastError(err_code)
return err_code
def CameraStop(hCamera):
err_code = _sdk.CameraStop(hCamera)
SetLastError(err_code)
return err_code
def CameraInitRecord(hCamera, iFormat, pcSavePath, b2GLimit, dwQuality, iFrameRate):
err_code = _sdk.CameraInitRecord(hCamera, iFormat, _str_to_string_buffer(pcSavePath), b2GLimit, dwQuality, iFrameRate)
SetLastError(err_code)
return err_code
def CameraStopRecord(hCamera):
err_code = _sdk.CameraStopRecord(hCamera)
SetLastError(err_code)
return err_code
def CameraPushFrame(hCamera, pbyImageBuffer, pFrInfo):
err_code = _sdk.CameraPushFrame(hCamera, c_void_p(pbyImageBuffer), byref(pFrInfo) )
SetLastError(err_code)
return err_code
def CameraSaveImage(hCamera, lpszFileName, pbyImageBuffer, pFrInfo, byFileType, byQuality):
err_code = _sdk.CameraSaveImage(hCamera, _str_to_string_buffer(lpszFileName), c_void_p(pbyImageBuffer), byref(pFrInfo), byFileType, byQuality)
SetLastError(err_code)
return err_code
def CameraSaveImageEx(hCamera, lpszFileName, pbyImageBuffer, uImageFormat, iWidth, iHeight, byFileType, byQuality):
err_code = _sdk.CameraSaveImageEx(hCamera, _str_to_string_buffer(lpszFileName), c_void_p(pbyImageBuffer), uImageFormat, iWidth, iHeight, byFileType, byQuality)
SetLastError(err_code)
return err_code
def CameraGetImageResolution(hCamera):
psCurVideoSize = tSdkImageResolution()
err_code = _sdk.CameraGetImageResolution(hCamera, byref(psCurVideoSize) )
SetLastError(err_code)
return psCurVideoSize
def CameraSetImageResolution(hCamera, pImageResolution):
err_code = _sdk.CameraSetImageResolution(hCamera, byref(pImageResolution) )
SetLastError(err_code)
return err_code
def CameraSetImageResolutionEx(hCamera, iIndex, Mode, ModeSize, x, y, width, height, ZoomWidth, ZoomHeight):
err_code = _sdk.CameraSetImageResolutionEx(hCamera, iIndex, Mode, ModeSize, x, y, width, height, ZoomWidth, ZoomHeight)
SetLastError(err_code)
return err_code
def CameraGetMediaType(hCamera):
piMediaType = c_int()
err_code = _sdk.CameraGetMediaType(hCamera, byref(piMediaType) )
SetLastError(err_code)
return piMediaType.value
def CameraSetMediaType(hCamera, iMediaType):
err_code = _sdk.CameraSetMediaType(hCamera, iMediaType)
SetLastError(err_code)
return err_code
def CameraSetAeState(hCamera, bAeState):
err_code = _sdk.CameraSetAeState(hCamera, bAeState)
SetLastError(err_code)
return err_code
def CameraGetAeState(hCamera):
pAeState = c_int()
err_code = _sdk.CameraGetAeState(hCamera, byref(pAeState) )
SetLastError(err_code)
return pAeState.value
def CameraSetSharpness(hCamera, iSharpness):
err_code = _sdk.CameraSetSharpness(hCamera, iSharpness)
SetLastError(err_code)
return err_code
def CameraGetSharpness(hCamera):
piSharpness = c_int()
err_code = _sdk.CameraGetSharpness(hCamera, byref(piSharpness) )
SetLastError(err_code)
return piSharpness.value
def CameraSetLutMode(hCamera, emLutMode):
err_code = _sdk.CameraSetLutMode(hCamera, emLutMode)
SetLastError(err_code)
return err_code
def CameraGetLutMode(hCamera):
pemLutMode = c_int()
err_code = _sdk.CameraGetLutMode(hCamera, byref(pemLutMode) )
SetLastError(err_code)
return pemLutMode.value
def CameraSelectLutPreset(hCamera, iSel):
err_code = _sdk.CameraSelectLutPreset(hCamera, iSel)
SetLastError(err_code)
return err_code
def CameraGetLutPresetSel(hCamera):
piSel = c_int()
err_code = _sdk.CameraGetLutPresetSel(hCamera, byref(piSel) )
SetLastError(err_code)
return piSel.value
def CameraSetCustomLut(hCamera, iChannel, pLut):
pLutNative = (c_ushort * 4096)(*pLut)
err_code = _sdk.CameraSetCustomLut(hCamera, iChannel, pLutNative)
SetLastError(err_code)
return err_code
def CameraGetCustomLut(hCamera, iChannel):
pLutNative = (c_ushort * 4096)()
err_code = _sdk.CameraGetCustomLut(hCamera, iChannel, pLutNative)
SetLastError(err_code)
return pLutNative[:]
def CameraGetCurrentLut(hCamera, iChannel):
pLutNative = (c_ushort * 4096)()
err_code = _sdk.CameraGetCurrentLut(hCamera, iChannel, pLutNative)
SetLastError(err_code)
return pLutNative[:]
def CameraSetWbMode(hCamera, bAuto):
err_code = _sdk.CameraSetWbMode(hCamera, bAuto)
SetLastError(err_code)
return err_code
def CameraGetWbMode(hCamera):
pbAuto = c_int()
err_code = _sdk.CameraGetWbMode(hCamera, byref(pbAuto) )
SetLastError(err_code)
return pbAuto.value
def CameraSetPresetClrTemp(hCamera, iSel):
err_code = _sdk.CameraSetPresetClrTemp(hCamera, iSel)
SetLastError(err_code)
return err_code
def CameraGetPresetClrTemp(hCamera):
piSel = c_int()
err_code = _sdk.CameraGetPresetClrTemp(hCamera, byref(piSel) )
SetLastError(err_code)
return piSel.value
def CameraSetUserClrTempGain(hCamera, iRgain, iGgain, iBgain):
err_code = _sdk.CameraSetUserClrTempGain(hCamera, iRgain, iGgain, iBgain)
SetLastError(err_code)
return err_code
def CameraGetUserClrTempGain(hCamera):
piRgain = c_int()
piGgain = c_int()
piBgain = c_int()
err_code = _sdk.CameraGetUserClrTempGain(hCamera, byref(piRgain), byref(piGgain), byref(piBgain) )
SetLastError(err_code)
return (piRgain.value, piGgain.value, piBgain.value)
def CameraSetUserClrTempMatrix(hCamera, pMatrix):
pMatrixNative = (c_float * 9)(*pMatrix)
err_code = _sdk.CameraSetUserClrTempMatrix(hCamera, pMatrixNative)
SetLastError(err_code)
return err_code
def CameraGetUserClrTempMatrix(hCamera):
pMatrixNative = (c_float * 9)()
err_code = _sdk.CameraGetUserClrTempMatrix(hCamera, pMatrixNative)
SetLastError(err_code)
return pMatrixNative[:]
def CameraSetClrTempMode(hCamera, iMode):
err_code = _sdk.CameraSetClrTempMode(hCamera, iMode)
SetLastError(err_code)
return err_code
def CameraGetClrTempMode(hCamera):
piMode = c_int()
err_code = _sdk.CameraGetClrTempMode(hCamera, byref(piMode) )
SetLastError(err_code)
return piMode.value
def CameraSetOnceWB(hCamera):
err_code = _sdk.CameraSetOnceWB(hCamera)
SetLastError(err_code)
return err_code
def CameraSetOnceBB(hCamera):
err_code = _sdk.CameraSetOnceBB(hCamera)
SetLastError(err_code)
return err_code
def CameraSetAeTarget(hCamera, iAeTarget):
err_code = _sdk.CameraSetAeTarget(hCamera, iAeTarget)
SetLastError(err_code)
return err_code
def CameraGetAeTarget(hCamera):
piAeTarget = c_int()
err_code = _sdk.CameraGetAeTarget(hCamera, byref(piAeTarget) )
SetLastError(err_code)
return piAeTarget.value
def CameraSetAeExposureRange(hCamera, fMinExposureTime, fMaxExposureTime):
err_code = _sdk.CameraSetAeExposureRange(hCamera, c_double(fMinExposureTime), c_double(fMaxExposureTime) )
SetLastError(err_code)
return err_code
def CameraGetAeExposureRange(hCamera):
fMinExposureTime = c_double()
fMaxExposureTime = c_double()
err_code = _sdk.CameraGetAeExposureRange(hCamera, byref(fMinExposureTime), byref(fMaxExposureTime) )
SetLastError(err_code)
return (fMinExposureTime.value, fMaxExposureTime.value)
def CameraSetAeAnalogGainRange(hCamera, iMinAnalogGain, iMaxAnalogGain):
err_code = _sdk.CameraSetAeAnalogGainRange(hCamera, iMinAnalogGain, iMaxAnalogGain)
SetLastError(err_code)
return err_code
def CameraGetAeAnalogGainRange(hCamera):
iMinAnalogGain = c_int()
iMaxAnalogGain = c_int()
err_code = _sdk.CameraGetAeAnalogGainRange(hCamera, byref(iMinAnalogGain), byref(iMaxAnalogGain) )
SetLastError(err_code)
return (iMinAnalogGain.value, iMaxAnalogGain.value)
def CameraSetAeThreshold(hCamera, iThreshold):
err_code = _sdk.CameraSetAeThreshold(hCamera, iThreshold)
SetLastError(err_code)
return err_code
def CameraGetAeThreshold(hCamera):