def __init__(self, index): self.hCam = ueye.HIDS( index ) # 0: first available camera; 1-254: The camera with the specified camera ID self.sInfo = ueye.SENSORINFO() self.cInfo = ueye.CAMINFO() self.pcImageMemory = ueye.c_mem_p() self.MemID = ueye.int() self.rectAOI = ueye.IS_RECT() self.pitch = ueye.INT() self.nBitsPerPixel = ueye.INT( 24 ) # 24: bits per pixel for color mode; take 8 bits per pixel for monochrome channels = 3 # 3: channels for color mode(RGB); take 1 channel for monochrome self.m_nColorMode = ueye.INT() # Y8/RGB16/RGB24/REG32 self.bytes_per_pixel = int(self.nBitsPerPixel / 8) # --------------------------------------------------------------------------------------------------------------------------------------- # print( "START" ) # print() # Starts the driver and establishes the connection to the camera self.nRet = ueye.is_InitCamera(self.hCam, None) if self.nRet != ueye.IS_SUCCESS: raise Exception("is_InitCamera ERROR") # Reads out the data hard-coded in the non-volatile camera memory and writes it to the data structure that self.cInfo # points to self.nRet = ueye.is_GetCameraInfo(self.hCam, self.cInfo) if self.nRet != ueye.IS_SUCCESS: raise Exception("is_GetCameraInfo ERROR") # You can query additional information about the sensor type used in the camera self.nRet = ueye.is_GetSensorInfo(self.hCam, self.sInfo) if self.nRet != ueye.IS_SUCCESS: raise Exception("is_GetSensorInfo ERROR") self.nRet = ueye.is_ResetToDefault(self.hCam) if self.nRet != ueye.IS_SUCCESS: raise Exception("is_ResetToDefault ERROR") # Set display mode to DIB self.nRet = ueye.is_SetDisplayMode(self.hCam, ueye.IS_SET_DM_DIB) # Set the right color mode if int.from_bytes(self.sInfo.nColorMode.value, byteorder='big') == ueye.IS_COLORMODE_BAYER: # setup the color depth to the current windows setting ueye.is_GetColorDepth(self.hCam, self.nBitsPerPixel, self.m_nColorMode) self.bytes_per_pixel = int(self.nBitsPerPixel / 8) print("IS_COLORMODE_BAYER: ", ) print("\tm_nColorMode: \t\t", self.m_nColorMode) print("\tnBitsPerPixel: \t\t", self.nBitsPerPixel) print("\tbytes_per_pixel: \t\t", self.bytes_per_pixel) print() elif int.from_bytes(self.sInfo.nColorMode.value, byteorder='big') == ueye.IS_COLORMODE_CBYCRY: # for color camera models use RGB32 mode self.m_nColorMode = ueye.IS_CM_BGRA8_PACKED self.nBitsPerPixel = ueye.INT(32) self.bytes_per_pixel = int(self.nBitsPerPixel / 8) print("IS_COLORMODE_CBYCRY: ", ) print("\tm_nColorMode: \t\t", self.m_nColorMode) print("\tnBitsPerPixel: \t\t", self.nBitsPerPixel) print("\tbytes_per_pixel: \t\t", self.bytes_per_pixel) print() elif int.from_bytes(self.sInfo.nColorMode.value, byteorder='big') == ueye.IS_COLORMODE_MONOCHROME: # for color camera models use RGB32 mode self.m_nColorMode = ueye.IS_CM_MONO8 self.nBitsPerPixel = ueye.INT(8) self.bytes_per_pixel = int(self.nBitsPerPixel / 8) print("IS_COLORMODE_MONOCHROME: ", ) print("\tm_nColorMode: \t\t", self.m_nColorMode) print("\tnBitsPerPixel: \t\t", self.nBitsPerPixel) print("\tbytes_per_pixel: \t\t", self.bytes_per_pixel) print() else: # 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("else") # Can be used to set the size and position of an "area of interest"(AOI) within an image self.nRet = ueye.is_AOI(self.hCam, ueye.IS_AOI_IMAGE_GET_AOI, self.rectAOI, ueye.sizeof(self.rectAOI)) if self.nRet != ueye.IS_SUCCESS: raise Exception("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) print() # --------------------------------------------------------------------------------------------------------------------------------------- # Allocates an image memory for an image having its dimensions defined by width and height and its color depth # defined by nBitsPerPixel self.nRet = ueye.is_AllocImageMem(self.hCam, self.width, self.height, self.nBitsPerPixel, self.pcImageMemory, self.MemID) if self.nRet != ueye.IS_SUCCESS: raise Exception("is_AllocImageMem ERROR") else: # Makes the specified image memory the active memory self.nRet = ueye.is_SetImageMem(self.hCam, self.pcImageMemory, self.MemID) if self.nRet != ueye.IS_SUCCESS: raise Exception("is_SetImageMem ERROR") else: # Set the desired color mode self.nRet = ueye.is_SetColorMode(self.hCam, self.m_nColorMode) # Activates the camera's live video mode (free run mode) self.nRet = ueye.is_CaptureVideo(self.hCam, ueye.IS_DONT_WAIT) if self.nRet != ueye.IS_SUCCESS: raise Exception("is_CaptureVideo ERROR") # Enables the queue mode for existing image memory sequences self.nRet = ueye.is_InquireImageMem(self.hCam, self.pcImageMemory, self.MemID, self.width, self.height, self.nBitsPerPixel, self.pitch) if self.nRet != ueye.IS_SUCCESS: raise Exception("is_InquireImageMem ERROR") else: print("Camera Connection success")
def initialize_camera(): #--------------------------------------------------------------------------------------------------------------------------------------- print("START") print() # Starts the driver and establishes the connection to the camera CameraApi.nRet = ueye.is_InitCamera(CameraApi.hCam, None) if CameraApi.nRet != ueye.IS_SUCCESS: print("is_InitCamera ERROR") # Reads out the data hard-coded in the non-volatile camera memory and writes it to the data structure that cInfo points to CameraApi.nRet = ueye.is_GetCameraInfo(CameraApi.hCam, CameraApi.cInfo) if CameraApi.nRet != ueye.IS_SUCCESS: print("is_GetCameraInfo ERROR") # You can query additional information about the sensor type used in the camera CameraApi.nRet = ueye.is_GetSensorInfo(CameraApi.hCam, CameraApi.sInfo) if CameraApi.nRet != ueye.IS_SUCCESS: print("is_GetSensorInfo ERROR") CameraApi.nRet = ueye.is_ResetToDefault(CameraApi.hCam) if CameraApi.nRet != ueye.IS_SUCCESS: print("is_ResetToDefault ERROR") # Set display mode to DIB CameraApi.nRet = ueye.is_SetDisplayMode(CameraApi.hCam, ueye.IS_SET_DM_DIB) # Set the right color mode if int.from_bytes(CameraApi.sInfo.nColorMode.value, byteorder='big') == ueye.IS_COLORMODE_BAYER: # setup the color depth to the current windows setting ueye.is_GetColorDepth(CameraApi.hCam, CameraApi.nBitsPerPixel, CameraApi.m_nColorMode) CameraApi.bytes_per_pixel = int(CameraApi.nBitsPerPixel / 8) print("IS_COLORMODE_BAYER: ", ) print("\tm_nColorMode: \t\t", CameraApi.m_nColorMode) print("\tnBitsPerPixel: \t\t", CameraApi.nBitsPerPixel) print("\tbytes_per_pixel: \t\t", CameraApi.bytes_per_pixel) print() elif int.from_bytes(CameraApi.sInfo.nColorMode.value, byteorder='big') == ueye.IS_COLORMODE_CBYCRY: # for color camera models use RGB32 mode m_nColorMode = ueye.IS_CM_BGRA8_PACKED nBitsPerPixel = ueye.INT(32) CameraApi.bytes_per_pixel = int(nBitsPerPixel / 8) print("IS_COLORMODE_CBYCRY: ", ) print("\tm_nColorMode: \t\t", m_nColorMode) print("\tnBitsPerPixel: \t\t", nBitsPerPixel) print("\tbytes_per_pixel: \t\t", CameraApi.bytes_per_pixel) print() elif int.from_bytes(CameraApi.sInfo.nColorMode.value, byteorder='big') == ueye.IS_COLORMODE_MONOCHROME: # for color camera models use RGB32 mode m_nColorMode = ueye.IS_CM_MONO8 nBitsPerPixel = ueye.INT(8) CameraApi.bytes_per_pixel = int(nBitsPerPixel / 8) print("IS_COLORMODE_MONOCHROME: ", ) print("\tm_nColorMode: \t\t", m_nColorMode) print("\tnBitsPerPixel: \t\t", nBitsPerPixel) print("\tbytes_per_pixel: \t\t", CameraApi.bytes_per_pixel) print() else: # for monochrome camera models use Y8 mode m_nColorMode = ueye.IS_CM_MONO8 nBitsPerPixel = ueye.INT(8) CameraApi.bytes_per_pixel = int(nBitsPerPixel / 8) print("else") # Can be used to set the size and position of an "area of interest"(AOI) within an image CameraApi.nRet = ueye.is_AOI(CameraApi.hCam, ueye.IS_AOI_IMAGE_GET_AOI, CameraApi.rectAOI, ueye.sizeof(CameraApi.rectAOI)) if CameraApi.nRet != ueye.IS_SUCCESS: print("is_AOI ERROR") CameraApi.width = CameraApi.rectAOI.s32Width CameraApi.height = CameraApi.rectAOI.s32Height # Prints out some information about the camera and the sensor print("Camera model:\t\t", CameraApi.sInfo.strSensorName.decode('utf-8')) print("Camera serial no.:\t", CameraApi.cInfo.SerNo.decode('utf-8')) print("Maximum image width:\t", CameraApi.width) print("Maximum image height:\t", CameraApi.height) print() #--------------------------------------------------------------------------------------------------------------------------------------- # Allocates an image memory for an image having its dimensions defined by width and height and its color depth defined by nBitsPerPixel CameraApi.nRet = ueye.is_AllocImageMem(CameraApi.hCam, CameraApi.width, CameraApi.height, CameraApi.nBitsPerPixel, CameraApi.pcImageMemory, CameraApi.MemID) if CameraApi.nRet != ueye.IS_SUCCESS: print("is_AllocImageMem ERROR") else: # Makes the specified image memory the active memory CameraApi.nRet = ueye.is_SetImageMem(CameraApi.hCam, CameraApi.pcImageMemory, CameraApi.MemID) if CameraApi.nRet != ueye.IS_SUCCESS: print("is_SetImageMem ERROR") else: # Set the desired color mode CameraApi.nRet = ueye.is_SetColorMode(CameraApi.hCam, CameraApi.m_nColorMode) # Activates the camera's live video mode (free run mode) CameraApi.nRet = ueye.is_CaptureVideo(CameraApi.hCam, ueye.IS_DONT_WAIT) if CameraApi.nRet != ueye.IS_SUCCESS: print("is_CaptureVideo ERROR") # Enables the queue mode for existing image memory sequences CameraApi.nRet = ueye.is_InquireImageMem( CameraApi.hCam, CameraApi.pcImageMemory, CameraApi.MemID, CameraApi.width, CameraApi.height, CameraApi.nBitsPerPixel, CameraApi.pitch) if CameraApi.nRet != ueye.IS_SUCCESS: print("is_InquireImageMem ERROR") else: print("Press q to leave the programm")
) # 24: bits per pixel for color mode; take 8 bits per pixel for monochrome channels = 3 # 3: channels for color mode(RGB); take 1 channel for monochrome m_nColorMode = ueye.INT() # Y8/RGB16/RGB24/REG32 bytes_per_pixel = int(nBitsPerPixel / 8) # --------------------------------------------------------------------------------------------------------------------------------------- print("START") print() # Starts the driver and establishes the connection to the camera nRet = ueye.is_InitCamera(hCam, None) if nRet != ueye.IS_SUCCESS: print("is_InitCamera ERROR") # Reads out the data hard-coded in the non-volatile camera memory and writes it to the data structure that cInfo # points to nRet = ueye.is_GetCameraInfo(hCam, cInfo) if nRet != ueye.IS_SUCCESS: print("is_GetCameraInfo ERROR") # You can query additional information about the sensor type used in the camera nRet = ueye.is_GetSensorInfo(hCam, sInfo) if nRet != ueye.IS_SUCCESS: print("is_GetSensorInfo ERROR") nRet = ueye.is_ResetToDefault(hCam) if nRet != ueye.IS_SUCCESS: print("is_ResetToDefault ERROR") # Set display mode to DIB nRet = ueye.is_SetDisplayMode(hCam, ueye.IS_SET_DM_DIB)
def Setup(self): # Setup camera's driver and color mode # Starts the driver and establishes the connection to the camera self.nRet = ueye.is_InitCamera(self.cam, None) if self.nRet != ueye.IS_SUCCESS: error_log(self.nRet, "is_InitCamera") self.nRet = ueye.is_SetExternalTrigger(self.cam, ueye.IS_SET_TRIGGER_LO_HI) if self.nRet != ueye.IS_SUCCESS: error_log(self.nRet, "is_SetExternalTrigger") # You can query additional information about the sensor type used in the camera self.nRet = ueye.is_GetSensorInfo(self.cam, self.sInfo) if self.nRet != ueye.IS_SUCCESS: error_log(self.nRet, "is_GetSensorInfo") # Reads out the data hard-coded in the non-volatile camera memory and writes it to the data structure that cInfo points to self.nRet = ueye.is_GetCameraInfo(self.cam, self.cInfo) if self.nRet != ueye.IS_SUCCESS: error_log(self.nRet, "is_GetCameraInfo") # Set Auto Gain #self.set_gain_auto(1) # Take params from json param_from_json(self) # Set Gain self.set_gain(self.gain, self.rGain, self.gGain, self.bGain) # Set Pixelclock self.set_pixelclock(self.pixelclock) # Set Exposure self.set_exposure(self.exposure) # Set display mode to DIB self.nRet = ueye.is_SetDisplayMode(self.cam, ueye.IS_SET_DM_DIB) if self.nRet != ueye.IS_SUCCESS: error_log(self.nRet, "is_SetDisplayMode") self.get_bit_per_pixel(self.m_nColorMode) # Set Color Mode to BGR8 self.nRet = ueye.is_SetColorMode(self.cam, self.m_nColorMode) if self.nRet != ueye.IS_SUCCESS: error_log(self.nRet, "is_SetColorMode") # Set AOI self.nRet = ueye.is_AOI(self.cam, ueye.IS_AOI_IMAGE_SET_AOI, self.rectAOI, ueye.sizeof(self.rectAOI)) if self.nRet != ueye.IS_SUCCESS: error_log(self.nRet, "is_AOI") 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) print("Exposure:\t\t", self.get_exposure()) print("Frame rate:\t\t", self.current_fps) print("PixelClock:\t\t", self.get_pixelclock()) print("Gain:\t\t\t", self.get_gain()) print("rGain:\t\t\t", self.rGain) print("bGain:\t\t\t", self.bGain) print("gGain:\t\t\t", self.gGain) print("Color mode:\t\t", self.m_nColorMode) print("Bits per pixel:\t\t", int(self.bits_per_pixel)) print() self.alloc() self.nRet = self.capture_video() if self.nRet != ueye.IS_SUCCESS: error_log(self.nRet, "is_CaptureVideo") print("Press \'Ctrl + C\' to leave the programm") print()
def __init__(self): #Variables self.hCam = ueye.HIDS(0) #0: first available camera; 1-254: The camera with the specified camera ID self.sInfo = ueye.SENSORINFO() self.cInfo = ueye.CAMINFO() self.pcImageMemory = ueye.c_mem_p() self.MemID = ueye.int() self.rectAOI = ueye.IS_RECT() self.pitch = ueye.INT() self.nBitsPerPixel = ueye.INT(24) #24: bits per pixel for color mode; take 8 bits per pixel for monochrome self.channels = 3 #3: channels for color mode(RGB); take 1 channel for monochrome self.m_nColorMode = ueye.INT() # Y8/RGB16/RGB24/REG32 self.bytes_per_pixel = int(self.nBitsPerPixel / 8) self.exposure = ueye.DOUBLE(10) # 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") # Reads out the data hard-coded in the non-volatile camera memory and writes it to the data structure that cInfo points to nRet = ueye.is_GetCameraInfo(self.hCam, self.cInfo) if nRet != ueye.IS_SUCCESS: print("is_GetCameraInfo ERROR") # You can query additional information about the sensor type used in the camera nRet = ueye.is_GetSensorInfo(self.hCam, self.sInfo) if nRet != ueye.IS_SUCCESS: print("is_GetSensorInfo ERROR") nRet = ueye.is_ResetToDefault(self.hCam) if nRet != ueye.IS_SUCCESS: print("is_ResetToDefault ERROR") # Set display mode to DIB nRet = ueye.is_SetDisplayMode(self.hCam, ueye.IS_SET_DM_DIB) # Set the right color mode if int.from_bytes(self.sInfo.nColorMode.value, byteorder='big') == ueye.IS_COLORMODE_BAYER: # setup the color depth to the current windows setting ueye.is_GetColorDepth(self.hCam, self.nBitsPerPixel, self.m_nColorMode) self.nBitsPerPixel = ueye.INT(32) #------------Added this because it gets changed on linux and that f***s everything up. self.bytes_per_pixel = int(self.nBitsPerPixel / 8) print("IS_COLORMODE_BAYER: ", ) print("\tm_nColorMode: \t\t", self.m_nColorMode) print("\tnBitsPerPixel: \t\t", self.nBitsPerPixel) print("\tbytes_per_pixel: \t\t", self.bytes_per_pixel) print() elif int.from_bytes(self.sInfo.nColorMode.value, byteorder='big') == ueye.IS_COLORMODE_CBYCRY: # for color camera models use RGB32 mode self.m_nColorMode = ueye.IS_CM_BGRA8_PACKED self.nBitsPerPixel = ueye.INT(32) self.bytes_per_pixel = int(self.nBitsPerPixel / 8) print("IS_COLORMODE_CBYCRY: ", ) print("\tm_nColorMode: \t\t", self.m_nColorMode) print("\tnBitsPerPixel: \t\t", self.nBitsPerPixel) print("\tbytes_per_pixel: \t\t", self.bytes_per_pixel) print() elif int.from_bytes(self.sInfo.nColorMode.value, byteorder='big') == ueye.IS_COLORMODE_MONOCHROME: # for color camera models use RGB32 mode self.m_nColorMode = ueye.IS_CM_MONO8 self.nBitsPerPixel = ueye.INT(8) self.bytes_per_pixel = int(self.nBitsPerPixel / 8) print("IS_COLORMODE_MONOCHROME: ", ) print("\tm_nColorMode: \t\t", self.m_nColorMode) print("\tnBitsPerPixel: \t\t", self.nBitsPerPixel) print("\tbytes_per_pixel: \t\t", self.bytes_per_pixel) print() else: # 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("else") nRet = ueye.is_Exposure(self.hCam, ueye.IS_EXPOSURE_CMD_SET_EXPOSURE, self.exposure, ueye.sizeof(self.exposure))#TODO # 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, 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) print() #Allocate image dimensions self.update_image_memory()
def __get_camera_info(self): if not ueye.is_GetCameraInfo(self.cam, self.cam_info) == ueye.IS_SUCCESS: raise RuntimeError("Camera Info not fetched") print("Camera info acquired")
def cameraInit(load_parameters_EEPROM=load_parameters_EEPROM): """Initializes the camera with the correct parameters""" global mBuff, bpp, pitch, channels, bytes_per_pixel, tt hCam = ueye.HIDS(0) # 0: first available camera; 1-254: The camera with the specified camera ID sInfo = ueye.SENSORINFO() cInfo = ueye.CAMINFO() # Starts the driver and establishes the connection to the camera nRet = ueye.is_InitCamera(hCam, None) logger.debug("Setting Camera Data") if nRet != ueye.IS_SUCCESS: logger.info("is_InitCamera ERROR, camera not connected?") return -1, 0 # Reads out the data hard-coded in the non-volatile camera memory and writes it to the data structure that cInfo points to nRet = ueye.is_GetCameraInfo(hCam, cInfo) if nRet != ueye.IS_SUCCESS: logger.info("is_GetCameraInfo ERROR") # You can query additional information about the sensor type used in the camera nRet = ueye.is_GetSensorInfo(hCam, sInfo) if nRet != ueye.IS_SUCCESS: logger.info("is_GetSensorInfo ERROR") nRet = ueye.is_ResetToDefault(hCam) if nRet != ueye.IS_SUCCESS: logger.info("is_ResetToDefault ERROR") # Set display mode to DIB nRet = ueye.is_SetDisplayMode(hCam, ueye.IS_SET_DM_DIB) if int.from_bytes(sInfo.nColorMode.value, byteorder='big') == ueye.IS_COLORMODE_MONOCHROME: # for color camera models use RGB32 mode logger.info("Setting colormode to black and white") m_nColorMode = ueye.IS_CM_MONO8 nBitsPerPixel = ueye.INT(8) bytes_per_pixel = int(nBitsPerPixel / 8) logger.info(f"IS_COLORMODE_MONOCHROME: ") logger.info(f"\tm_nColorMode: \t\t{m_nColorMode}") logger.info(f"\tnBitsPerPixel: \t\t{nBitsPerPixel}") logger.info(f"\tbytes_per_pixel: \t\t {bytes_per_pixel}") if load_parameters_EEPROM: logger.debug("Loading parameters from EEPROM") nullint = ueye._value_cast(0, ueye.ctypes.c_uint) rvv = ueye.is_ParameterSet(hCam, ueye.IS_PARAMETERSET_CMD_LOAD_EEPROM, nullint, nullint) # Can be used to set the size and position of an "area of interest"(AOI) within an image nRet = ueye.is_AOI(hCam, ueye.IS_AOI_IMAGE_GET_AOI, rectAOI, ueye.sizeof(rectAOI)) if nRet != ueye.IS_SUCCESS: logger.error("is_AOI ERROR") width = rectAOI.s32Width height = rectAOI.s32Height # Prints out some information about the camera and the sensor logger.info(f"Camera model:\t\t {sInfo.strSensorName.decode('utf-8')}") logger.info(f"Camera serial no.:\t {cInfo.SerNo.decode('utf-8')}") logger.info(f"Maximum image width:\t {width}") logger.info(f"Maximum image height:\t {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(hCam, width, height, nBitsPerPixel, pcImageMemory, MemID) if nRet != ueye.IS_SUCCESS: logger.info("is_AllocImageMem ERROR") else: # Makes the specified image memory the active memory nRet = ueye.is_SetImageMem(hCam, pcImageMemory, MemID) if nRet != ueye.IS_SUCCESS: logger.info("is_SetImageMem ERROR") else: # Set the desired color mode nRet = ueye.is_SetColorMode(hCam, m_nColorMode) # Activates the camera's live video mode (free run mode) nRet = ueye.is_CaptureVideo(hCam, ueye.IS_DONT_WAIT) if nRet != ueye.IS_SUCCESS: logger.info("is_CaptureVideo ERROR") # Enables the queue mode for existing image memory sequences nRet = ueye.is_InquireImageMem(hCam, pcImageMemory, MemID, width, height, nBitsPerPixel, pitch) if nRet != ueye.IS_SUCCESS: logger.info("is_InquireImageMem ERROR") else: logger.info("Press q to leave the programm") # --------------------------------------------------------------------------------------------------------------------------------------- # shutter = int.from_bytes(sInfo.bGlobShutter.value, byteorder='big') # rvv = ueye.is_ParameterSet(hCam,ueye.IS_PARAMETERSET_CMD_LOAD_EEPROM,nullint,nullint) # Continuous image display tt = ueye.is_AOI(hCam, ueye.IS_AOI_IMAGE_GET_AOI, rect_aoi, ueye.sizeof(rect_aoi)) width = rect_aoi.s32Width.value height = rect_aoi.s32Height.value for i in range(numBuffers): buff = ImageBuffer() ueye.is_AllocImageMem(hCam, width, height, bpp, buff.mem_ptr, buff.mem_id) ueye.is_AddToSequence(hCam, buff.mem_ptr, buff.mem_id) buffs.append(buff) rvIQ = ueye.is_InitImageQueue(hCam, 0) nRet = ueye.IS_SUCCESS ret = ueye.is_WaitForNextImage(hCam, 100, mBuff.mem_ptr, mBuff.mem_id) rr = ueye.is_GetActSeqBuf(hCam, buffCurrent.mem_id, buffLast.mem_ptr, buffLast.mem_ptr) if (not ret): # cnt+=1 array = ueye.get_data(mBuff.mem_ptr, width, height, bpp, pitch, copy=True) ueye.is_UnlockSeqBuf(hCam, mBuff.mem_id, mBuff.mem_ptr) return nRet, hCam
def Cameras_stream(): #Variables hCam1 = ueye.HIDS(1) #0: first available camera; 1-254: The camera with the specified camera ID hCam2 = ueye.HIDS(2) #0: first available camera; 1-254: The camera with the specified camera ID sInfo = ueye.SENSORINFO() cInfo = ueye.CAMINFO() pcImageMemory = ueye.c_mem_p() pcImageMemory2 = ueye.c_mem_p() MemID = ueye.int() MemID2 = ueye.int() rectAOI = ueye.IS_RECT() pitch = ueye.INT() nBitsPerPixel = ueye.INT(24) #24: bits per pixel for color mode; take 8 bits per pixel for monochrome channels = 3 #3: channels for color mode(RGB); take 1 channel for monochrome m_nColorMode = ueye.INT() # Y8/RGB16/RGB24/REG32 bytes_per_pixel = int(nBitsPerPixel / 8) #--------------------------------------------------------------------------------------------------------------------------------------- # print("START") # print() # Starts the driver and establishes the connection to the camera nRet1 = ueye.is_InitCamera(hCam1, None) if nRet1 != ueye.IS_SUCCESS: pass # print("is_InitCamera ERROR") else: print(f'Camera 1 : SUCCESS') nRet2 = ueye.is_InitCamera(hCam2, None) if nRet2 != ueye.IS_SUCCESS: pass # print("is_InitCamera ERROR") else: print(f'Camera 2 : SUCCESS') # Reads out the data hard-coded in the non-volatile camera memory and writes it to the data structure that cInfo points to nRet1 = ueye.is_GetCameraInfo(hCam1, cInfo) if nRet1 != ueye.IS_SUCCESS: print("is_GetCameraInfo ERROR") nRet2 = ueye.is_GetCameraInfo(hCam2, cInfo) if nRet2 != ueye.IS_SUCCESS: print("is_GetCameraInfo ERROR") # You can query additional information about the sensor type used in the camera nRet1 = ueye.is_GetSensorInfo(hCam1, sInfo) if nRet1 != ueye.IS_SUCCESS: print("is_GetSensorInfo ERROR") nRet1 = ueye.is_ResetToDefault( hCam1) if nRet1 != ueye.IS_SUCCESS: print("is_ResetToDefault ERROR") # Set display mode to DIB nRet1 = ueye.is_SetDisplayMode(hCam1, ueye.IS_SET_DM_DIB) nRet2 = ueye.is_SetDisplayMode(hCam2, ueye.IS_SET_DM_DIB) # Set the right color mode if int.from_bytes(sInfo.nColorMode.value, byteorder='big') == ueye.IS_COLORMODE_BAYER: # setup the color depth to the current windows setting ueye.is_GetColorDepth(hCam1, nBitsPerPixel, m_nColorMode) bytes_per_pixel = int(nBitsPerPixel / 8) print("IS_COLORMODE_BAYER: ", ) print("\tm_nColorMode: \t\t", m_nColorMode) print("\tnBitsPerPixel: \t\t", nBitsPerPixel) print("\tbytes_per_pixel: \t\t", bytes_per_pixel) print() elif int.from_bytes(sInfo.nColorMode.value, byteorder='big') == ueye.IS_COLORMODE_CBYCRY: # for color camera models use RGB32 mode m_nColorMode = ueye.IS_CM_BGRA8_PACKED nBitsPerPixel = ueye.INT(32) bytes_per_pixel = int(nBitsPerPixel / 8) print("IS_COLORMODE_CBYCRY: ", ) print("\tm_nColorMode: \t\t", m_nColorMode) print("\tnBitsPerPixel: \t\t", nBitsPerPixel) print("\tbytes_per_pixel: \t\t", bytes_per_pixel) print() elif int.from_bytes(sInfo.nColorMode.value, byteorder='big') == ueye.IS_COLORMODE_MONOCHROME: # for color camera models use RGB32 mode m_nColorMode = ueye.IS_CM_MONO8 nBitsPerPixel = ueye.INT(8) bytes_per_pixel = int(nBitsPerPixel / 8) print("IS_COLORMODE_MONOCHROME: ", ) print("\tm_nColorMode: \t\t", m_nColorMode) print("\tnBitsPerPixel: \t\t", nBitsPerPixel) print("\tbytes_per_pixel: \t\t", bytes_per_pixel) print() else: # for monochrome camera models use Y8 mode m_nColorMode = ueye.IS_CM_MONO8 nBitsPerPixel = ueye.INT(8) bytes_per_pixel = int(nBitsPerPixel / 8) print("else") # Can be used to set the size and position of an "area of interest"(AOI) within an image nRet1 = ueye.is_AOI(hCam1, ueye.IS_AOI_IMAGE_GET_AOI, rectAOI, ueye.sizeof(rectAOI)) if nRet1 != ueye.IS_SUCCESS: print("is_AOI ERROR") width = rectAOI.s32Width height = rectAOI.s32Height # Prints out some information about the camera and the sensor print("Camera model:\t\t", sInfo.strSensorName.decode('utf-8')) print("Camera serial no.:\t", cInfo.SerNo.decode('utf-8')) print("Maximum image width:\t", width) print("Maximum image height:\t", height) print() #--------------------------------------------------------------------------------------------------------------------------------------- # Allocates an image memory for an image having its dimensions defined by width and height and its color depth defined by nBitsPerPixel nRet1 = ueye.is_AllocImageMem(hCam1, width, height, nBitsPerPixel, pcImageMemory, MemID) if nRet1 != ueye.IS_SUCCESS: print("is_AllocImageMem ERROR") else: # Makes the specified image memory the active memory nRet = ueye.is_SetImageMem(hCam1, pcImageMemory, MemID) if nRet != ueye.IS_SUCCESS: print("is_SetImageMem ERROR") else: # Set the desired color mode nRet = ueye.is_SetColorMode(hCam1, m_nColorMode) if nRet1 != ueye.IS_SUCCESS: print("is_AllocImageMem ERROR") else: # Makes the specified image memory the active memory nRet = ueye.is_SetImageMem(hCam1, pcImageMemory, MemID) if nRet != ueye.IS_SUCCESS: print("is_SetImageMem ERROR") else: # Set the desired color mode nRet = ueye.is_SetColorMode(hCam2, m_nColorMode) # 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(hCam2, width, height, nBitsPerPixel, pcImageMemory2, MemID2) if nRet != ueye.IS_SUCCESS: print("is_AllocImageMem ERROR") else: # Makes the specified image memory the active memory nRet = ueye.is_SetImageMem(hCam2, pcImageMemory2, MemID2) if nRet != ueye.IS_SUCCESS: print("is_SetImageMem ERROR") else: # Set the desired color mode nRet = ueye.is_SetColorMode(hCam2, m_nColorMode) nRet = ueye.is_AllocImageMem(hCam2, width, height, nBitsPerPixel, pcImageMemory2, MemID2) if nRet != ueye.IS_SUCCESS: print("is_AllocImageMem ERROR") else: # Makes the specified image memory the active memory nRet = ueye.is_SetImageMem(hCam2, pcImageMemory2, MemID2) if nRet != ueye.IS_SUCCESS: print("is_SetImageMem ERROR") else: # Set the desired color mode nRet = ueye.is_SetColorMode(hCam2, m_nColorMode) # Activates the camera's live video mode (free run mode) nRet = ueye.is_CaptureVideo(hCam1, ueye.IS_DONT_WAIT) if nRet != ueye.IS_SUCCESS: print("is_CaptureVideo ERROR") nRet = ueye.is_CaptureVideo(hCam2, ueye.IS_DONT_WAIT) if nRet != ueye.IS_SUCCESS: print("is_CaptureVideo ERROR") # Enables the queue mode for existing image memory sequences nRet = ueye.is_InquireImageMem(hCam1, pcImageMemory, MemID, width, height, nBitsPerPixel, pitch) if nRet != ueye.IS_SUCCESS: print("is_InquireImageMem ERROR") else: print("Press q to leave the programm") nRet2 = ueye.is_InquireImageMem(hCam2, pcImageMemory2, MemID, width, height, nBitsPerPixel, pitch) if nRet2 != ueye.IS_SUCCESS: print("is_InquireImageMem ERROR") else: print("Press q to leave the programm") #--------------------------------------------------------------------------------------------------------------------------------------- # Continuous image display while(nRet == ueye.IS_SUCCESS) and (nRet2 == 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) array2 = ueye.get_data(pcImageMemory2, 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)) frame2 = np.reshape(array2,(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) #--------------------------------------------------------------------------------------------------------------------------------------- #Include image data processing here #--------------------------------------------------------------------------------------------------------------------------------------- #...and finally display it if __name__=="__main__": cv2.imshow("SimpleLive_Python_uEye_OpenCV", frame) cv2.imshow("SimpleLive_Python_uEye_OpenCV 2", frame2) # 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(hCam1, pcImageMemory, MemID) ueye.is_FreeImageMem(hCam2, pcImageMemory2, MemID2) # Disables the hCam camera handle and releases the data structures and memory areas taken up by the uEye camera ueye.is_ExitCamera(hCam1) ueye.is_ExitCamera(hCam2) # Destroys the OpenCv windows cv2.destroyAllWindows() print() print("END")
def open_connection(self, camID): """ Function taking care of the Thorlabs camera initialization. Parameters ---------- camID : int - indicate the handle of the camera we want to intialize. """ # Starts the driver and establishes the connection to the camera # -------------------------------------------------------------- self.hcam = ueye.HIDS(camID) Init = ueye.is_InitCamera(self.hcam, None) if Init != ueye.IS_SUCCESS: print( "is_InitCamera ERROR - make sure the camera is properly connected" ) self.cam_initialized.emit('') return # Reads out the data hard-coded in the non-volatile camera memory and # writes it to the data structure that cInfo points to # ---------------------------------------------------- read_cam_info = ueye.is_GetCameraInfo(self.hcam, self.cam_info) if read_cam_info != ueye.IS_SUCCESS: print("is_GetCameraInfo ERROR") self.cam_initialized.emit('') return # You can query additional information about the sensor type used in # the camera # ---------- read_sensor_info = ueye.is_GetSensorInfo(self.hcam, self.sensor_info) if read_sensor_info != ueye.IS_SUCCESS: print("is_GetSensorInfo ERROR") self.cam_initialized.emit('') return # Reset buffer and all the display parameters to the default values # ----------------------------------------------------------------- reset = ueye.is_ResetToDefault(self.hcam) if reset != ueye.IS_SUCCESS: print("is_ResetToDefault ERROR") self.cam_initialized.emit('') return # Set display mode to DIB - the image is directly saved on the RAM # ---------------------------------------------------------------- ueye.is_SetDisplayMode(self.hcam, ueye.IS_SET_DM_DIB) # Set the color mode according to the sensor properties # ----------------------------------------------------- if int.from_bytes(self.sensor_info.nColorMode.value, byteorder='big') == ueye.IS_COLORMODE_CBYCRY: # for color camera models use RGB32 mode self.m_nColorMode = ueye.IS_CM_BGRA8_PACKED self.nBitsPerPixel = ueye.INT(32) self.bytes_per_pixel = int(self.nBitsPerPixel / 8) self.color_mode = 'RGB' elif int.from_bytes(self.sensor_info.nColorMode.value, byteorder='big') == ueye.IS_COLORMODE_MONOCHROME: # for color camera models use RGB32 mode self.m_nColorMode = ueye.IS_CM_MONO8 self.nBitsPerPixel = ueye.INT(8) self.bytes_per_pixel = int(self.nBitsPerPixel / 8) self.color_mode = 'Monochrome' else: print('Error : the camera type is unknown.') self.cam_initialized.emit('') return # Define a dictionary with the main properties of the camera selected # ------------------------------------------------------------------- ueye.is_AOI(self.hcam, ueye.IS_AOI_IMAGE_GET_AOI, self.rectAOI, ueye.sizeof(self.rectAOI)) self.Properties = { 'Camera sensor model (from IDS)': self.sensor_info.strSensorName.decode('utf-8'), 'Camera s/n': self.cam_info.SerNo.decode('utf-8'), 'Color mode': self.color_mode, 'Image width': int(self.rectAOI.s32Width), 'Image height': int(self.rectAOI.s32Height), } # Indicate that the initialization procedure was completed # -------------------------------------------------------- print('Success : Thorlabs camera was found and initialized') self.cam_initialized.emit(self.Properties['Camera s/n'])