def alloc(self): """ Allocate memory for futur images. """ rect = self.get_aoi() bpp = self.nBitsPerPixel for buff in self.img_buffer: self.nRet = ueye.is_FreeImageMem(self.cam, buff.mem_ptr, buff.mem_id) if self.nRet != ueye.IS_SUCCESS: error_log(self.nRet, "is_FreeImageMem") self.img_buffer = [] for i in range(self.buffer_count): buff = ImageBuffer() ueye.is_AllocImageMem(self.cam, rect.width, rect.height, bpp, buff.mem_ptr, buff.mem_id) ueye.is_AddToSequence(self.cam, buff.mem_ptr, buff.mem_id) self.img_buffer.append(buff) self.nRet = ueye.is_InitImageQueue(self.cam, 0) if self.nRet != ueye.IS_SUCCESS: error_log(self.nRet, "is_InitImageQueue")
def setBuffer(self, size): self.bufCount=size if self.Imgs is not None: for i in range(self.bufCount): rv=ueye.is_FreeImageMem (self.hcam, self.Imgs[i], self.bufIds[i]) if rv: self.status=True return True self.bufIds[i] = 0 if self.getAOI(): self.status=True return True self.imgWidth=self.AOI.s32Width.value self.imgHeight=self.AOI.s32Height.value self.Imgs=[ueye.c_mem_p() for i in range(size)] self.bufIds=[ueye.c_int() for i in range(size)] for i in range(self.bufCount): rv=ueye.is_AllocImageMem(self.hcam, self.imgWidth, self.imgHeight,self.bitsPixel, self.Imgs[i], self.bufIds[i]) if rv: self.status=True return True rv=ueye.is_AddToSequence (self.hcam, self.Imgs[i], self.bufIds[i]) if rv: self.status=True return True self.LineInc=ueye.c_int() rv=ueye.is_GetImageMemPitch (self.hcam, self.LineInc) if rv: self.status=True return True return False
def alloc(self, buffer_count=3): ''' Initialization of the ring buffer. ''' rec_aoi = self.Rect(*self.get_aoi()) color_mode = ueye.is_SetColorMode(self.cam, ueye.IS_GET_COLOR_MODE) self.bpp = get_bits_per_pixel(color_mode) # --- freeing the memory from previous buffer --- # for buff in self.frame_buffer: hasWorked = ueye.is_FreeImageMem(self.cam, buff.mem_ptr, buff.mem_id) self.check(hasWorked, 'is_FreeImageMem') # --- allocate memory to buffer --- # for i in range(buffer_count): buff = self.ImageBuffer() ueye.is_AllocImageMem(self.cam, rec_aoi.width, rec_aoi.height, self.bpp, buff.mem_ptr, buff.mem_id) hasWorked = ueye.is_AddToSequence(self.cam, buff.mem_ptr, buff.mem_id) self.check(hasWorked, 'is_AddToSequence') self.frame_buffer.append(buff) # --- --- # hasWorked = ueye.is_InitImageQueue( self.cam, 0) # init and return the success of image queued. self.check(hasWorked, 'is_InitImageQueue') # --- --- # self.img_buffer = self.frame_buffer[-1]
def alloc(self, buffer_count=3): rect = self.get_aoi() bpp = get_bits_per_pixel(self.get_colormode()) for buff in self.img_buffers: check(ueye.is_FreeImageMem(self.h_cam, buff.mem_ptr, buff.mem_id)) for i in range(buffer_count): buff = ImageBuffer() ueye.is_AllocImageMem(self.h_cam, rect.width, rect.height, bpp, buff.mem_ptr, buff.mem_id) check(ueye.is_AddToSequence(self.h_cam, buff.mem_ptr, buff.mem_id)) self.img_buffers.append(buff) ueye.is_InitImageQueue(self.h_cam, 0)
def alloc(self): """ Allocate memory for futur images. """ # Get camera settings rect = self.get_aoi() bpp = get_bits_per_pixel(self.get_colormode()) # Check that already existing buffers are free for buff in self.img_buffers: check(ueye.is_FreeImageMem(self.h_cam, buff.mem_ptr, buff.mem_id)) self.img_buffers = [] # Create asked buffers for i in range(self.buffer_count): buff = ImageBuffer() ueye.is_AllocImageMem(self.h_cam, rect.width, rect.height, bpp, buff.mem_ptr, buff.mem_id) check(ueye.is_AddToSequence(self.h_cam, buff.mem_ptr, buff.mem_id)) self.img_buffers.append(buff) # Check that ... ueye.is_InitImageQueue(self.h_cam, 0)
def InitBuffers(self, n_buffers=50, n_accum_buffers=50): for ind in range(n_buffers): data = ueye.c_mem_p() buffer_id = ueye.int() if self.nbits == 8: bitsperpix = 8 bufferdtype = np.uint8 else: # 10 & 12 bits bitsperpix = 16 bufferdtype = np.uint16 self.check_success( ueye.is_AllocImageMem(self.h, self.GetPicWidth(), self.GetPicHeight(), bitsperpix, data, buffer_id)) self.check_success(ueye.is_AddToSequence(self.h, data, buffer_id)) self._buffers.append((buffer_id, data)) # IDS currently only supports nMode = 0 self.check_success(ueye.is_InitImageQueue(self.h, 0)) self.transfer_buffer = np.zeros( [self.GetPicHeight(), self.GetPicWidth()], bufferdtype) self.free_buffers = queue.Queue() # CS: we leave this as uint16 regardless of 8 or 12 bits for now as accumulation # of the underlying 12 bit data should be ok (but maybe not?) for ind in range(n_accum_buffers): self.free_buffers.put( np.zeros([self.GetPicHeight(), self.GetPicWidth()], np.uint16)) self.accum_buffer = self.free_buffers.get() self.n_accum_current = 0 self._poll = True
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