def display_image(self): fps = ueye.DOUBLE() ueye.is_GetFramesPerSecond(self.hCam, fps) timeout = int((5 / fps) * 1000) h_event = None if platform.system() == 'Windows': h_event = win32event.CreateEvent(None, False, False, None) self.event = ueye.HANDLE(int(h_event)) ueye.is_InitEvent(self.hCam, self.event, self.frame_event_id) ueye.is_EnableEvent(self.hCam, self.frame_event_id) while True: ret = None if not self.capturing: break if platform.system() == 'Windows': ret = win32event.WaitForSingleObject(h_event, timeout) elif platform.system() == 'Linux': ret = ueye.is_WaitEvent(self.hCam, self.frame_event_id, timeout) if ret == 0: converted_image_data = self.convert_image_data() self.image_data_copy = ( ueye.CHAR * int(self.img_data.width * self.img_data.height * 3))() ueye.is_CopyImageMem( hCam=self.hCam, pcSource=converted_image_data.memory_pointer, nID=converted_image_data.memory_id, pcDest=self.image_data_copy) bytes_per_pixel = 3 self.image_data_copy = numpy.reshape( self.image_data_copy, (int(self.img_data.height), int( self.img_data.width), bytes_per_pixel)) self.image_data_copy = self.image_data_copy.view(numpy.uint8) self.pil_image = Image.fromarray(self.image_data_copy) self.graphics_scene.clear() self.width, self.height = self.pil_image.size self.qt_image = ImageQt.ImageQt(self.pil_image) self.pix_map = QPixmap.fromImage(self.qt_image) self.graphics_scene.addPixmap(self.pix_map) self.graphics_view.fitInView( QRectF(0, 0, self.width, self.height), Qt.KeepAspectRatio) self.graphics_scene.update() app.processEvents()
def GetNextBuffer(self): """ Get the next valid image buffer""" self.NewSeqBuf1=ueye.c_mem_p() tries=0 while True: rv= ueye.is_GetImageMem(self.hcam, self.NewSeqBuf1) if self.NewSeqBuf1.value != self.LastSeqBuf1.value: break tries+=1 if tries ==3: return True rv=ueye.is_EnableEvent(self.hcam, ueye.IS_SET_EVENT_FRAME) rv= ueye.is_WaitEvent(self.hcam, ueye.IS_SET_EVENT_FRAME, 1000) rv=ueye.is_DisableEvent(self.hcam, ueye.IS_SET_EVENT_FRAME) self.LastSeqBuf1.value=self.NewSeqBuf1.value return False
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))
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 __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 __set_events(self): if not ueye.is_EnableEvent(self.cam, ueye.IS_SET_EVENT_FRAME) == ueye.IS_SUCCESS: raise RuntimeError("Event not set") print("Events enabled")