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 __del__(self): ueye.is_DisableEvent(self.hCam, ueye.IS_SET_EVENT_FRAME) # Releases an image memory that was allocated using is_AllocImageMem() and removes it from the driver management ueye.is_FreeImageMem(self.hCam, self.pcImageMemory, self.MemID) # Disables the self.self.hCam camera handle and releases the data structures and memory areas taken up by the uEye camera ueye.is_ExitCamera(self.hCam)
def __disable_events(self): if not ueye.is_DisableEvent(self.cam, ueye.IS_SET_EVENT_FRAME) == ueye.IS_SUCCESS: raise RuntimeError("Event not disabled") print("Events disabled")
def closeEvent(self, event): self.capturing = False ueye.is_DisableEvent(self.hCam, self.frame_event_id) ueye.is_ExitEvent(self.hCam, self.frame_event_id) if ueye.is_CaptureVideo(self.hCam, ueye.IS_GET_LIVE): ueye.is_StopLiveVideo(self.hCam, Wait=True)