解决python demo停止扫描流程,修改扫描出的图片文件名
This commit is contained in:
parent
b5863c2670
commit
4d6c5a9a3a
|
@ -4,6 +4,7 @@ from os import system
|
|||
import time
|
||||
import platform
|
||||
from ctypes import *
|
||||
import random
|
||||
|
||||
class HGLibSaveImageParam(Structure):
|
||||
_fields_ = [ ("size", c_uint),
|
||||
|
@ -78,25 +79,37 @@ HGLib_SetDeviceParam.restype = ctypes.c_int
|
|||
DevParam = ctypes.c_int(1) #HGLIB_OPTION_ENUMVALUE_DLSCLX_W -> 不进行多流输出类型
|
||||
Ret = HGLib_SetDeviceParam(Device, 1, byref(DevParam)) #见HGLib_SetDeviceParam 头文件接口说明 1 -> HGLIB_OPTION_NAME_DLSC 多流输出
|
||||
|
||||
bStop=False
|
||||
|
||||
#扫描事件回调
|
||||
def HGLibDeviceScanEventFunc(device: c_void_p, event: c_uint, err: c_int, info: c_char_p, param: c_void_p):
|
||||
print(info)
|
||||
s_info=info
|
||||
global bStop
|
||||
print("event code",event," event info:",s_info)
|
||||
if event == 2:#HGLIB_DEVSCAN_EVENT_END 扫描停止
|
||||
bStop=True
|
||||
print("bStop true")
|
||||
elif event == 1:
|
||||
bStop=False
|
||||
print("bStop false")
|
||||
return
|
||||
|
||||
imgindex=0
|
||||
#扫描图像事件回调
|
||||
def HGLibDeviceScanImageFunc(device: c_void_p, image: c_void_p, param: c_void_p):
|
||||
global imgindex
|
||||
ImageParam = HGLibSaveImageParam()
|
||||
ImageParam.size = 20
|
||||
ImageParam.jpegQuality = 100
|
||||
ImageParam.tiffCompression = 0
|
||||
ImageParam.tiffJpegQuality = 0
|
||||
ImageParam.ocr = 0
|
||||
Ret = HGLib_SaveImage(image, c_char_p(b"3.jpg"), pointer(ImageParam))
|
||||
print("image call back!!")
|
||||
imgindex+=1
|
||||
t_index=imgindex
|
||||
imgname=str(t_index) + '_scanned.jpg'
|
||||
print(imgname)
|
||||
b_imagename=imgname.encode('utf-8')
|
||||
pchar=c_char_p(b_imagename)
|
||||
Ret = HGLib_SaveImage(image, pchar, pointer(ImageParam))
|
||||
return
|
||||
|
||||
#注册扫描相关事件并启动扫描
|
||||
|
@ -111,9 +124,12 @@ print("start scan")
|
|||
Ret = HGLib_StartDeviceScan(Device, cb1, 0, cb2, 0)
|
||||
|
||||
#模拟扫描持续应等待扫描事件回调返回扫描停止才结束本次扫描流程
|
||||
while(bStop != True):
|
||||
while(not bStop):
|
||||
time.sleep(1)
|
||||
break;
|
||||
print("scanning...")
|
||||
|
||||
|
||||
print("scan done!!!")
|
||||
|
||||
#关闭当前打开的设备
|
||||
HGLib_CloseDevice=Objdll.HGLib_CloseDevice
|
||||
|
|
Loading…
Reference in New Issue