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()
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) thingy=ueye.is_SetHardwareGain(hCam,gain, ueye.IS_IGNORE_PARAMETER, ueye.IS_IGNORE_PARAMETER, ueye.IS_IGNORE_PARAMETER) #--------------------------------------------------------------------------------------------------------------------------------------- nRet = ueye.is_FreezeVideo(hCam, ueye.IS_WAIT) Iinfo=ueye.UEYEIMAGEINFO() n=1 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))
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