大华工业相机图像采集Python代码实现
Posted zfsn
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了大华工业相机图像采集Python代码实现相关的知识,希望对你有一定的参考价值。
1 #!/usr/bin/env python 2 # coding: utf-8 3 ‘‘‘ 4 Created on 2017-10-25 5 6 @author: 7 ‘‘‘ 8 9 from ImageConvert import * 10 from MVSDK import * 11 import time 12 import numpy 13 import gc 14 from PIL import Image 15 from queue import Queue 16 # from Helper import MessageBox 17 18 19 class Camera: 20 21 def __init__(self): 22 23 self.g_cameraStatusUserInfo = b"statusInfo" 24 self.g_Image_Grabbing_Timer = 10 # unit : s 25 self.g_isStop = 0 26 self.connectCallBackFuncEx = connectCallBackEx(self.deviceLinkNotify) 27 self.frameCallbackFuncEx = callbackFuncEx(self.onGetFrameEx) 28 self.dev = None 29 self.qimage = Queue(maxsize=0) 30 self.userInfo = b"test" 31 # self.messagebox = MessageBox() 32 33 def onGetFrameEx(self, frame, userInfo): 34 """ 取流回调函数Ex """ 35 if (self.g_isStop == 1): 36 return 37 38 nRet = frame.contents.valid(frame) 39 if (nRet != 0): 40 print("frame is invalid!") 41 # 释放驱动图像缓存资源 42 frame.contents.release(frame) 43 return 44 45 print("BlockId = {}".format(str(frame.contents.getBlockId(frame)))) 46 47 #此处客户应用程序应将图像拷贝出使用 48 # 给转码所需的参数赋值 49 imageParams = IMGCNV_SOpenParam() 50 imageParams.dataSize = frame.contents.getImageSize(frame) 51 imageParams.height = frame.contents.getImageHeight(frame) 52 imageParams.width = frame.contents.getImageWidth(frame) 53 imageParams.paddingX = frame.contents.getImagePaddingX(frame) 54 imageParams.paddingY = frame.contents.getImagePaddingY(frame) 55 imageParams.pixelForamt = frame.contents.getImagePixelFormat(frame) 56 57 # 将裸数据图像拷出 58 imageBuff = frame.contents.getImage(frame) 59 userBuff = c_buffer(b‘