def getCurrentFrame(self): nRet = ueye.is_FreezeVideo(self.hCam, ueye.IS_WAIT) if nRet != ueye.IS_SUCCESS: print("is_GetCameraInfo ERROR") # Enables the queue mode for existing image memory sequences nRet = ueye.is_InquireImageMem(self.hCam, self.pcImageMemory, self.MemID, self.width, self.height, self.nBitsPerPixel, self.pitch) if nRet != ueye.IS_SUCCESS: print("is_InquireImageMem ERROR") print("getting image") array = ueye.get_data(self.pcImageMemory, self.width, self.height, self.nBitsPerPixel, self.pitch, copy=False) frame = np.reshape( array, (self.height.value, self.width.value, self.bytes_per_pixel)) print(frame.shape) coadd = np.zeros(frame.shape[0:2]).astype('float') #coadd[:,:] = (frame[:,:,1]*255).astype('float')+frame[:,:,0].astype('float') coadd[:, :] = frame[:, :, 1].astype('float') * 255 + frame[:, :, 0].astype('float') return coadd
def setMemroyForVideoCapture(self): nRet = ueye.is_AllocImageMem(self.hCam, self.width, self.height, self.nBitsPerPixel, self.pcImageMemory, self.MemID) if nRet != ueye.IS_SUCCESS: print("is_AllocImageMem ERROR") else: # Makes the specified image memory the active memory nRet = ueye.is_SetImageMem(self.hCam, self.pcImageMemory, self.MemID) if nRet != ueye.IS_SUCCESS: print("is_SetImageMem ERROR") else: # Set the desired color mode nRet = ueye.is_SetColorMode(self.hCam, self.m_nColorMode) # Activates the camera's live video mode (free run mode) nRet = ueye.is_CaptureVideo(self.hCam, ueye.IS_DONT_WAIT) if nRet != ueye.IS_SUCCESS: print("is_CaptureVideo ERROR") # Enables the queue mode for existing image memory sequences nRet = ueye.is_InquireImageMem(self.hCam, self.pcImageMemory, self.MemID, self.width, self.height, self.nBitsPerPixel, self.pitch) if nRet != ueye.IS_SUCCESS: print("is_InquireImageMem ERROR") else: print("Press q to leave the programm")
def allocateMemory(self): # Allocates an image memory for an image having its dimensions defined by self.width and height and its color depth defined by self.nBitsPerPixel nRet = ueye.is_AllocImageMem(self.hCam, self.width, self.height, self.nBitsPerPixel, self.pcImageMemory, self.MemID) if nRet != ueye.IS_SUCCESS: print("is_AllocImageMem ERROR") else: # Makes the specified image memory the active memory nRet = ueye.is_SetImageMem(self.hCam, self.pcImageMemory, self.MemID) if nRet != ueye.IS_SUCCESS: print("is_SetImageMem ERROR") else: # Set the desired color mode nRet = ueye.is_SetColorMode(self.hCam, self.m_nColorMode) # Activates the camera's live video mode (free run mode) nRet = ueye.is_CaptureVideo(self.hCam, ueye.IS_DONT_WAIT) if nRet != ueye.IS_SUCCESS: print("is_CaptureVideo ERROR") # Enables the queue mode for existing image memory sequences nRet = ueye.is_InquireImageMem(self.hCam, self.pcImageMemory, self.MemID, self.width, self.height, self.nBitsPerPixel, self.pitch) if nRet != ueye.IS_SUCCESS: print("is_InquireImageMem ERROR")
def show_image(self): nRet = ueye.is_InitCamera(self.h_cam, None) nRet = ueye.is_SetDisplayMode(self.h_cam, ueye.IS_SET_DM_DIB) nRet = ueye.is_AOI(self.h_cam, ueye.IS_AOI_IMAGE_GET_AOI, self.rectAOI, ueye.sizeof(self.rectAOI)) self.width = self.rectAOI.s32Width self.height = self.rectAOI.s32Height nRet = ueye.is_AllocImageMem(self.h_cam, self.width, self.height, self.nBitsPerPixel, self.pcImageMemory, self.MemID) nRet = ueye.is_SetImageMem(self.h_cam, self.pcImageMemory, self.MemID) nRet = ueye.is_SetColorMode(self.h_cam, self.ColorMode) nRet = ueye.is_CaptureVideo(self.h_cam, ueye.IS_DONT_WAIT) nRet = ueye.is_InquireImageMem(self.h_cam, self.pcImageMemory, self.MemID, self.width, self.height, self.nBitsPerPixel, self.pitch) while nRet == ueye.IS_SUCCESS: array = ueye.get_data(self.pcImageMemory, self.width, self.height, self.nBitsPerPixel, self.pitch, copy=False) frame = np.reshape( array, (self.height.value, self.width.value, self.bytes_per_pixel)) frame = cv2.resize(frame, (0, 0), fx=0.5, fy=0.5) size = (self.height, self.width) new_camera_matrix, roi = cv2.getOptimalNewCameraMatrix( self.camera_matrix, self.dist_coeff, size, 1, size) dst = cv2.undistort(frame, self.camera_matrix, self.dist_coeff, None, new_camera_matrix) x, y, w, h = roi self.dst = dst[y:y + h, x:x + w] self.detect_colors() self.extrinsic_calibration() cv2.imshow("camera", self.dst) if cv2.waitKey(1) & 0xFF == ord('q'): break elif cv2.waitKey(1) & 0xFF == ord('t'): cv2.imwrite("/home/lennart/dorna/camera/images/gps.bmp", self.dst) elif cv2.waitKey(100) & 0xFF == ord('l'): self.found_container = False self.container_world_position.clear() print("Behälterposition zurückgesetzt") ueye.is_FreeImageMem(self.h_cam, self.pcImageMemory, self.MemID) ueye.is_ExitCamera(self.h_cam) cv2.destroyAllWindows()
def acquireimage(self): self.ret = ueye.is_CaptureVideo(self.hcam, ueye.IS_DONT_WAIT) if self.ret != ueye.IS_SUCCESS: print("is Error") self.ret = ueye.is_InquireImageMem(self.hcam, self.pcImageMemory, self.MemID, self.width, self.height, self.nBitsPerPixel, self.pitch) if self.ret != ueye.IS_SUCCESS: print("is_InquireImageMem ERROR") else: print("Press q to leave the programm")
def __init__(self): super(CamDialog, self).__init__() loadUi('cam.ui', self) self.image=None self.roi_color=None self.startButton.clicked.connect(self.start_webcam) self.stopButton.clicked.connect(self.stop_webcam) # self.detectButton.setCheckable(True) # self.detectButton.toggled.connect(self.detect_webcam_face) self.face_Enabled=False self.faceCascade=cv2.CascadeClassifier('haarcascade_frontalface_default.xml') self.hCam = ueye.HIDS(0) # 0: first available camera; 1-254: The camera with the specified camera ID self.sInfo = ueye.SENSORINFO() self.cInfo = ueye.CAMINFO() self.pcImageMemory = ueye.c_mem_p() self.MemID = ueye.int() self.rectAOI = ueye.IS_RECT() self.pitch = ueye.INT() self.nBitsPerPixel = ueye.INT(24) # 24: bits per pixel for color mode; take 8 bits per pixel for monochrome self.channels = 3 # 3: channels for color mode(RGB); take 1 channel for monochrome self.m_nColorMode = ueye.INT() # Y8/RGB16/RGB24/REG32 self.bytes_per_pixel = int(self.nBitsPerPixel / 8) self.nRet = ueye.is_InitCamera(self.hCam, None) self.nRet = ueye.is_GetCameraInfo(self.hCam, self.cInfo) self.nRet = ueye.is_GetSensorInfo(self.hCam, self.sInfo) self.nRet = ueye.is_ResetToDefault(self.hCam) self.nRet = ueye.is_SetDisplayMode(self.hCam, ueye.IS_SET_DM_DIB) ueye.is_GetColorDepth(self.hCam, self.nBitsPerPixel, self.m_nColorMode) self.nRet = ueye.is_AOI(self.hCam, ueye.IS_AOI_IMAGE_GET_AOI, self.rectAOI, ueye.sizeof(self.rectAOI)) self.width = self.rectAOI.s32Width self.height = self.rectAOI.s32Height self.nRet = ueye.is_AllocImageMem(self.hCam, self.width, self.height, self.nBitsPerPixel, self.pcImageMemory, self.MemID) self.nRet = ueye.is_SetImageMem(self.hCam, self.pcImageMemory, self.MemID) self.nRet = ueye.is_SetColorMode(self.hCam, self.m_nColorMode) self.nRet = ueye.is_CaptureVideo(self.hCam, ueye.IS_DONT_WAIT) self.nRet = ueye.is_InquireImageMem(self.hCam, self.pcImageMemory, self.MemID, self.width, self.height, self.nBitsPerPixel, self.pitch) self.xp=[] self.yp=[] self.lxp=[] self.lyp = [] self.rxp = [] self.ryp = [] self.sx = 200 self.sy = 150 self.endx = 600 self.endy = 450 # self.avgx = 0 # self.avgy = 0 self.holeflag = 0 self.lflag = 0 self.rflag = 0
def capture_video(self): # Activates the camera's live video mode (free run mode) nRet = ueye.is_CaptureVideo(self.hCam, ueye.IS_DONT_WAIT) if nRet != ueye.IS_SUCCESS: print("is_CaptureVideo ERROR") # Enables the queue mode for existing image memory sequences nRet = ueye.is_InquireImageMem(self.hCam, self.pcImageMemory, self.MemID, self.rectAOI.s32Width, self.rectAOI.s32Height, self.nBitsPerPixel, self.pitch) if nRet != ueye.IS_SUCCESS: print("is_InquireImageMem ERROR")
def init_acquisition(self): """ Allocate the computer memory according to the size of the image and start the acquisition. """ # Allocate memory for the acquisition # ----------------------------------- self.width = self.rectAOI.s32Width self.height = self.rectAOI.s32Height Allocate_memory = ueye.is_AllocImageMem(self.hcam, self.width, self.height, self.nBitsPerPixel, self.pcImageMemory, self.MemID) if Allocate_memory != ueye.IS_SUCCESS: print("is_AllocImageMem ERROR") return else: # Makes the specified image memory the active memory Allocate_memory = ueye.is_SetImageMem(self.hcam, self.pcImageMemory, self.MemID) if Allocate_memory != ueye.IS_SUCCESS: print("is_SetImageMem ERROR") return else: # Set the desired color mode Color_mode = ueye.is_SetColorMode(self.hcam, self.m_nColorMode) # Activates the camera's live video mode (free run mode) # ------------------------------------------------------ Launch_capture = ueye.is_CaptureVideo(self.hcam, ueye.IS_DONT_WAIT) if Launch_capture != ueye.IS_SUCCESS: print("is_CaptureVideo ERROR") return # Enables the queue mode for existing image memory sequences nRet = ueye.is_InquireImageMem(self.hcam, self.pcImageMemory, self.MemID, self.width, self.height, self.nBitsPerPixel, self.pitch) if nRet != ueye.IS_SUCCESS: print("is_InquireImageMem ERROR") return # Launch the live acquisition # --------------------------- self.acquire()
def go_live(self): if not ueye.is_CaptureVideo(self.cam, ueye.IS_DONT_WAIT) == ueye.IS_SUCCESS: raise RuntimeError("Capture mode failed") if not ueye.is_InquireImageMem(self.cam, self.image_memory, self.memory_id, self.width, self.height, self.bits_per_pixel, self.pitch) == ueye.IS_SUCCESS: raise RuntimeError("Memory inquiry failed") print("Pitch is {}".format(self.pitch)) print("Camera in live mode")
def __init__(self, h_cam, img_buff): self.x = ueye.int() self.y = ueye.int() self.bits = ueye.int() self.pitch = ueye.int() self.img_buff = img_buff rect_aoi = ueye.IS_RECT() check(ueye.is_AOI(h_cam, ueye.IS_AOI_IMAGE_GET_AOI, rect_aoi, ueye.sizeof(rect_aoi))) self.width = rect_aoi.s32Width.value self.height = rect_aoi.s32Height.value check(ueye.is_InquireImageMem(h_cam, self.img_buff.mem_ptr, self.img_buff.mem_id, self.x, self.y, self.bits, self.pitch))
def give_da_stream(): hCam, sInfo, cInfo, pcImageMemory, MemID, rectAOI, pitch, nBitsPerPixel, channels, m_nColorMode, bytes_per_pixel, height, width = init_camera( ) nRet = ueye.is_CaptureVideo(hCam, ueye.IS_DONT_WAIT) nRet = ueye.is_InquireImageMem(hCam, pcImageMemory, MemID, width, height, nBitsPerPixel, pitch) try: while (nRet == ueye.IS_SUCCESS): # In order to display the image in an OpenCV window we need to... # ...extract the data of our image memory array = ueye.get_data(pcImageMemory, width, height, nBitsPerPixel, pitch, copy=False) # bytes_per_pixel = int(nBitsPerPixel / 8) # ...reshape it in an numpy array... frame = np.reshape(array, (height.value, width.value, bytes_per_pixel)) # ...resize the image by a half # frame = cv2.resize(frame,(0,0),fx=0.5, fy=0.5) # Press q if you want to end the loop # Press q if you want to end the loop yield frame # --------------------------------------------------------------------------------------------------------------------------------------- # Include image data processing here # --------------------------------------------------------------------------------------------------------------------------------------- finally: # Releases an image memory that was allocated using is_AllocImageMem() and removes it from the driver management ueye.is_FreeImageMem(hCam, pcImageMemory, MemID) # Disables the hCam camera handle and releases the data structures and memory areas taken up by the uEye camera ueye.is_ExitCamera(hCam)
def initialize_modes(self): ''' Enables live video mode. Enables queue mode. Sets: self.pitch ''' # Activates the camera's live video mode (free run mode) nRet = ueye.is_CaptureVideo(self.input, ueye.IS_DONT_WAIT) if nRet != ueye.IS_SUCCESS: log.error("is_CaptureVideo ERROR") # Enables the queue mode for existing image memory sequences self.pitch = ueye.INT() nRet = ueye.is_InquireImageMem(self.input, self.mem_image, self.mem_id, self.width, self.height, self.bits_per_pixel, self.pitch) if nRet != ueye.IS_SUCCESS: log.error("is_InquireImageMem ERROR")
def start_video_capture(self): # Activates the camera's live video mode (free run mode) err = ueye.is_CaptureVideo(self._cam, ueye.IS_WAIT) if err != ueye.IS_SUCCESS: raise CameraException(self._cam, 'ueye>video_capture>', err, False) err = ueye.is_InquireImageMem( self._cam, self._ppc_img_mem, self._mem_id, self._width, self._height, self._nBitsPerPixel, self._pitch, ) if err != ueye.IS_SUCCESS: raise CameraException(self._cam, 'ueye>video_capture>', err, False) self._video_capture = True
def start_video_capture(self): # Activates the camera's live video mode (free run mode) err = pue.is_CaptureVideo(self._cam, pue.IS_DONT_WAIT) if err != pue.IS_SUCCESS: raise CameraException(self._cam, 'ueye>video_capture', err, False) self._pitch = pue.INT() err = pue.is_InquireImageMem( self._cam, self._ppc_img_mem, self._mem_id, self._c_width, self._c_height, self._c_pixel_bits, self._pitch, ) if err != pue.IS_SUCCESS: raise CameraException(self._cam, 'ueye>video_capture', err, False) self._video_capture = True
def run(self): a = ueye.is_InitCamera(self.hCam, None) b = ueye.is_GetCameraInfo(self.hCam, self.cInfo) c = ueye.is_GetSensorInfo(self.hCam, self.sInfo) d = ueye.is_ResetToDefault(self.hCam) e = ueye.is_SetDisplayMode(self.hCam, ueye.IS_SET_DM_DIB) g = ueye.is_AOI(self.hCam, ueye.IS_AOI_IMAGE_GET_AOI, self.rectAOI, ueye.sizeof(self.rectAOI)) self.width = self.rectAOI.s32Width self.height = self.rectAOI.s32Height h = ueye.is_AllocImageMem(self.hCam, self.width, self.height, self.nBitsPerPixel, self.pcImageMemory, self.MemID) i = ueye.is_SetImageMem(self.hCam, self.pcImageMemory, self.MemID) f = ueye.is_SetColorMode(self.hCam, ueye.IS_CM_MONO12) ueye.is_CaptureVideo(self.hCam, ueye.IS_WAIT) j = ueye.is_InquireImageMem(self.hCam, self.pcImageMemory, self.MemID, self.width, self.height, self.nBitsPerPixel, self.pitch) self.IMAGE_FILE_PARAMS = ueye.IMAGE_FILE_PARAMS( self.pcImageMemory, self.MemID) self.IMAGE_FILE_PARAMS.nFileType = ueye.IS_IMG_PNG self.k = ueye.sizeof(self.IMAGE_FILE_PARAMS) # ueye.is_AutoParameter(self.hCam, ueye.IS_AES_CMD_SET_ENABLE, self.autoParameter, ueye.sizeof(self.autoParameter)) while self.flag: self.data = np.ctypeslib.as_array( ctypes.cast(self.pcImageMemory, ctypes.POINTER(ctypes.c_ubyte)), (self.height * self.pitch, )) self.data.dtype = 'uint16' self.CameraSignal.emit(self.data) time.sleep(0.1) ueye.is_FreeImageMem(self.hCam, self.pcImageMemory, self.MemID) ueye.is_ExitCamera(self.hCam)
def getImageData(self): # --- set AOI --- # rect_aoi = ueye.IS_RECT() hasWorked = ueye.is_AOI(self.cam, ueye.IS_AOI_IMAGE_GET_AOI, rect_aoi, ueye.sizeof(rect_aoi)) self.check(hasWorked, 'getImageData') # --- --- # x = ueye.int() y = ueye.int() bits = ueye.int() pitch = ueye.int() self.frame_width = rect_aoi.s32Width.value self.frame_height = rect_aoi.s32Height.value hasWorked = ueye.is_InquireImageMem(self.cam, self.img_buffer.mem_ptr, self.img_buffer.mem_id, x, y, bits, pitch) self.check(hasWorked, 'getImageData') self.imgdata = ueye.get_data(self.img_buffer.mem_ptr, self.frame_width, self.frame_height, bits, pitch, True)
def __init__(self, cam, img_buffer): self.x = ueye.int() self.y = ueye.int() self.bits = ueye.int() self.pitch = ueye.int() self.img_buff = img_buffer rect_aoi = ueye.IS_RECT() nRet = ueye.is_AOI(cam, ueye.IS_AOI_IMAGE_GET_AOI, rect_aoi, ueye.sizeof(rect_aoi)) if nRet != ueye.IS_SUCCESS: error_log(nRet, "is_Aoi") self.width = rect_aoi.s32Width.value self.height = rect_aoi.s32Height.value nRet = ueye.is_InquireImageMem(cam, self.img_buff.mem_ptr, self.img_buff.mem_id, self.x, self.y, self.bits, self.pitch) if nRet != ueye.IS_SUCCESS: error_log(nRet, "is_InquireImageMem")
def acquisition_oneshot(self, timeout_ms=1000): nRet = ueye.is_EnableEvent(self.hCam, ueye.IS_SET_EVENT_FRAME) if nRet != ueye.IS_SUCCESS: raise RuntimeError("is_EnableEvent ERROR") nRet = ueye.is_FreezeVideo(self.hCam, ueye.IS_DONT_WAIT) if nRet != ueye.IS_SUCCESS: raise RuntimeError("is_CaptureVideo ERROR") nRet = ueye.is_WaitEvent(self.hCam, ueye.IS_SET_EVENT_FRAME, timeout_ms) if nRet != ueye.IS_SUCCESS: raise RuntimeError("is_WaitEvent ERROR") nRet = ueye.is_InquireImageMem( self.hCam, self.pcImageMemory, self.MemID, self.width, self.height, self.nBitsPerPixel, self.pitch, ) if nRet != ueye.IS_SUCCESS: raise RuntimeError("is_InquireImageMem ERROR") array = ueye.get_data( self.pcImageMemory, self.width, self.height, self.nBitsPerPixel, self.pitch, copy=True, ) nRet = ueye.is_DisableEvent(self.hCam, ueye.IS_SET_EVENT_FRAME) if nRet != ueye.IS_SUCCESS: raise RuntimeError("is_DisableEvent ERROR") return array.reshape((self.height.value, self.width.value))
def initialize_camera(): #--------------------------------------------------------------------------------------------------------------------------------------- print("START") print() # Starts the driver and establishes the connection to the camera CameraApi.nRet = ueye.is_InitCamera(CameraApi.hCam, None) if CameraApi.nRet != ueye.IS_SUCCESS: print("is_InitCamera ERROR") # Reads out the data hard-coded in the non-volatile camera memory and writes it to the data structure that cInfo points to CameraApi.nRet = ueye.is_GetCameraInfo(CameraApi.hCam, CameraApi.cInfo) if CameraApi.nRet != ueye.IS_SUCCESS: print("is_GetCameraInfo ERROR") # You can query additional information about the sensor type used in the camera CameraApi.nRet = ueye.is_GetSensorInfo(CameraApi.hCam, CameraApi.sInfo) if CameraApi.nRet != ueye.IS_SUCCESS: print("is_GetSensorInfo ERROR") CameraApi.nRet = ueye.is_ResetToDefault(CameraApi.hCam) if CameraApi.nRet != ueye.IS_SUCCESS: print("is_ResetToDefault ERROR") # Set display mode to DIB CameraApi.nRet = ueye.is_SetDisplayMode(CameraApi.hCam, ueye.IS_SET_DM_DIB) # Set the right color mode if int.from_bytes(CameraApi.sInfo.nColorMode.value, byteorder='big') == ueye.IS_COLORMODE_BAYER: # setup the color depth to the current windows setting ueye.is_GetColorDepth(CameraApi.hCam, CameraApi.nBitsPerPixel, CameraApi.m_nColorMode) CameraApi.bytes_per_pixel = int(CameraApi.nBitsPerPixel / 8) print("IS_COLORMODE_BAYER: ", ) print("\tm_nColorMode: \t\t", CameraApi.m_nColorMode) print("\tnBitsPerPixel: \t\t", CameraApi.nBitsPerPixel) print("\tbytes_per_pixel: \t\t", CameraApi.bytes_per_pixel) print() elif int.from_bytes(CameraApi.sInfo.nColorMode.value, byteorder='big') == ueye.IS_COLORMODE_CBYCRY: # for color camera models use RGB32 mode m_nColorMode = ueye.IS_CM_BGRA8_PACKED nBitsPerPixel = ueye.INT(32) CameraApi.bytes_per_pixel = int(nBitsPerPixel / 8) print("IS_COLORMODE_CBYCRY: ", ) print("\tm_nColorMode: \t\t", m_nColorMode) print("\tnBitsPerPixel: \t\t", nBitsPerPixel) print("\tbytes_per_pixel: \t\t", CameraApi.bytes_per_pixel) print() elif int.from_bytes(CameraApi.sInfo.nColorMode.value, byteorder='big') == ueye.IS_COLORMODE_MONOCHROME: # for color camera models use RGB32 mode m_nColorMode = ueye.IS_CM_MONO8 nBitsPerPixel = ueye.INT(8) CameraApi.bytes_per_pixel = int(nBitsPerPixel / 8) print("IS_COLORMODE_MONOCHROME: ", ) print("\tm_nColorMode: \t\t", m_nColorMode) print("\tnBitsPerPixel: \t\t", nBitsPerPixel) print("\tbytes_per_pixel: \t\t", CameraApi.bytes_per_pixel) print() else: # for monochrome camera models use Y8 mode m_nColorMode = ueye.IS_CM_MONO8 nBitsPerPixel = ueye.INT(8) CameraApi.bytes_per_pixel = int(nBitsPerPixel / 8) print("else") # Can be used to set the size and position of an "area of interest"(AOI) within an image CameraApi.nRet = ueye.is_AOI(CameraApi.hCam, ueye.IS_AOI_IMAGE_GET_AOI, CameraApi.rectAOI, ueye.sizeof(CameraApi.rectAOI)) if CameraApi.nRet != ueye.IS_SUCCESS: print("is_AOI ERROR") CameraApi.width = CameraApi.rectAOI.s32Width CameraApi.height = CameraApi.rectAOI.s32Height # Prints out some information about the camera and the sensor print("Camera model:\t\t", CameraApi.sInfo.strSensorName.decode('utf-8')) print("Camera serial no.:\t", CameraApi.cInfo.SerNo.decode('utf-8')) print("Maximum image width:\t", CameraApi.width) print("Maximum image height:\t", CameraApi.height) print() #--------------------------------------------------------------------------------------------------------------------------------------- # Allocates an image memory for an image having its dimensions defined by width and height and its color depth defined by nBitsPerPixel CameraApi.nRet = ueye.is_AllocImageMem(CameraApi.hCam, CameraApi.width, CameraApi.height, CameraApi.nBitsPerPixel, CameraApi.pcImageMemory, CameraApi.MemID) if CameraApi.nRet != ueye.IS_SUCCESS: print("is_AllocImageMem ERROR") else: # Makes the specified image memory the active memory CameraApi.nRet = ueye.is_SetImageMem(CameraApi.hCam, CameraApi.pcImageMemory, CameraApi.MemID) if CameraApi.nRet != ueye.IS_SUCCESS: print("is_SetImageMem ERROR") else: # Set the desired color mode CameraApi.nRet = ueye.is_SetColorMode(CameraApi.hCam, CameraApi.m_nColorMode) # Activates the camera's live video mode (free run mode) CameraApi.nRet = ueye.is_CaptureVideo(CameraApi.hCam, ueye.IS_DONT_WAIT) if CameraApi.nRet != ueye.IS_SUCCESS: print("is_CaptureVideo ERROR") # Enables the queue mode for existing image memory sequences CameraApi.nRet = ueye.is_InquireImageMem( CameraApi.hCam, CameraApi.pcImageMemory, CameraApi.MemID, CameraApi.width, CameraApi.height, CameraApi.nBitsPerPixel, CameraApi.pitch) if CameraApi.nRet != ueye.IS_SUCCESS: print("is_InquireImageMem ERROR") else: print("Press q to leave the programm")
print("is_AllocImageMem ERROR") else: # Makes the specified image memory the active memory nRet = ueye.is_SetImageMem(hCam, pcImageMemory, MemID) if nRet != ueye.IS_SUCCESS: print("is_SetImageMem ERROR") else: # Set the desired color mode nRet = ueye.is_SetColorMode(hCam, m_nColorMode) # Activates the camera's live video mode (free run mode) # Enables the queue mode for existing image memory sequences nRet = ueye.is_InquireImageMem(hCam, pcImageMemory, MemID, width, height, nBitsPerPixel, pitch) if nRet != ueye.IS_SUCCESS: print("is_InquireImageMem ERROR") else: print("Press q to leave the program") a=20 a=ueye.DOUBLE(30) c=ueye.DOUBLE() b=ueye.UINT(8) thing=ueye.is_Exposure(hCam,ueye.IS_EXPOSURE_CMD_SET_EXPOSURE, a,b ) thing=ueye.is_Exposure(hCam,ueye.IS_EXPOSURE_CMD_GET_EXPOSURE, c,b ) print(c) gain=ueye.UINT(80)
def configure_device(self): """ Configure camera. """ self.nRet = ueye.is_ResetToDefault(self.hid) if self.nRet != ueye.IS_SUCCESS: print('Reset ERROR') ueye.is_Exposure(self.hid, ueye.IS_EXPOSURE_CMD_GET_EXPOSURE_RANGE_MIN, self.minExp, 8) ueye.is_Exposure(self.hid, ueye.IS_EXPOSURE_CMD_GET_EXPOSURE_RANGE_MAX, self.maxExp, 8) self.nRet = ueye.is_SetDisplayMode(self.hid, ueye.IS_SET_DM_DIB) if self.nRet != ueye.IS_SUCCESS: print('Display Mode ERROR') ueye.is_Exposure(self.hid, ueye.IS_EXPOSURE_CMD_SET_EXPOSURE, self.minExp, 8 ) ueye.is_Exposure(self.hid, ueye.IS_EXPOSURE_CMD_GET_EXPOSURE, self.Exp, 8 ) # Set the right color mode if int.from_bytes(self.sinfo.nColorMode.value, byteorder='big') == ueye.IS_COLORMODE_BAYER: # setup the color depth to the current windows setting ueye.is_GetColorDepth(self.hid, self.bitspixel, self.colorm) self.bytesppixel = int(self.bitspixel / 8) elif int.from_bytes(self.sinfo.nColorMode.value, byteorder='big') == ueye.IS_COLORMODE_CBYCRY: # for color camera models use RGB32 mode self.colorm = ueye.IS_CM_BGRA8_PACKED self.bitspixel = ueye.INT(32) self.bytesppixel = int(self.bitspixel / 8) elif int.from_bytes(self.sinfo.nColorMode.value, byteorder='big') == ueye.IS_COLORMODE_MONOCHROME: # for color camera models use RGB32 mode self.colorm = ueye.IS_CM_MONO8 self.bitspixel = ueye.INT(8) self.bytesppixel = int(self.bitspixel / 8) else: # for monochrome camera models use Y8 mode self.colorm = ueye.IS_CM_MONO8 self.bitspixel = ueye.INT(8) self.bytesppixel = int(self.bitspixel / 8) self.nRet = ueye.is_AOI(self.hid, ueye.IS_AOI_IMAGE_GET_AOI, self.rect, ueye.sizeof(self.rect)) self.width = self.rect.s32Width self.height = self.rect.s32Height self.pixelSizeMicron = self.sinfo.wPixelSize.value / 100 if self.nRet != ueye.IS_SUCCESS: print('AOI ERROR') self.nRet = ueye.is_AllocImageMem(self.hid, self.width, self.height, self.bitspixel, self.ppcImgMem, self.MemID) if self.nRet != ueye.IS_SUCCESS: print('AllocImageMem ERROR') else: self.nRet = ueye.is_SetImageMem(self.hid, self.ppcImgMem, self.MemID) if self.nRet != ueye.IS_SUCCESS: print('SetImageMem ERROR') else: self.nRet = ueye.is_SetColorMode(self.hid, self.colorm) self.nRet = ueye.is_CaptureVideo(self.hid, ueye.IS_DONT_WAIT) #if self.nRet != ueye.IS_SUCCESS: #print('CaptureVideo ERROR') self.nRet = ueye.is_InquireImageMem(self.hid, self.ppcImgMem, self.MemID, self.width, self.height, self.bitspixel, self.pitch) if self.nRet != ueye.IS_SUCCESS: print('InquireImageMem ERROR')
def cameraInit(load_parameters_EEPROM=load_parameters_EEPROM): """Initializes the camera with the correct parameters""" global mBuff, bpp, pitch, channels, bytes_per_pixel, tt hCam = ueye.HIDS(0) # 0: first available camera; 1-254: The camera with the specified camera ID sInfo = ueye.SENSORINFO() cInfo = ueye.CAMINFO() # Starts the driver and establishes the connection to the camera nRet = ueye.is_InitCamera(hCam, None) logger.debug("Setting Camera Data") if nRet != ueye.IS_SUCCESS: logger.info("is_InitCamera ERROR, camera not connected?") return -1, 0 # Reads out the data hard-coded in the non-volatile camera memory and writes it to the data structure that cInfo points to nRet = ueye.is_GetCameraInfo(hCam, cInfo) if nRet != ueye.IS_SUCCESS: logger.info("is_GetCameraInfo ERROR") # You can query additional information about the sensor type used in the camera nRet = ueye.is_GetSensorInfo(hCam, sInfo) if nRet != ueye.IS_SUCCESS: logger.info("is_GetSensorInfo ERROR") nRet = ueye.is_ResetToDefault(hCam) if nRet != ueye.IS_SUCCESS: logger.info("is_ResetToDefault ERROR") # Set display mode to DIB nRet = ueye.is_SetDisplayMode(hCam, ueye.IS_SET_DM_DIB) if int.from_bytes(sInfo.nColorMode.value, byteorder='big') == ueye.IS_COLORMODE_MONOCHROME: # for color camera models use RGB32 mode logger.info("Setting colormode to black and white") m_nColorMode = ueye.IS_CM_MONO8 nBitsPerPixel = ueye.INT(8) bytes_per_pixel = int(nBitsPerPixel / 8) logger.info(f"IS_COLORMODE_MONOCHROME: ") logger.info(f"\tm_nColorMode: \t\t{m_nColorMode}") logger.info(f"\tnBitsPerPixel: \t\t{nBitsPerPixel}") logger.info(f"\tbytes_per_pixel: \t\t {bytes_per_pixel}") if load_parameters_EEPROM: logger.debug("Loading parameters from EEPROM") nullint = ueye._value_cast(0, ueye.ctypes.c_uint) rvv = ueye.is_ParameterSet(hCam, ueye.IS_PARAMETERSET_CMD_LOAD_EEPROM, nullint, nullint) # Can be used to set the size and position of an "area of interest"(AOI) within an image nRet = ueye.is_AOI(hCam, ueye.IS_AOI_IMAGE_GET_AOI, rectAOI, ueye.sizeof(rectAOI)) if nRet != ueye.IS_SUCCESS: logger.error("is_AOI ERROR") width = rectAOI.s32Width height = rectAOI.s32Height # Prints out some information about the camera and the sensor logger.info(f"Camera model:\t\t {sInfo.strSensorName.decode('utf-8')}") logger.info(f"Camera serial no.:\t {cInfo.SerNo.decode('utf-8')}") logger.info(f"Maximum image width:\t {width}") logger.info(f"Maximum image height:\t {height}") # --------------------------------------------------------------------------------------------------------------------------------------- # Allocates an image memory for an image having its dimensions defined by width and height and its color depth defined by nBitsPerPixel nRet = ueye.is_AllocImageMem(hCam, width, height, nBitsPerPixel, pcImageMemory, MemID) if nRet != ueye.IS_SUCCESS: logger.info("is_AllocImageMem ERROR") else: # Makes the specified image memory the active memory nRet = ueye.is_SetImageMem(hCam, pcImageMemory, MemID) if nRet != ueye.IS_SUCCESS: logger.info("is_SetImageMem ERROR") else: # Set the desired color mode nRet = ueye.is_SetColorMode(hCam, m_nColorMode) # Activates the camera's live video mode (free run mode) nRet = ueye.is_CaptureVideo(hCam, ueye.IS_DONT_WAIT) if nRet != ueye.IS_SUCCESS: logger.info("is_CaptureVideo ERROR") # Enables the queue mode for existing image memory sequences nRet = ueye.is_InquireImageMem(hCam, pcImageMemory, MemID, width, height, nBitsPerPixel, pitch) if nRet != ueye.IS_SUCCESS: logger.info("is_InquireImageMem ERROR") else: logger.info("Press q to leave the programm") # --------------------------------------------------------------------------------------------------------------------------------------- # shutter = int.from_bytes(sInfo.bGlobShutter.value, byteorder='big') # rvv = ueye.is_ParameterSet(hCam,ueye.IS_PARAMETERSET_CMD_LOAD_EEPROM,nullint,nullint) # Continuous image display tt = ueye.is_AOI(hCam, ueye.IS_AOI_IMAGE_GET_AOI, rect_aoi, ueye.sizeof(rect_aoi)) width = rect_aoi.s32Width.value height = rect_aoi.s32Height.value for i in range(numBuffers): buff = ImageBuffer() ueye.is_AllocImageMem(hCam, width, height, bpp, buff.mem_ptr, buff.mem_id) ueye.is_AddToSequence(hCam, buff.mem_ptr, buff.mem_id) buffs.append(buff) rvIQ = ueye.is_InitImageQueue(hCam, 0) nRet = ueye.IS_SUCCESS ret = ueye.is_WaitForNextImage(hCam, 100, mBuff.mem_ptr, mBuff.mem_id) rr = ueye.is_GetActSeqBuf(hCam, buffCurrent.mem_id, buffLast.mem_ptr, buffLast.mem_ptr) if (not ret): # cnt+=1 array = ueye.get_data(mBuff.mem_ptr, width, height, bpp, pitch, copy=True) ueye.is_UnlockSeqBuf(hCam, mBuff.mem_id, mBuff.mem_ptr) return nRet, hCam
def show_image(self): # Kamera initialisieren nRet = ueye.is_InitCamera(self.h_cam, None) nRet = ueye.is_SetDisplayMode(self.h_cam, ueye.IS_SET_DM_DIB) nRet = ueye.is_AOI(self.h_cam, ueye.IS_AOI_IMAGE_GET_AOI, self.rectAOI, ueye.sizeof(self.rectAOI)) self.width = self.rectAOI.s32Width self.height = self.rectAOI.s32Height nRet = ueye.is_AllocImageMem(self.h_cam, self.width, self.height, self.nBitsPerPixel, self.pcImageMemory, self.MemID) nRet = ueye.is_SetImageMem(self.h_cam, self.pcImageMemory, self.MemID) nRet = ueye.is_SetColorMode(self.h_cam, self.ColorMode) nRet = ueye.is_CaptureVideo(self.h_cam, ueye.IS_DONT_WAIT) nRet = ueye.is_InquireImageMem(self.h_cam, self.pcImageMemory, self.MemID, self.width, self.height, self.nBitsPerPixel, self.pitch) while nRet == ueye.IS_SUCCESS: # Daten der Kamera auslesen array = ueye.get_data(self.pcImageMemory, self.width, self.height, self.nBitsPerPixel, self.pitch, copy=True) # Bild zuschneiden frame = np.reshape( array, (self.height.value, self.width.value, self.bytes_per_pixel)) frame = cv2.resize(frame, (0, 0), fx=0.5, fy=0.5) # Kamerabild ausgeben cv2.imshow("camera", frame) # mit q Kamera schließen if cv2.waitKey(1) & 0xFF == ord('q'): break # mit t Bild aufnehmen und speichern, wenn ein Schachbrettmuster erkannt wird elif cv2.waitKey(1) & 0xFF == ord('t'): ret, corners = cv2.findChessboardCorners( frame, (self.nx, self.ny), None) if ret: im_name = self.path + str(self.n_im) + ".bmp" cv2.imwrite(im_name, frame) self.n_im = self.n_im + 1 print("Bild", self.n_im, "aufgenommen.") else: print("Kein Chessboard gefunden") # mit d Schachbrettlinien zeichnen und speichern elif cv2.waitKey(1) & 0xFF == ord('d'): self.draw_chessboard_corners(True) # mit c Kamera intrinsisch kalibrieren elif cv2.waitKey(1) & 0xFF == ord('c'): if self.n_im > 0: self.calibrate() else: print("Vorher Bilder aufnehmen!") ueye.is_FreeImageMem(self.h_cam, self.pcImageMemory, self.MemID) ueye.is_ExitCamera(self.h_cam) cv2.destroyAllWindows()
def __init__(self, index): self.hCam = ueye.HIDS( index ) # 0: first available camera; 1-254: The camera with the specified camera ID self.sInfo = ueye.SENSORINFO() self.cInfo = ueye.CAMINFO() self.pcImageMemory = ueye.c_mem_p() self.MemID = ueye.int() self.rectAOI = ueye.IS_RECT() self.pitch = ueye.INT() self.nBitsPerPixel = ueye.INT( 24 ) # 24: bits per pixel for color mode; take 8 bits per pixel for monochrome channels = 3 # 3: channels for color mode(RGB); take 1 channel for monochrome self.m_nColorMode = ueye.INT() # Y8/RGB16/RGB24/REG32 self.bytes_per_pixel = int(self.nBitsPerPixel / 8) # --------------------------------------------------------------------------------------------------------------------------------------- # print( "START" ) # print() # Starts the driver and establishes the connection to the camera self.nRet = ueye.is_InitCamera(self.hCam, None) if self.nRet != ueye.IS_SUCCESS: raise Exception("is_InitCamera ERROR") # Reads out the data hard-coded in the non-volatile camera memory and writes it to the data structure that self.cInfo # points to self.nRet = ueye.is_GetCameraInfo(self.hCam, self.cInfo) if self.nRet != ueye.IS_SUCCESS: raise Exception("is_GetCameraInfo ERROR") # You can query additional information about the sensor type used in the camera self.nRet = ueye.is_GetSensorInfo(self.hCam, self.sInfo) if self.nRet != ueye.IS_SUCCESS: raise Exception("is_GetSensorInfo ERROR") self.nRet = ueye.is_ResetToDefault(self.hCam) if self.nRet != ueye.IS_SUCCESS: raise Exception("is_ResetToDefault ERROR") # Set display mode to DIB self.nRet = ueye.is_SetDisplayMode(self.hCam, ueye.IS_SET_DM_DIB) # Set the right color mode if int.from_bytes(self.sInfo.nColorMode.value, byteorder='big') == ueye.IS_COLORMODE_BAYER: # setup the color depth to the current windows setting ueye.is_GetColorDepth(self.hCam, self.nBitsPerPixel, self.m_nColorMode) self.bytes_per_pixel = int(self.nBitsPerPixel / 8) print("IS_COLORMODE_BAYER: ", ) print("\tm_nColorMode: \t\t", self.m_nColorMode) print("\tnBitsPerPixel: \t\t", self.nBitsPerPixel) print("\tbytes_per_pixel: \t\t", self.bytes_per_pixel) print() elif int.from_bytes(self.sInfo.nColorMode.value, byteorder='big') == ueye.IS_COLORMODE_CBYCRY: # for color camera models use RGB32 mode self.m_nColorMode = ueye.IS_CM_BGRA8_PACKED self.nBitsPerPixel = ueye.INT(32) self.bytes_per_pixel = int(self.nBitsPerPixel / 8) print("IS_COLORMODE_CBYCRY: ", ) print("\tm_nColorMode: \t\t", self.m_nColorMode) print("\tnBitsPerPixel: \t\t", self.nBitsPerPixel) print("\tbytes_per_pixel: \t\t", self.bytes_per_pixel) print() elif int.from_bytes(self.sInfo.nColorMode.value, byteorder='big') == ueye.IS_COLORMODE_MONOCHROME: # for color camera models use RGB32 mode self.m_nColorMode = ueye.IS_CM_MONO8 self.nBitsPerPixel = ueye.INT(8) self.bytes_per_pixel = int(self.nBitsPerPixel / 8) print("IS_COLORMODE_MONOCHROME: ", ) print("\tm_nColorMode: \t\t", self.m_nColorMode) print("\tnBitsPerPixel: \t\t", self.nBitsPerPixel) print("\tbytes_per_pixel: \t\t", self.bytes_per_pixel) print() else: # for monochrome camera models use Y8 mode self.m_nColorMode = ueye.IS_CM_MONO8 self.nBitsPerPixel = ueye.INT(8) self.bytes_per_pixel = int(self.nBitsPerPixel / 8) print("else") # Can be used to set the size and position of an "area of interest"(AOI) within an image self.nRet = ueye.is_AOI(self.hCam, ueye.IS_AOI_IMAGE_GET_AOI, self.rectAOI, ueye.sizeof(self.rectAOI)) if self.nRet != ueye.IS_SUCCESS: raise Exception("is_AOI ERROR") self.width = self.rectAOI.s32Width self.height = self.rectAOI.s32Height # Prints out some information about the camera and the sensor print("Camera model:\t\t", self.sInfo.strSensorName.decode('utf-8')) print("Camera serial no.:\t", self.cInfo.SerNo.decode('utf-8')) print("Maximum image width:\t", self.width) print("Maximum image height:\t", self.height) print() # --------------------------------------------------------------------------------------------------------------------------------------- # Allocates an image memory for an image having its dimensions defined by width and height and its color depth # defined by nBitsPerPixel self.nRet = ueye.is_AllocImageMem(self.hCam, self.width, self.height, self.nBitsPerPixel, self.pcImageMemory, self.MemID) if self.nRet != ueye.IS_SUCCESS: raise Exception("is_AllocImageMem ERROR") else: # Makes the specified image memory the active memory self.nRet = ueye.is_SetImageMem(self.hCam, self.pcImageMemory, self.MemID) if self.nRet != ueye.IS_SUCCESS: raise Exception("is_SetImageMem ERROR") else: # Set the desired color mode self.nRet = ueye.is_SetColorMode(self.hCam, self.m_nColorMode) # Activates the camera's live video mode (free run mode) self.nRet = ueye.is_CaptureVideo(self.hCam, ueye.IS_DONT_WAIT) if self.nRet != ueye.IS_SUCCESS: raise Exception("is_CaptureVideo ERROR") # Enables the queue mode for existing image memory sequences self.nRet = ueye.is_InquireImageMem(self.hCam, self.pcImageMemory, self.MemID, self.width, self.height, self.nBitsPerPixel, self.pitch) if self.nRet != ueye.IS_SUCCESS: raise Exception("is_InquireImageMem ERROR") else: print("Camera Connection success")
def show_image(self): # Kamera initialisieren nRet = ueye.is_InitCamera(self.h_cam, None) nRet = ueye.is_SetDisplayMode(self.h_cam, ueye.IS_SET_DM_DIB) nRet = ueye.is_AOI(self.h_cam, ueye.IS_AOI_IMAGE_GET_AOI, self.rectAOI, ueye.sizeof(self.rectAOI)) self.width = self.rectAOI.s32Width self.height = self.rectAOI.s32Height nRet = ueye.is_AllocImageMem(self.h_cam, self.width, self.height, self.nBitsPerPixel, self.pcImageMemory, self.MemID) nRet = ueye.is_SetImageMem(self.h_cam, self.pcImageMemory, self.MemID) nRet = ueye.is_SetColorMode(self.h_cam, self.ColorMode) nRet = ueye.is_CaptureVideo(self.h_cam, ueye.IS_DONT_WAIT) nRet = ueye.is_InquireImageMem(self.h_cam, self.pcImageMemory, self.MemID, self.width, self.height, self.nBitsPerPixel, self.pitch) while nRet == ueye.IS_SUCCESS: # Daten der Kamera auslesen array = ueye.get_data(self.pcImageMemory, self.width, self.height, self.nBitsPerPixel, self.pitch, copy=False) # Bild zuschneiden frame = np.reshape( array, (self.height.value, self.width.value, self.bytes_per_pixel)) frame = cv2.resize(frame, (0, 0), fx=0.5, fy=0.5) size = (self.height, self.width) # optimale Kameramatrix erstellen self.new_camera_matrix, roi = cv2.getOptimalNewCameraMatrix( self.camera_matrix, self.dist_coeff, size, 1, size) # Bild entzerren dst = cv2.undistort(frame, self.camera_matrix, self.dist_coeff, None, self.new_camera_matrix) x, y, w, h = roi self.dst = dst[y:y + h, x:x + w] # Farbmasken erstellen self.blue.create_color_mask(self.dst, self.found_blue_container) self.red.create_color_mask(self.dst, self.found_red_container) self.green.create_color_mask(self.dst, self.found_green_container) # Kamera extrinsisch kalibrieren self.extrinsic_calibration() # Bild auf dem Bildschirm ausgeben cv2.imshow("camera", self.dst) # mit q Kamera schließen if cv2.waitKey(1) & 0xFF == ord('q'): break # mit t Bild aufnehemen elif cv2.waitKey(100) & 0xFF == ord('t'): cv2.imwrite(self.path_images + "image.bmp", self.dst) print("Bild aufgenommen") # mit l Position der Behälter zurücksetzen elif cv2.waitKey(100) & 0xFF == ord('l'): self.found_blue_container = False self.found_red_container = False self.found_green_container = False print("Behälterposition zurückgesetzt") ueye.is_FreeImageMem(self.h_cam, self.pcImageMemory, self.MemID) ueye.is_ExitCamera(self.h_cam) cv2.destroyAllWindows()
def main(): from pyueye import ueye import numpy as np import cv2 import sys import os import tensorflow as tf import SoundTheAlarm import time # --------------------------------------------------------------------------------------------------------------------------------------- # This is needed since the notebook is stored in the object_detection folder. sys.path.append("..") # Import utilites from utils import label_map_util from utils import visualization_utils as vis_util # Name of the directory containing the object detection module we're using MODEL_NAME = 'inference_graph' # Grab path to current working directory CWD_PATH = os.getcwd() # Path to frozen detection graph .pb file, which contains the model that is used # for object detection. PATH_TO_CKPT = os.path.join(CWD_PATH, MODEL_NAME, 'frozen_inference_graph.pb') # Path to label map file PATH_TO_LABELS = os.path.join(CWD_PATH, 'training', 'labelmap.pbtxt') # Number of classes the object detector can identify NUM_CLASSES = 3 ## Load the label map. # Label maps map indices to category names, so that when our convolution # network predicts `5`, we know that this corresponds to `king`. # Here we use internal utility functions, but anything that returns a # dictionary mapping integers to appropriate string labels would be fine label_map = label_map_util.load_labelmap(PATH_TO_LABELS) categories = label_map_util.convert_label_map_to_categories(label_map, max_num_classes=NUM_CLASSES, use_display_name=True) category_index = label_map_util.create_category_index(categories) # Load the Tensorflow model into memory. detection_graph = tf.Graph() with detection_graph.as_default(): od_graph_def = tf.GraphDef() with tf.gfile.GFile(PATH_TO_CKPT, 'rb') as fid: serialized_graph = fid.read() od_graph_def.ParseFromString(serialized_graph) tf.import_graph_def(od_graph_def, name='') sess = tf.Session(graph=detection_graph) # Define input and output tensors (i.e. data) for the object detection classifier # Input tensor is the image image_tensor = detection_graph.get_tensor_by_name('image_tensor:0') # Output tensors are the detection boxes, scores, and classes # Each box represents a part of the image where a particular object was detected detection_boxes = detection_graph.get_tensor_by_name('detection_boxes:0') # Each score represents level of confidence for each of the objects. # The score is shown on the result image, together with the class label. detection_scores = detection_graph.get_tensor_by_name('detection_scores:0') detection_classes = detection_graph.get_tensor_by_name('detection_classes:0') # Number of objects detected num_detections = detection_graph.get_tensor_by_name('num_detections:0') # Variables hCam = ueye.HIDS(0) # 0: first available camera; 1-254: The camera with the specified camera ID sInfo = ueye.SENSORINFO() cInfo = ueye.CAMINFO() pcImageMemory = ueye.c_mem_p() MemID = ueye.int() rectAOI = ueye.IS_RECT() pitch = ueye.INT() nBitsPerPixel = ueye.INT(24) # 24: bits per pixel for color mode; take 8 bits per pixel for monochrome channels = 3 # 3: channels for color mode(RGB); take 1 channel for monochrome m_nColorMode = ueye.INT() # Y8/RGB16/RGB24/REG32 ueye.is_SetColorMode(hCam, ueye.IS_CM_BGR8_PACKED) bytes_per_pixel = int(nBitsPerPixel / 8) # --------------------------------------------------------------------------------------------------------------------------------------- print("START") print() # Starts the driver and establishes the connection to the camera nRet = ueye.is_InitCamera(hCam, None) if nRet != ueye.IS_SUCCESS: print("is_InitCamera ERROR") # Reads out the data hard-coded in the non-volatile camera memory and writes it to the data structure that cInfo points to nRet = ueye.is_GetCameraInfo(hCam, cInfo) if nRet != ueye.IS_SUCCESS: print("is_GetCameraInfo ERROR") # You can query additional information about the sensor type used in the camera nRet = ueye.is_GetSensorInfo(hCam, sInfo) if nRet != ueye.IS_SUCCESS: print("is_GetSensorInfo ERROR") nRet = ueye.is_ResetToDefault(hCam) if nRet != ueye.IS_SUCCESS: print("is_ResetToDefault ERROR") # Set display mode to DIB nRet = ueye.is_SetDisplayMode(hCam, ueye.IS_SET_DM_DIB) # Set the right color mode if int.from_bytes(sInfo.nColorMode.value, byteorder='big') == ueye.IS_COLORMODE_BAYER: # setup the color depth to the current windows setting ueye.is_GetColorDepth(hCam, nBitsPerPixel, m_nColorMode) bytes_per_pixel = int(nBitsPerPixel / 8) print("IS_COLORMODE_BAYER: ", ) print("\tm_nColorMode: \t\t", m_nColorMode) print("\tnBitsPerPixel: \t\t", nBitsPerPixel) print("\tbytes_per_pixel: \t\t", bytes_per_pixel) print() elif int.from_bytes(sInfo.nColorMode.value, byteorder='big') == ueye.IS_COLORMODE_CBYCRY: # for color camera models use RGB32 mode m_nColorMode = ueye.IS_CM_BGRA8_PACKED nBitsPerPixel = ueye.INT(32) bytes_per_pixel = int(nBitsPerPixel / 8) print("IS_COLORMODE_CBYCRY: ", ) print("\tm_nColorMode: \t\t", m_nColorMode) print("\tnBitsPerPixel: \t\t", nBitsPerPixel) print("\tbytes_per_pixel: \t\t", bytes_per_pixel) print() elif int.from_bytes(sInfo.nColorMode.value, byteorder='big') == ueye.IS_COLORMODE_MONOCHROME: # for color camera models use RGB32 mode m_nColorMode = ueye.IS_CM_MONO8 nBitsPerPixel = ueye.INT(8) bytes_per_pixel = int(nBitsPerPixel / 8) print("IS_COLORMODE_MONOCHROME: ", ) print("\tm_nColorMode: \t\t", m_nColorMode) print("\tnBitsPerPixel: \t\t", nBitsPerPixel) print("\tbytes_per_pixel: \t\t", bytes_per_pixel) print() else: # for monochrome camera models use Y8 mode m_nColorMode = ueye.IS_CM_MONO8 nBitsPerPixel = ueye.INT(8) bytes_per_pixel = int(nBitsPerPixel / 8) print("else") # Can be used to set the size and position of an "area of interest"(AOI) within an image nRet = ueye.is_AOI(hCam, ueye.IS_AOI_IMAGE_GET_AOI, rectAOI, ueye.sizeof(rectAOI)) if nRet != ueye.IS_SUCCESS: print("is_AOI ERROR") width = rectAOI.s32Width height = rectAOI.s32Height # Prints out some information about the camera and the sensor print("Camera model:\t\t", sInfo.strSensorName.decode('utf-8')) print("Camera serial no.:\t", cInfo.SerNo.decode('utf-8')) print("Maximum image width:\t", width) print("Maximum image height:\t", height) print() # --------------------------------------------------------------------------------------------------------------------------------------- # Allocates an image memory for an image having its dimensions defined by width and height and its color depth defined by nBitsPerPixel nRet = ueye.is_AllocImageMem(hCam, width, height, nBitsPerPixel, pcImageMemory, MemID) if nRet != ueye.IS_SUCCESS: print("is_AllocImageMem ERROR") else: # Makes the specified image memory the active memory nRet = ueye.is_SetImageMem(hCam, pcImageMemory, MemID) if nRet != ueye.IS_SUCCESS: print("is_SetImageMem ERROR") else: # Set the desired color mode nRet = ueye.is_SetColorMode(hCam, m_nColorMode) # Activates the camera's live video mode (free run mode) nRet = ueye.is_CaptureVideo(hCam, ueye.IS_DONT_WAIT) if nRet != ueye.IS_SUCCESS: print("is_CaptureVideo ERROR") # Enables the queue mode for existing image memory sequences nRet = ueye.is_InquireImageMem(hCam, pcImageMemory, MemID, width, height, nBitsPerPixel, pitch) if nRet != ueye.IS_SUCCESS: print("is_InquireImageMem ERROR") else: print("Press q to leave the programm") # -----------------------------------start image loop--------------------------------------------------------------- # Continuous image display while (nRet == ueye.IS_SUCCESS): # In order to display the image in an OpenCV window we need to... # ...extract the data of our image memory array = ueye.get_data(pcImageMemory, width, height, nBitsPerPixel, pitch, copy=False) # bytes_per_pixel = int(nBitsPerPixel / 8) # ...reshape it in an numpy array... frame = np.reshape(array, (height.value, width.value, bytes_per_pixel)) frame = cv2.cvtColor(frame, cv2.COLOR_GRAY2BGR) # ------------------------------------------network_run--------------------------------------------------------- frame_expanded = np.expand_dims(frame, axis=0) # Perform the actual detection by running the model with the image as input (boxes, scores, classes, num) = sess.run( [detection_boxes, detection_scores, detection_classes, num_detections], feed_dict={image_tensor: frame_expanded}) # print("check this point-2") # Draw the results of the detection (aka 'visualize the results') vis_util.visualize_boxes_and_labels_on_image_array( frame, np.squeeze(boxes), np.squeeze(classes).astype(np.int32), np.squeeze(scores), category_index, use_normalized_coordinates=True, line_thickness=8, min_score_thresh=0.85) counter = [] add = 0 while add < (NUM_CLASSES + 1): counter.append(0) add += 1 element = 0 # i used this loop to configure the alarm for i in classes[0]: # it uses the variables to count how many of each object appear in each image if (scores[0][element]) > 0.85: #=min_score_thresh # use it to feed an alarm detector script based on counter[int(i)] += 1 # what "should" and "shouldn't" appear element += 1 else: break #the break stops from iterating through the entire array, which is uneccessary ####---the alarm protocol---#### #if counter[2] and counter[3]: #if not counter[1]: #SoundTheAlarm.sound_loop() print("number of each class", counter) # All the results have been drawn on the frame, so it's time to display it. frame = cv2.resize(frame, None, fx=0.5, fy=0.5) cv2.destroyAllWindows() # -------------------------------------------------------------------------------------------------------------- # ...and finally display it cv2.imshow("SimpleLive_Python_uEye_OpenCV", frame) # Press q if you want to end the loop if cv2.waitKey(1) & 0xFF == ord('q'): break time.sleep(0.5) # ------------------------------------------------------------------------------------------------------------------ # Releases an image memory that was allocated using is_AllocImageMem() and removes it from the driver management ueye.is_FreeImageMem(hCam, pcImageMemory, MemID) # Disables the hCam camera handle and releases the data structures and memory areas taken up by the uEye camera ueye.is_ExitCamera(hCam) # Destroys the OpenCv windows cv2.destroyAllWindows() print() print("END")
async def acquisition_async( self, num=np.inf, timeout=1000, raw=False, initialising_cams=None, raise_on_timeout=True, ): """Concrete implementation """ loop = asyncio.get_event_loop() nRet = ueye.is_CaptureVideo(self.hCam, ueye.IS_DONT_WAIT) if nRet != ueye.IS_SUCCESS: raise RuntimeError("is_CaptureVideo ERROR") try: nRet = ueye.is_InquireImageMem( self.hCam, self.pcImageMemory, self.MemID, self.width, self.height, self.nBitsPerPixel, self.pitch, ) image_info = ueye.UEYEIMAGEINFO() if nRet != ueye.IS_SUCCESS: raise RuntimeError("is_InquireImageMem ERROR") count = 0 while count < num: nRet = ueye.is_EnableEvent(self.hCam, ueye.IS_SET_EVENT_FRAME) if nRet != ueye.IS_SUCCESS: raise RuntimeError("is_EnableEvent ERROR") nRet = await loop.run_in_executor(None, ueye.is_WaitEvent, self.hCam, ueye.IS_SET_EVENT_FRAME, timeout) if nRet == ueye.IS_TIMED_OUT: if raise_on_timeout: raise RuntimeError("Timeout") else: stop_signal = yield None if stop_signal: break else: continue elif nRet != ueye.IS_SUCCESS: raise RuntimeError("is_WaitEvent ERROR") array = ueye.get_data( self.pcImageMemory, self.width, self.height, self.nBitsPerPixel, self.pitch, copy=False, ) nRet = ueye.is_GetImageInfo(self.hCam, self.MemID, image_info, ctypes.sizeof(image_info)) if nRet != ueye.IS_SUCCESS: raise RuntimeError("is_GetImageInfo ERROR") count = count + 1 ts = datetime( image_info.TimestampSystem.wYear.value, image_info.TimestampSystem.wMonth.value, image_info.TimestampSystem.wDay.value, image_info.TimestampSystem.wHour.value, image_info.TimestampSystem.wMinute.value, image_info.TimestampSystem.wSecond.value, image_info.TimestampSystem.wMilliseconds * 1000, ) stop_signal = yield MetadataArray( array.reshape((self.height.value, self.width.value)), metadata={ "counter": count, "timestamp": ts.timestamp() }, ) if stop_signal: break finally: nRet = ueye.is_StopLiveVideo(self.hCam, ueye.IS_DONT_WAIT) if nRet != ueye.IS_SUCCESS: raise RuntimeError("is_StopLiveVideo ERROR") nRet = ueye.is_DisableEvent(self.hCam, ueye.IS_SET_EVENT_FRAME) if nRet != ueye.IS_SUCCESS: raise RuntimeError("is_DisableEvent ERROR") if stop_signal: yield True
def main(): cam = ueye.HIDS() # open first available cam check(ueye.is_InitCamera(cam, None)) # query image size size = ueye.IS_SIZE_2D() check((ueye.is_AOI(cam, ueye.IS_AOI_IMAGE_GET_SIZE, size, ueye.sizeof(size)))) width = size.s32Width height = size.s32Height # allocate memory. we need at least one buffer mem_ptr = ueye.c_mem_p() mem_id = ueye.INT() bits_per_pixel = ueye.INT(24) # assume we have 24 bits per pixel (rgb) check( ueye.is_AllocImageMem(cam, width, height, bits_per_pixel, mem_ptr, mem_id)) # set the image mem active, so we can render into check(ueye.is_SetImageMem(cam, mem_ptr, mem_id)) # we need to get the mem pitch for later usage pitch = ueye.INT() check( ueye.is_InquireImageMem(cam, mem_ptr, mem_id, width, height, bits_per_pixel, pitch)) #expMax = ueye.DOUBLE(0.0) expMax = [10, 20, 30, 40] # now lets capture a contineous video while True: # For loop for i in my_range(0, 4, 1): if i == 4: break # print("i= ",expMax[i]) timeExp = ueye.DOUBLE(expMax[i]) check( ueye.is_Exposure(cam, ueye.IS_EXPOSURE_CMD_SET_EXPOSURE, timeExp, ueye.sizeof(timeExp))) print("Set Exposure :", timeExp) time.sleep(1) # lets capture one image check(ueye.is_FreezeVideo(cam, ueye.IS_WAIT)) # for this we use a function from the pyueye interface get data array = ueye.get_data(mem_ptr, width, height, bits_per_pixel, pitch, copy=False) # we do not want to copy # print(array) # we have to reshape the array frame = np.reshape(array, (height.value, width.value, 3)) # print(frame) framesmall = cv2.resize(frame, (0, 0), fx=0.3, fy=0.3) time.sleep(1) #cv2.imshow('img', framesmall) # Save image OpenCV cv2.imwrite("img_" + str(expMax[i]) + 'ms.jpg', frame) print("save image to file: " + "img_" + str(expMax[i]) + 'ms.jpg') # if the 'q' key is pressed, stop the loop key = cv2.waitKey(1) & 0xFF if cv2.waitKey(1) & 0xFF == ord('q'): break # we have to free our image mem at the end check(ueye.is_FreeImageMem(cam, mem_ptr, mem_id)) check(ueye.is_ExitCamera(cam))
def __init__(self, camId=0): print("Initializing camera module") self.hCam = ueye.HIDS(camId) # Starts the driver and establishes the connection to the camera nRet = ueye.is_InitCamera(self.hCam, None) if nRet != ueye.IS_SUCCESS: print("is_InitCamera ERROR") nRet = ueye.is_ResetToDefault(self.hCam) if nRet != ueye.IS_SUCCESS: print("is_ResetToDefault ERROR") nRet = ueye.is_SetDisplayMode(self.hCam, ueye.IS_SET_DM_DIB) # for monochrome camera models use Y8 mode self.m_nColorMode = ueye.IS_CM_MONO8 self.nBitsPerPixel = ueye.INT(8) self.bytes_per_pixel = int(self.nBitsPerPixel / 8) print("Monochrome Mode") # Area of interest can be set here nRet = ueye.is_AOI(self.hCam, ueye.IS_AOI_IMAGE_GET_AOI, self.rectAOI, ueye.sizeof(self.rectAOI)) if nRet != ueye.IS_SUCCESS: print("is_AOI ERROR") self.width = self.rectAOI.s32Width self.height = self.rectAOI.s32Height # Prints out some information about the camera and the sensor #print("Camera model:\t\t", self.sInfo.strSensorName.decode('utf-8')) #print("Camera serial no.:\t", self.cInfo.SerNo.decode('utf-8')) print("Maximum image width:\t", self.width) print("Maximum image height:\t", self.height) # Allocates an image memory for an image having its dimensions defined by width and height and its color depth defined by nBitsPerPixel nRet = ueye.is_AllocImageMem(self.hCam, self.width, self.height, self.nBitsPerPixel, self.pcImageMemory, self.MemID) if nRet != ueye.IS_SUCCESS: print("is_AllocImageMem ERROR") else: # Makes the specified image memory the active memory nRet = ueye.is_SetImageMem(self.hCam, self.pcImageMemory, self.MemID) if nRet != ueye.IS_SUCCESS: print("is_SetImageMem ERROR") else: # Set the desired color mode nRet = ueye.is_SetColorMode(self.hCam, self.m_nColorMode) # Activates the camera's live video mode (free run mode) nRet = ueye.is_CaptureVideo(self.hCam, ueye.IS_DONT_WAIT) if nRet != ueye.IS_SUCCESS: print("is_CaptureVideo ERROR") ueye.is_SetRopEffect(self.hCam, ueye.IS_SET_ROP_MIRROR_UPDOWN, 1, 0) ueye.is_SetRopEffect(self.hCam, ueye.IS_SET_ROP_MIRROR_LEFTRIGHT, 1, 0) # Enables the queue mode for existing image memory sequences nRet = ueye.is_InquireImageMem(self.hCam, self.pcImageMemory, self.MemID, self.width, self.height, self.nBitsPerPixel, self.pitch) if nRet != ueye.IS_SUCCESS: print("is_InquireImageMem ERROR") # enable trigger for new frame ueye.is_EnableEvent(self.hCam, ueye.IS_SET_EVENT_FRAME) print("Initialized!")
def Cameras_stream(): #Variables hCam1 = ueye.HIDS(1) #0: first available camera; 1-254: The camera with the specified camera ID hCam2 = ueye.HIDS(2) #0: first available camera; 1-254: The camera with the specified camera ID sInfo = ueye.SENSORINFO() cInfo = ueye.CAMINFO() pcImageMemory = ueye.c_mem_p() pcImageMemory2 = ueye.c_mem_p() MemID = ueye.int() MemID2 = ueye.int() rectAOI = ueye.IS_RECT() pitch = ueye.INT() nBitsPerPixel = ueye.INT(24) #24: bits per pixel for color mode; take 8 bits per pixel for monochrome channels = 3 #3: channels for color mode(RGB); take 1 channel for monochrome m_nColorMode = ueye.INT() # Y8/RGB16/RGB24/REG32 bytes_per_pixel = int(nBitsPerPixel / 8) #--------------------------------------------------------------------------------------------------------------------------------------- # print("START") # print() # Starts the driver and establishes the connection to the camera nRet1 = ueye.is_InitCamera(hCam1, None) if nRet1 != ueye.IS_SUCCESS: pass # print("is_InitCamera ERROR") else: print(f'Camera 1 : SUCCESS') nRet2 = ueye.is_InitCamera(hCam2, None) if nRet2 != ueye.IS_SUCCESS: pass # print("is_InitCamera ERROR") else: print(f'Camera 2 : SUCCESS') # Reads out the data hard-coded in the non-volatile camera memory and writes it to the data structure that cInfo points to nRet1 = ueye.is_GetCameraInfo(hCam1, cInfo) if nRet1 != ueye.IS_SUCCESS: print("is_GetCameraInfo ERROR") nRet2 = ueye.is_GetCameraInfo(hCam2, cInfo) if nRet2 != ueye.IS_SUCCESS: print("is_GetCameraInfo ERROR") # You can query additional information about the sensor type used in the camera nRet1 = ueye.is_GetSensorInfo(hCam1, sInfo) if nRet1 != ueye.IS_SUCCESS: print("is_GetSensorInfo ERROR") nRet1 = ueye.is_ResetToDefault( hCam1) if nRet1 != ueye.IS_SUCCESS: print("is_ResetToDefault ERROR") # Set display mode to DIB nRet1 = ueye.is_SetDisplayMode(hCam1, ueye.IS_SET_DM_DIB) nRet2 = ueye.is_SetDisplayMode(hCam2, ueye.IS_SET_DM_DIB) # Set the right color mode if int.from_bytes(sInfo.nColorMode.value, byteorder='big') == ueye.IS_COLORMODE_BAYER: # setup the color depth to the current windows setting ueye.is_GetColorDepth(hCam1, nBitsPerPixel, m_nColorMode) bytes_per_pixel = int(nBitsPerPixel / 8) print("IS_COLORMODE_BAYER: ", ) print("\tm_nColorMode: \t\t", m_nColorMode) print("\tnBitsPerPixel: \t\t", nBitsPerPixel) print("\tbytes_per_pixel: \t\t", bytes_per_pixel) print() elif int.from_bytes(sInfo.nColorMode.value, byteorder='big') == ueye.IS_COLORMODE_CBYCRY: # for color camera models use RGB32 mode m_nColorMode = ueye.IS_CM_BGRA8_PACKED nBitsPerPixel = ueye.INT(32) bytes_per_pixel = int(nBitsPerPixel / 8) print("IS_COLORMODE_CBYCRY: ", ) print("\tm_nColorMode: \t\t", m_nColorMode) print("\tnBitsPerPixel: \t\t", nBitsPerPixel) print("\tbytes_per_pixel: \t\t", bytes_per_pixel) print() elif int.from_bytes(sInfo.nColorMode.value, byteorder='big') == ueye.IS_COLORMODE_MONOCHROME: # for color camera models use RGB32 mode m_nColorMode = ueye.IS_CM_MONO8 nBitsPerPixel = ueye.INT(8) bytes_per_pixel = int(nBitsPerPixel / 8) print("IS_COLORMODE_MONOCHROME: ", ) print("\tm_nColorMode: \t\t", m_nColorMode) print("\tnBitsPerPixel: \t\t", nBitsPerPixel) print("\tbytes_per_pixel: \t\t", bytes_per_pixel) print() else: # for monochrome camera models use Y8 mode m_nColorMode = ueye.IS_CM_MONO8 nBitsPerPixel = ueye.INT(8) bytes_per_pixel = int(nBitsPerPixel / 8) print("else") # Can be used to set the size and position of an "area of interest"(AOI) within an image nRet1 = ueye.is_AOI(hCam1, ueye.IS_AOI_IMAGE_GET_AOI, rectAOI, ueye.sizeof(rectAOI)) if nRet1 != ueye.IS_SUCCESS: print("is_AOI ERROR") width = rectAOI.s32Width height = rectAOI.s32Height # Prints out some information about the camera and the sensor print("Camera model:\t\t", sInfo.strSensorName.decode('utf-8')) print("Camera serial no.:\t", cInfo.SerNo.decode('utf-8')) print("Maximum image width:\t", width) print("Maximum image height:\t", height) print() #--------------------------------------------------------------------------------------------------------------------------------------- # Allocates an image memory for an image having its dimensions defined by width and height and its color depth defined by nBitsPerPixel nRet1 = ueye.is_AllocImageMem(hCam1, width, height, nBitsPerPixel, pcImageMemory, MemID) if nRet1 != ueye.IS_SUCCESS: print("is_AllocImageMem ERROR") else: # Makes the specified image memory the active memory nRet = ueye.is_SetImageMem(hCam1, pcImageMemory, MemID) if nRet != ueye.IS_SUCCESS: print("is_SetImageMem ERROR") else: # Set the desired color mode nRet = ueye.is_SetColorMode(hCam1, m_nColorMode) if nRet1 != ueye.IS_SUCCESS: print("is_AllocImageMem ERROR") else: # Makes the specified image memory the active memory nRet = ueye.is_SetImageMem(hCam1, pcImageMemory, MemID) if nRet != ueye.IS_SUCCESS: print("is_SetImageMem ERROR") else: # Set the desired color mode nRet = ueye.is_SetColorMode(hCam2, m_nColorMode) # Allocates an image memory for an image having its dimensions defined by width and height and its color depth defined by nBitsPerPixel nRet = ueye.is_AllocImageMem(hCam2, width, height, nBitsPerPixel, pcImageMemory2, MemID2) if nRet != ueye.IS_SUCCESS: print("is_AllocImageMem ERROR") else: # Makes the specified image memory the active memory nRet = ueye.is_SetImageMem(hCam2, pcImageMemory2, MemID2) if nRet != ueye.IS_SUCCESS: print("is_SetImageMem ERROR") else: # Set the desired color mode nRet = ueye.is_SetColorMode(hCam2, m_nColorMode) nRet = ueye.is_AllocImageMem(hCam2, width, height, nBitsPerPixel, pcImageMemory2, MemID2) if nRet != ueye.IS_SUCCESS: print("is_AllocImageMem ERROR") else: # Makes the specified image memory the active memory nRet = ueye.is_SetImageMem(hCam2, pcImageMemory2, MemID2) if nRet != ueye.IS_SUCCESS: print("is_SetImageMem ERROR") else: # Set the desired color mode nRet = ueye.is_SetColorMode(hCam2, m_nColorMode) # Activates the camera's live video mode (free run mode) nRet = ueye.is_CaptureVideo(hCam1, ueye.IS_DONT_WAIT) if nRet != ueye.IS_SUCCESS: print("is_CaptureVideo ERROR") nRet = ueye.is_CaptureVideo(hCam2, ueye.IS_DONT_WAIT) if nRet != ueye.IS_SUCCESS: print("is_CaptureVideo ERROR") # Enables the queue mode for existing image memory sequences nRet = ueye.is_InquireImageMem(hCam1, pcImageMemory, MemID, width, height, nBitsPerPixel, pitch) if nRet != ueye.IS_SUCCESS: print("is_InquireImageMem ERROR") else: print("Press q to leave the programm") nRet2 = ueye.is_InquireImageMem(hCam2, pcImageMemory2, MemID, width, height, nBitsPerPixel, pitch) if nRet2 != ueye.IS_SUCCESS: print("is_InquireImageMem ERROR") else: print("Press q to leave the programm") #--------------------------------------------------------------------------------------------------------------------------------------- # Continuous image display while(nRet == ueye.IS_SUCCESS) and (nRet2 == ueye.IS_SUCCESS): # In order to display the image in an OpenCV window we need to... # ...extract the data of our image memory array = ueye.get_data(pcImageMemory, width, height, nBitsPerPixel, pitch, copy=False) array2 = ueye.get_data(pcImageMemory2, width, height, nBitsPerPixel, pitch, copy=False) # bytes_per_pixel = int(nBitsPerPixel / 8) # ...reshape it in an numpy array... frame = np.reshape(array,(height.value, width.value, bytes_per_pixel)) frame2 = np.reshape(array2,(height.value, width.value, bytes_per_pixel)) # ...resize the image by a half # frame = cv2.resize(frame,(0,0),fx=0.5, fy=0.5) #--------------------------------------------------------------------------------------------------------------------------------------- #Include image data processing here #--------------------------------------------------------------------------------------------------------------------------------------- #...and finally display it if __name__=="__main__": cv2.imshow("SimpleLive_Python_uEye_OpenCV", frame) cv2.imshow("SimpleLive_Python_uEye_OpenCV 2", frame2) # Press q if you want to end the loop if cv2.waitKey(1) & 0xFF == ord('q'): break #--------------------------------------------------------------------------------------------------------------------------------------- # Releases an image memory that was allocated using is_AllocImageMem() and removes it from the driver management ueye.is_FreeImageMem(hCam1, pcImageMemory, MemID) ueye.is_FreeImageMem(hCam2, pcImageMemory2, MemID2) # Disables the hCam camera handle and releases the data structures and memory areas taken up by the uEye camera ueye.is_ExitCamera(hCam1) ueye.is_ExitCamera(hCam2) # Destroys the OpenCv windows cv2.destroyAllWindows() print() print("END")