def captureVideo(self): count = 0 prevCaptureTime = 0 imageInfo = ueye.UEYEIMAGEINFO() while (True): 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)) nRet = ueye.is_GetImageInfo(self.hCam, self.MemID, imageInfo, ueye.sizeof(imageInfo)) if nRet != ueye.IS_SUCCESS: print("GET IMAGE INFO ERROR") captureTime = imageInfo.u64TimestampDevice if ((captureTime > prevCaptureTime) and (captureTime != 0)): exposureTime = ueye.double() retVal = ueye.is_Exposure(self.hCam, ueye.IS_EXPOSURE_CMD_GET_EXPOSURE, exposureTime, 8) self.timeStampsFile.write( str(count).zfill(5) + " " + str(captureTime - 0) + " " + str(exposureTime) + "\n") cv2.imwrite("images/" + str(count).zfill(5) + ".jpg", frame) count = count + 1 prevCaptureTime = captureTime - 0 cv2.imshow("captureVideo", frame) if cv2.waitKey(1) & 0xFF == ord('q'): break cv2.destroyAllWindows()
# ...resize the image by a half frame2 = cv2.resize(frame,(0,0),fx=0.3, fy=0.3) #--------------------------------------------------------------------------------------------------------------------------------------- #Include image data processing here #--------------------------------------------------------------------------------------------------------------------------------------- #...and finally display it cv2.imshow("SimpleLive_Python_uEye_OpenCV", frame2) # Press q if you want to end the loop if cv2.waitKey(1): nRet = ueye.is_FreezeVideo(hCam, ueye.IS_WAIT) nRet1= ueye.is_GetImageInfo(hCam,MemID, Iinfo, ueye.sizeof(Iinfo) ) print(Iinfo.TimestampSystem.wSecond.value) if cv2.waitKey(1) & 0xFF == ord('s'): string="Cal"+str(n)+".jpg" cv2.imwrite(string, frame) n=n+1 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(hCam, pcImageMemory, MemID)
def captureCalibrationVideo(self): pParam = ueye.double() nRet = ueye.is_Exposure(self.hCam, ueye.IS_EXPOSURE_CMD_GET_EXPOSURE_RANGE_MAX, pParam, ueye.sizeof(pParam)) if nRet != ueye.IS_SUCCESS: print("Error getting max exposure, error code: ", nRet) else: print("max exposure is: ", pParam.value) pParam = ueye.double() pParam.value = 0 nRet = ueye.is_Exposure(self.hCam, ueye.IS_EXPOSURE_CMD_SET_EXPOSURE, pParam, ueye.sizeof(pParam)) count = 0 prevCaptureTime = 0 maxExposure = pParam.value currExposure = 0 imageInfo = ueye.UEYEIMAGEINFO() while (currExposure <= maxExposure): 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)) nRet = ueye.is_GetImageInfo(self.hCam, self.MemID, imageInfo, ueye.sizeof(imageInfo)) if nRet != ueye.IS_SUCCESS: print("GET IMAGE INFO ERROR") captureTime = imageInfo.u64TimestampDevice if ((captureTime > prevCaptureTime) and (captureTime != 0)): pParam = ueye.double() pParam.value = currExposure nRet = ueye.is_Exposure(self.hCam, ueye.IS_EXPOSURE_CMD_SET_EXPOSURE, pParam, ueye.sizeof(pParam)) currExposure += 0.01 self.timeStampsFile.write( str(count).zfill(5) + " " + str(captureTime - 0) + " " + str(currExposure) + "\n") cv2.imwrite("images/" + str(count).zfill(5) + ".jpg", frame) count = count + 1 prevCaptureTime = captureTime - 0 cv2.imshow("captureVideo", frame) if cv2.waitKey(1) & 0xFF == ord('q'): break cv2.destroyAllWindows()
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