def saveImage(self): ueye.is_AllocImageMem(self.hcam, self.sensorinfo.nMaxWidth, self.sensorinfo.nMaxHeight, 24, self.pccmem, self.memID) ueye.is_SetImageMem(self.hcam, self.pccmem, self.memID) ueye.is_SetDisplayPos(self.hcam, 100, 100) self.nret = ueye.is_FreezeVideo(self.hcam, ueye.IS_WAIT) self.rawImageTimeStamp = datetime.datetime.now() self.imageTimeStamp = datetime.datetime.now().strftime('%Y_%m_%d_%H_%M_%S') self.imageName = 'imagem_%s.jpg' % self.imageTimeStamp self.imagePath = self.operationConfigs['savingDirectory'] + self.imageName # self.imagePath = self.operationConfigs['savingDirectory'] + "tmp.jpg" self.FileParams = ueye.IMAGE_FILE_PARAMS() self.FileParams.pwchFileName = self.imagePath self.FileParams.nFileType = ueye.IS_IMG_BMP self.FileParams.ppcImageMem = None self.FileParams.pnImageID = None self.nret = ueye.is_ImageFile(self.hcam, ueye.IS_IMAGE_FILE_CMD_SAVE, self.FileParams, ueye.sizeof(self.FileParams)) ueye.is_FreeImageMem(self.hcam, self.pccmem, self.memID) sleep(.01) ueye.is_ExitCamera(self.hcam) # self.image = np.ones((self.sensorinfo.nMaxHeight.value, self.sensorinfo.nMaxWidth.value), dtype=np.uint8) # ueye.is_CopyImageMem(self.hcam, self.pccmem, self.memID, self.image.ctypes.data) self.image = np.uint8(ndimage.imread(self.imagePath, flatten=True))
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 release(self): # 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 hCam camera handle and releases the data structures and memory areas taken up by the uEye camera ueye.is_ExitCamera(self.hCam) print('Camera connection closed')
def close_connection(self): """ Close the connection with the Thorlabs camera and release the handle as well as the memory usage """ ueye.is_FreeImageMem(self.hcam, self.pcImageMemory, self.MemID) ueye.is_ExitCamera(self.hcam) print('Connection to the camera was closed')
def disconnect_device(self, variable=None): ueye.is_FreeImageMem(self.hid, self.ppcImgMem, self.MemID) ueye.is_ExitCamera(self.hid) self.camera = False if variable: variable.delete(0, 'end') self.return_devices(variable)
def disconnect_device(self): """ Disconnect a previously connected camera. """ ueye.is_FreeImageMem(self.hid, self.ppcImgMem, self.MemID) ueye.is_ExitCamera(self.hid) self.camera = False
def __del__(self): ueye.is_FreeImageMem(self.hCam, self.pcImageMemory, self.MemID) # Disables the hCam camera handle and releases the data structures and memory areas taken up by the uEye camera ueye.is_ExitCamera(self.hCam) # Destroys the OpenCv windows self.timeStampsFile.close()
def main_loop(): color_trackbars() while (CameraApi.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(CameraApi.pcImageMemory, CameraApi.width, CameraApi.height, CameraApi.nBitsPerPixel, CameraApi.pitch, copy=False) # ...reshape it in an numpy array... frame = np.reshape(array, (CameraApi.height.value, CameraApi.width.value, CameraApi.bytes_per_pixel)) # ...resize the image by a half # frame = cv2.resize(frame,(0,0), fx=0.5, fy=0.5) #--------------------------------------------------------------------------------------------------------------------------------------- #Convert camera feed from BGRA to BGR frame_to_bgr = cv2.cvtColor(frame, cv2.COLOR_BGRA2BGR) #Apply a Gaussian blur that has 11x11 kernel size to the BGR frame frame_to_bgr = cv2.GaussianBlur(frame_to_bgr, (5, 5), 0) cv2.imshow("BGR Frame", frame_to_bgr) #Convert camera feed from BGR color space to HSV color space hsv_frame = cv2.cvtColor(frame_to_bgr, cv2.COLOR_BGR2HSV) frame_threshold(frame_to_bgr, hsv_frame) #--------------------------------------------------------------------------------------------------------------------------------------- # 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(CameraApi.hCam, CameraApi.pcImageMemory, CameraApi.MemID) # Disables the hCam camera handle and releases the data structures and memory areas taken up by the uEye camera ueye.is_ExitCamera(CameraApi.hCam) # Destroys the OpenCv windows cv2.destroyAllWindows() print() print("END")
def return_devices(self, variable): cam_num = ueye.INT() ueye.is_GetNumberOfCameras(cam_num) for i in range(cam_num.value): hid = ueye.HIDS(cam_num) s = ueye.is_InitCamera(self.hid, self.hwnd) r = ueye.is_GetSensorInfo(self.hid, self.sinfo) sname = self.sinfo.strSensorName.decode('UTF-8') self.detected_devices[sname] = i + 1 variable.insert('end', sname) ueye.is_ExitCamera(self.hid)
def close_camera(self): ret = None if self.cam is not None: ret = ueye.is_ExitCamera(self.cam) if ret == ueye.IS_SUCCESS: self.cam = None self.isCameraInit = False
def exit(self): ret = None if self.h_cam is not None: ret = ueye.is_ExitCamera(self.h_cam) if ret == ueye.IS_SUCCESS: self.h_cam = None return
def closeEvent(self, event): """ Close window and disconnects camera. """ self.running = False if self.initTrigger is not None: ret = ueye.is_ExitCamera(self.hcam)
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 saveImage(self): try: time1 = datetime.datetime.now() ueye.is_AllocImageMem(self.hcam, self.sensorinfo.nMaxWidth, self.sensorinfo.nMaxHeight, 24, self.pccmem, self.memID) ueye.is_SetImageMem(self.hcam, self.pccmem, self.memID) ueye.is_SetDisplayPos(self.hcam, 100, 100) self.nret = ueye.is_FreezeVideo(self.hcam, ueye.IS_WAIT) self.imageTimeStamp = datetime.datetime.now().strftime( '%Y_%m_%d_%H_%M_%S') self.imageName = 'imagem_%s.jpg' % self.imageTimeStamp self.imagePath = self.operationConfigs[ 'savingDirectory'] + self.imageName self.FileParams = ueye.IMAGE_FILE_PARAMS() self.FileParams.pwchFileName = self.imagePath self.FileParams.nFileType = ueye.IS_IMG_BMP self.FileParams.ppcImageMem = None self.FileParams.pnImageID = None self.nret = ueye.is_ImageFile(self.hcam, ueye.IS_IMAGE_FILE_CMD_SAVE, self.FileParams, ueye.sizeof(self.FileParams)) ueye.is_FreeImageMem(self.hcam, self.pccmem, self.memID) sleep(.01) ueye.is_ExitCamera(self.hcam) time2 = datetime.datetime.now() elapsed_time = time2 - time1 logging.info('Saved: {}! Elasped time (ms): {}'.format( self.imageName, elapsed_time.microseconds / 1000)) self.pijuice.status.SetLedBlink('D2', 2, [0, 255, 0], 50, [0, 255, 0], 50) sleep(.1) self.pijuice.status.SetLedState('D2', [0, 0, 0]) except: logging.warning('NOT SAVED: {}!\n'.format(self.imageName)) self.pijuice.status.SetLedBlink('D2', 2, [255, 0, 0], 50, [255, 0, 0], 50) sleep(.1) self.pijuice.status.SetLedState('D2', [0, 0, 0]) pass
def disconnect(self): exitRet = ueye.is_ExitCamera(self.CamID) if exitRet == 0: self.connected = False print('IDS camera disconnected.') else: print("Disconencting failure.")
def close(self): # Wait to make sure video file is saved completely while not self._done_saving: pass self._deallocate_memory() err = ueye.is_ExitCamera(self._cam) if err != ueye.IS_SUCCESS: raise CameraException(self._cam, 'ueye>close>', err)
def exit(self): """ Close the connection to the camera. """ ret = None if self.h_cam is not None: ret = ueye.is_ExitCamera(self.h_cam) if ret == ueye.IS_SUCCESS: self.h_cam = None
def exit(self): ret = None if self.h_cam is not None: ret = ueye.is_ExitCamera(self.h_cam) #disable message by using None at the window self.enable_message(None) if ret == ueye.IS_SUCCESS: self.h_cam = None
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 take_picture(hCam, pcImageMemory, MemID, pitch, nBitsPerPixel, bytes_per_pixel, height, width): array = ueye.get_data(pcImageMemory, width, height, nBitsPerPixel, pitch, copy=False) frame = np.reshape(array, (height.value, width.value, bytes_per_pixel)) 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() return frame
def exit(self): """ Close camera connection. """ if self.cam is not None: self.nRet = ueye.is_ExitCamera(self.cam) if self.nRet == ueye.IS_SUCCESS: self.cam = None print() print("Camera exit.")
def get_camera_status(n_device_id=5): print_style("Camera Status", color="blue") for i in range(n_device_id): h_cam = ueye.HIDS(i) ret = ueye.is_InitCamera(h_cam, None) if ret == ueye.IS_SUCCESS: print_style(" Camera ID:", i, " Available", color="green") else: print_style(" Camera ID:", i, " Unavailable", color="red") ret = ueye.is_ExitCamera(h_cam)
def Exit(self): if self.KepcoInit_Switch == 1: self.kepco_inst.write("CURR {curr}".format(curr=0)) self.kepco_inst.write("OUTP OFF") self.Movie_Switch = -1 #time.sleep(1) #cv2.destroyAllWindows() ueye.is_FreeImageMem(self.hcam, self.mem_ptr, self.mem_id) self.ret = ueye.is_ExitCamera(self.hcam) self.close()
def return_devices(self): """ Return list of connected camera. """ varOut = [] cam_num = ueye.INT() ueye.is_GetNumberOfCameras(cam_num) for i in range(cam_num.value): hid = ueye.HIDS(cam_num) s = ueye.is_InitCamera(self.hid, self.hwnd) r = ueye.is_GetSensorInfo(self.hid, self.sinfo) sname = self.sinfo.strSensorName.decode('UTF-8') self.detected_devices[sname] = i+1 varOut.append(sname) ueye.is_ExitCamera(self.hid) return varOut
def saveImage(self): try: time1 = datetime.datetime.now() ueye.is_AllocImageMem(self.hcam, self.sensorinfo.nMaxWidth, self.sensorinfo.nMaxHeight, 24, self.pccmem, self.memID) ueye.is_SetImageMem(self.hcam, self.pccmem, self.memID) ueye.is_SetDisplayPos(self.hcam, 100, 100) self.nret = ueye.is_FreezeVideo(self.hcam, ueye.IS_WAIT) self.imageTimeStamp = datetime.datetime.now().strftime( '%Y_%m_%d_%H_%M_%S') self.imageName = 'imagem_%s.jpg' % self.imageTimeStamp self.imagePath = self.savingDirectory + self.imageName self.FileParams = ueye.IMAGE_FILE_PARAMS() self.FileParams.pwchFileName = self.imagePath self.FileParams.nFileType = ueye.IS_IMG_BMP self.FileParams.ppcImageMem = None self.FileParams.pnImageID = None self.nret = ueye.is_ImageFile(self.hcam, ueye.IS_IMAGE_FILE_CMD_SAVE, self.FileParams, ueye.sizeof(self.FileParams)) # print(nret) ueye.is_FreeImageMem(self.hcam, self.pccmem, self.memID) sleep(.1) ueye.is_ExitCamera(self.hcam) time2 = datetime.datetime.now() elapsed_time = time2 - time1 # print('Elasped time (s): {}'.format(elapsed_time)) print('Image saved at {}! Elasped time (ms) {}'.format( self.imageTimeStamp, elapsed_time.microseconds / 1000)) except: print('Image not saved at {}!\n'.format(self.imageTimeStamp)) pass
def camParLoad(self): """Load Ueye Camera Parameters from EEPROM""" logger.debug("Loading parameters from EEPROM") logger.debug("Disabling framegetter:") self.stop_recording() nullint = ueye._value_cast(0, ueye.ctypes.c_uint) if self.state: rv = ueye.is_ExitCamera(self.hCam) nret, hCam = ueye_camera.cameraInit(True) # rvv = ueye.is_ParameterSet(self.hCam,ueye.IS_PARAMETERSET_CMD_LOAD_EEPROM,nullint,nullint) # rectAOI = rect_aoi = ueye.IS_RECT() # # Can be used to set the size and position of an "area of interest"(AOI) within an image # nRet = ueye.is_AOI(self.hCam, ueye.IS_AOI_IMAGE_GET_AOI, rectAOI, ueye.sizeof(rectAOI)) self.width = ueye_camera.rect_aoi.s32Width.value self.height = ueye_camera.rect_aoi.s32Height.value if self.width > 0: self.frame = np.zeros((self.height, self.width), np.uint8) self.start_recording() else: detection.addTextlines(self.frame, ["Camera not connected!", "Cannot load parameters"]) self.image_data.emit(self.frame)
def close(): ueye.is_ExitCamera(cam)
#...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) # 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")
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 close(self): ueye.is_FreeImageMem(self.input, self.mem_image, self.mem_id) ueye.is_ExitCamera(self.input)