def possible_pixelclock(self): """Query the possible values for pixelclock (in MHz) """ nPixelclocks = ueye.UINT() nRet = ueye.is_PixelClock( self.hCam, ueye.IS_PIXELCLOCK_CMD_GET_NUMBER, nPixelclocks, ctypes.sizeof(nPixelclocks), ) if nRet != ueye.IS_SUCCESS: raise RuntimeError("IS_PIXELCLOCK_CMD_GET_NUMBER failed") if nPixelclocks.value == 0: return [] pixelclock_list = (ueye.UINT * nPixelclocks.value)() nRet = ueye.is_PixelClock( self.hCam, ueye.IS_PIXELCLOCK_CMD_GET_LIST, pixelclock_list, ctypes.sizeof(pixelclock_list), ) if nRet != ueye.IS_SUCCESS: raise RuntimeError("IS_PIXELCLOCK_CMD_GET_LIST failed") return [pc.value for pc in pixelclock_list]
def set_pixelclock(self, pixelclock): """ Get the current pixelclock. Returns ======= pixelclock: number Current pixelclock. """ PCrange = (ctypes.c_uint * 3)() self.nRet = ueye.is_PixelClock(self.cam, ueye.IS_PIXELCLOCK_CMD_GET_RANGE, PCrange, 12) if self.nRet != ueye.IS_SUCCESS: error_log(self.nRet, "is_PixelClock") pcmin, pcmax, pcincr = PCrange if pixelclock < pcmin: pixelclock = pcmin print(f"Pixelclock out of range [{pcmin}, {pcmax}] and set " f"to {pcmin}") elif pixelclock > pcmax: pixelclock = pcmax print(f"Pixelclock out of range [{pcmin}, {pcmax}] and set " f"to {pcmax}") pixelclock = ueye.c_uint(pixelclock) self.nRet = ueye.is_PixelClock(self.cam, ueye.IS_PIXELCLOCK_CMD_SET, pixelclock, 4) if self.nRet != ueye.IS_SUCCESS: error_log(self.nRet, "is_PixelClock")
def set_pixelclock(self, pixelclock): """ Set the current pixelclock. Params ======= pixelclock: number Current pixelclock. """ # Warning print('Warning: when changing pixelclock at runtime, you may need to ' 'update the fps and exposure parameters') # get pixelclock range pcrange = (ueye.c_uint * 3)() check( ueye.is_PixelClock(self.h_cam, ueye.IS_PIXELCLOCK_CMD_GET_RANGE, pcrange, 12)) pcmin, pcmax, pcincr = pcrange if pixelclock < pcmin: pixelclock = pcmin print(f"Pixelclock out of range [{pcmin}, {pcmax}] and set " f"to {pcmin}") elif pixelclock > pcmax: pixelclock = pcmax print(f"Pixelclock out of range [{pcmin}, {pcmax}] and set " f"to {pcmax}") # Set pixelclock pixelclock = ueye.c_uint(pixelclock) check( ueye.is_PixelClock(self.h_cam, ueye.IS_PIXELCLOCK_CMD_SET, pixelclock, 4))
def initialize_camera_settings(self): '''Sets pixel_clock, fps, exposure, autofocus, autogain based on self.config.''' # get max pixel clock pixel_clock_range = (ueye.c_uint * 3)() ret = ueye.is_PixelClock(self.input, ueye.IS_PIXELCLOCK_CMD_GET_RANGE, pixel_clock_range, 3 * ueye.sizeof(ueye.UINT())) log.info(f'pixel_clock max: {pixel_clock_range[0]}, pixel_clock min: {pixel_clock_range[1]}, ret val: {ret}') # set max pixel clock pixel_clock = ueye.c_int(pixel_clock_range[1]) ret = ueye.is_PixelClock(self.input, ueye.IS_PIXELCLOCK_CMD_SET, pixel_clock, ueye.sizeof(pixel_clock)) self.config['pixel_clock'] = pixel_clock.value log.info(f'Actual pixel clock: {pixel_clock}, ret val: {ret}') # max out frame rate target_frame_rate = ueye.double(self.config.get('fps')) actual_frame_rate = ueye.double(0.0) ret = ueye.is_SetFrameRate(self.input, target_frame_rate, actual_frame_rate) self.config['fps'] = actual_frame_rate.value log.info(f'Attempted to set frame rate to {target_frame_rate}, ret value: {ret}, actual frame rate: {actual_frame_rate}') # max out exposure target_exposure = ueye.double(self.config.get('exposure')) actual_exposure = ueye.double(0.0) ret = ueye.is_Exposure(self.input, ueye.IS_EXPOSURE_CMD_SET_EXPOSURE, target_exposure, ueye.sizeof(target_exposure)) get_ret = ueye.is_Exposure(self.input, ueye.IS_EXPOSURE_CMD_GET_EXPOSURE, actual_exposure, ueye.sizeof(actual_exposure)) self.config['exposure'] = actual_exposure.value log.info(f'Attempted to set exposure to {target_exposure}, ret value: {ret}, actual frame rate: {actual_exposure}') # set autofocus limits if self.config.get('focus_min') is not None and self.config.get('focus_max') is not None: limit = ueye.AUTOFOCUS_LIMIT() limit.sMin = ueye.c_int(self.config['focus_min']) limit.sMax = ueye.c_int(self.config['focus_max']) ret = ueye.is_Focus(self.input, ueye.FOC_CMD_SET_AUTOFOCUS_LIMIT, limit, ueye.sizeof(limit)); if ret == ueye.IS_SUCCESS: log.info(f'Successfully set focus min: {self.config["focus_min"]}, focus max: {self.config["focus_max"]}') else: log.error('Failed to set focus min/max.') # enable autofocus if self.config.get('autofocus'): ret = ueye.is_Focus(self.input, ueye.FOC_CMD_SET_ENABLE_AUTOFOCUS, None, 0) if ret == ueye.IS_SUCCESS: log.info(f'Successfully set autofocus to {self.config.get("autofocus")}.') else: log.error('Failed to set autofocus.') # enable autogain if self.config.get('autogain'): ret = ueye.is_SetAutoParameter(self.input, ueye.IS_SET_ENABLE_AUTO_GAIN, ueye.double(1), ueye.double(0)) if ret == ueye.IS_SUCCESS: log.info(f'Successfully set autogain to {self.config.get("autogain")}.') else: log.error('Failed to set autogain.')
def connect(self): """ Connects to the USB camera, creates main controlling object + prints out confirmation """ connectRet = ueye.is_InitCamera(self.CamID, None) if connectRet == 0: # on succesful connection self.connected = True self.sensorInfo = ueye.SENSORINFO() print('IDS camera connected.') ueye.is_GetSensorInfo(self.CamID, self.sensorInfo) self.sensorHeight_ctype, self.sensorWidth_ctype = self.sensorInfo.nMaxHeight, self.sensorInfo.nMaxWidth self.currentHeight, self.currentWidth = self.sensorHeight_ctype.value, self.sensorWidth_ctype.value # Settings block ueye.is_PixelClock(self.CamID, ueye.IS_PIXELCLOCK_CMD_SET, ueye.c_int(self.pixelClock), ueye.sizeof(ueye.c_int(self.pixelClock))) self.currentFPS = ueye.c_double(0) #ueye.is_SetFrameRate(self.CamID, ueye.c_int(self.FPS),self.currentFPS) ueye.is_SetDisplayMode(self.CamID, ueye.IS_SET_DM_DIB) ueye.is_SetColorMode(self.CamID, ueye.IS_CM_SENSOR_RAW12) ueye.is_SetAutoParameter(self.CamID, ueye.IS_SET_ENABLE_AUTO_GAIN, ueye.c_double(0), ueye.c_double(0)) ueye.is_SetAutoParameter(self.CamID, ueye.IS_SET_ENABLE_AUTO_SENSOR_GAIN, ueye.c_double(0), ueye.c_double(0)) ueye.is_SetAutoParameter(self.CamID, ueye.IS_SET_ENABLE_AUTO_SHUTTER, ueye.c_double(0), ueye.c_double(0)) ueye.is_SetAutoParameter(self.CamID, ueye.IS_SET_ENABLE_AUTO_SENSOR_SHUTTER, ueye.c_double(0), ueye.c_double(0)) ueye.is_SetAutoParameter(self.CamID, ueye.IS_SET_ENABLE_AUTO_WHITEBALANCE, ueye.c_double(0), ueye.c_double(0)) ueye.is_SetAutoParameter( self.CamID, ueye.IS_SET_ENABLE_AUTO_SENSOR_WHITEBALANCE, ueye.c_double(0), ueye.c_double(0)) ueye.is_SetHardwareGain(self.CamID, ueye.c_int(0), ueye.c_int(0), ueye.c_int(0), ueye.c_int(0)) # Show a pattern (for testing) #ueye.is_SetSensorTestImage(self.CamID,ueye.IS_TEST_IMAGE_HORIZONTAL_GREYSCALE, ueye.c_int(0)) else: print('Camera connecting failure...')
def getPixelClock(self): self.pixelClock=ueye.c_uint() if ueye.is_PixelClock(self.hcam, ueye.IS_PIXELCLOCK_CMD_GET, self.pixelClock, ueye.sizeof(ueye.c_uint)): self.status=True _logger.error("Error retrinving PixelClock") return True return False
def getPixelClockRange(self): self.PixelClockRange=[ueye.c_uint() for i in range(3)] self.PixelClockRange=(ueye.c_uint*3)(*self.PixelClockRange) if ueye.is_PixelClock(self.hcam, ueye.IS_PIXELCLOCK_CMD_GET_RANGE, self.PixelClockRange, ueye.sizeof(self.PixelClockRange)): _logger.error("Error retrinving pixelclock range") self.status=True return True
def get_pixel_clock(self, verbose=False): ret = ueye.UINT() check( ueye.is_PixelClock(self.h_cam, ueye.IS_PIXELCLOCK_CMD_GET, ret, ueye.sizeof(ret))) if verbose: print('Pixel clock: {}'.format(str(ret))) return ret
def set_full_auto(self): print("full auto") disable = ueye.DOUBLE(0) enable = ueye.DOUBLE(1) zero = ueye.DOUBLE(0) ms = ueye.DOUBLE(20) rate = ueye.DOUBLE(50) newrate = ueye.DOUBLE() number = ueye.UINT() nRet = ueye.is_SetAutoParameter(self.h_cam, ueye.IS_SET_ENABLE_AUTO_GAIN, enable, zero); print('AG:',nRet) nRet = ueye.is_SetAutoParameter(self.h_cam, ueye.IS_SET_ENABLE_AUTO_SHUTTER, enable, zero); print('A_SHUTTER:',nRet) nRet = ueye.is_SetFrameRate(self.h_cam, rate, newrate); print('FR:',nRet,newrate) nRet = ueye.is_Exposure(self.h_cam, ueye.IS_EXPOSURE_CMD_GET_EXPOSURE, ms, ueye.sizeof(ms)); print('EXP:',nRet,ms) nRet = ueye.is_PixelClock(self.h_cam, ueye.IS_PIXELCLOCK_CMD_GET_NUMBER, number, ueye.sizeof(number)) print('PxCLK #:',nRet, number) PCrange = (ctypes.c_uint * 3)() nRet = ueye.is_PixelClock(self.h_cam, ueye.IS_PIXELCLOCK_CMD_GET_RANGE, PCrange, 3*ueye.sizeof(number)) print('PxCLK range:', nRet, PCrange[0], PCrange[1], PCrange[2]) list_pixel_clocks = (ctypes.c_uint * 150)() nRet = ueye.is_PixelClock(self.h_cam, ueye.IS_PIXELCLOCK_CMD_GET_LIST, list_pixel_clocks, number*ueye.sizeof(number)) list_np = np.frombuffer(list_pixel_clocks, int) print('PxCLK list:', nRet, list_np[0:number.value]) nRet = ueye.is_PixelClock(self.h_cam, ueye.IS_PIXELCLOCK_CMD_GET, number, ueye.sizeof(number)) print('PxCLK current:',nRet, number) nRet = ueye.is_PixelClock(self.h_cam, ueye.IS_PIXELCLOCK_CMD_GET_DEFAULT, number, ueye.sizeof(number)) print('PxCLK default:',nRet, number) nRet = ueye.is_PixelClock(self.h_cam, ueye.IS_PIXELCLOCK_CMD_SET, ueye.UINT(20), ueye.sizeof(number)) print('PxCLK set:',nRet, number) nRet = ueye.is_PixelClock(self.h_cam, ueye.IS_PIXELCLOCK_CMD_GET, number, ueye.sizeof(number)) print('PxCLK current:',nRet, number)
def set_pixelclock(self, pixelclock): """Set the pixelclock (in MHz) """ pc = ueye.UINT(int(pixelclock)) nRet = ueye.is_PixelClock(self.hCam, ueye.IS_PIXELCLOCK_CMD_SET, pc, ctypes.sizeof(pc)) if nRet != ueye.IS_SUCCESS: raise RuntimeError("IS_PIXELCLOCK_CMD_SET failed") return pc.value
def current_pixelclock(self): """Queries the current pixelclock (in MHz) """ pc = ueye.UINT() nRet = ueye.is_PixelClock(self.hCam, ueye.IS_PIXELCLOCK_CMD_GET, pc, ctypes.sizeof(pc)) if nRet != ueye.IS_SUCCESS: raise RuntimeError("IS_PIXELCLOCK_CMD_GET failed") return pc.value
def get_pixel_clock_range(self, verbose=False): ret = (ueye.UINT * 3)() check( ueye.is_PixelClock(self.h_cam, ueye.IS_PIXELCLOCK_CMD_GET_RANGE, ret, ueye.sizeof(ret))) if verbose: print('Pixel clock range: min={}, max={}, step={}'.format( str(ret[0].value), str(ret[1].value), str(ret[2].value))) return ret
def set_pixel_clock(self, pixel_clock): pc = ueye.UINT(int(pixel_clock)) if not ueye.is_PixelClock(self.cam, ueye.IS_PIXELCLOCK_CMD_SET, pc, ueye.ctypes.sizeof(pc)) == ueye.IS_SUCCESS: raise RuntimeError("Pixel Clock not set") print("Pixel clock set") return pc.value
def getPixelClock(self): """ return (0<int): the pixel clock in MHz """ pc = ctypes.c_uint32() hasWorked = ueye.is_PixelClock(self.cam, ueye.IS_PIXELCLOCK_CMD_GET, pc, ctypes.sizeof(pc)) self.check(hasWorked, 'getPixelClock') return pc.value
def set_pixelclock(self, freq=20): ''' set pixelclock in MHz param freq: pixelclock in MHz ''' mhz = ueye.UINT(freq) ret = ueye.is_PixelClock(self.h_cam, ueye.IS_PIXELCLOCK_CMD_SET, mhz, ueye.sizeof(mhz)) if ret: raise Exception('Set pixelclock failed')
def get_pixelclock(self): ''' returns pixelclock in MHz ''' mhz = ueye.UINT(22) ret = ueye.is_PixelClock(self.h_cam, ueye.IS_PIXELCLOCK_CMD_GET, mhz, ueye.sizeof(mhz)) if ret: raise Exception('Get pixelclock failed') return mhz.value
def setPixelClock(self, value): self.getPixelClockRange() if (value<self.PixelClockRange[0].value) & (value>self.PixelClockRange[1].value): self.status=True return True ran=np.arange(self.PixelClockRange[0].value, self.PixelClockRange[1].value, self.PixelClockRange[2].value) nwv=ueye.c_uint(ran[np.abs(ran-value).argmin()]) if ueye.is_PixelClock(self.hcam, ueye.IS_PIXELCLOCK_CMD_SET, nwv, ueye.sizeof(nwv)): self.status=True return True return False
def get_pixelclock(self): """ Get the current pixelclock. Returns ======= pixelclock: number Current pixelclock. """ pixelclock = ueye.c_uint() check(ueye.is_PixelClock(self.h_cam, ueye.IS_PIXELCLOCK_CMD_GET, pixelclock, 4)) return pixelclock
def set_pixel_clock(self, pixel_clock): """ Set the pixel clock in MHz. :param pixel_clock: pixel clock to be set :return: actual pixel clock """ pc = ueye.UINT(int(pixel_clock)) if not ueye.is_PixelClock(self.cam, ueye.IS_PIXELCLOCK_CMD_SET, pc, ueye.ctypes.sizeof(pc)) == ueye.IS_SUCCESS: raise RuntimeError("Pixel Clock not set") print("Pixel clock set to", pc.value, "MHz") return pc.value
def Camera_Initialization(self): self.hcam = ueye.HIDS(0) self.ret = ueye.is_InitCamera(self.hcam, None) self.ret = ueye.is_SetColorMode(self.hcam, ueye.IS_CM_MONO12) self.IDS_FPS = float(50) self.newrate = ueye.DOUBLE(self.IDS_FPS) self.rate = ueye.DOUBLE(self.IDS_FPS) self.IDS_exposure = float(20) self.width = 2056 self.height = 1542 self.rect_aoi = ueye.IS_RECT() self.rect_aoi.s32X = ueye.int(0) self.rect_aoi.s32Y = ueye.int(0) self.rect_aoi.s32Width = ueye.int(self.width) self.rect_aoi.s32Height = ueye.int(self.height) ueye.is_AOI(self.hcam, ueye.IS_AOI_IMAGE_SET_AOI, self.rect_aoi, ueye.sizeof(self.rect_aoi)) self.mem_ptr = ueye.c_mem_p() self.mem_id = ueye.int() self.bitspixel = 16 self.ret = ueye.is_AllocImageMem(self.hcam, self.width, self.height, self.bitspixel, self.mem_ptr, self.mem_id) self.ret = ueye.is_SetImageMem(self.hcam, self.mem_ptr, self.mem_id) self.ret = ueye.is_CaptureVideo(self.hcam, ueye.IS_DONT_WAIT) #self.lineinc = self.width * int((self.bitspixel + 7) / 8) self.lineinc = self.width * int(self.bitspixel / 8) self.nRet = ueye.is_SetFrameRate(self.hcam, self.rate, self.newrate) self.expms = ueye.DOUBLE(self.IDS_exposure) self.nRet = ueye.is_Exposure(self.hcam, ueye.IS_EXPOSURE_CMD_SET_EXPOSURE, self.expms, ueye.sizeof(self.expms)) self.pixelclock = ueye.c_uint(197) self.nRet = ueye.is_PixelClock(self.hcam, ueye.IS_PIXELCLOCK_CMD_SET, self.pixelclock, 4) #pixelclock = ueye.c_uint() #ueye.is_PixelClock(hcam, ueye.IS_PIXELCLOCK_CMD_GET, pixelclock, 4) self.nRet = ueye.is_SetHardwareGain(self.hcam, 100, ueye.IS_IGNORE_PARAMETER, ueye.IS_IGNORE_PARAMETER, ueye.IS_IGNORE_PARAMETER) #gg = ueye.c_uint() #ueye.is_SetHWGainFactor(hcam, ueye.IS_GET_MASTER_GAIN_FACTOR, gg) self.nRet = ueye.is_SetHardwareGamma(self.hcam, ueye.IS_SET_HW_GAMMA_ON)
def get_pixelclock(self): """ Get the current pixelclock. Returns ======= pixelclock: number Current pixelclock. """ pixelclock = ueye.c_uint() self.nRet = ueye.is_PixelClock(self.cam, ueye.IS_PIXELCLOCK_CMD_GET, pixelclock, 4) if self.nRet != ueye.IS_SUCCESS: error_log(self.nRet, "is_PixelClock") return pixelclock
def setExpoureTime(self, expTime): #Pixel-Clock Setting, the range of this camera is 7-35 MHz nPixelClockDefault = ueye.INT(200) nRet = ueye.is_PixelClock(self.hCam, ueye.IS_PIXELCLOCK_CMD_SET, nPixelClockDefault, ueye.sizeof(nPixelClockDefault)) print(nPixelClockDefault) if nRet != ueye.IS_SUCCESS: print("is_PixelClock ERROR") nFrameRate = ueye.double(40.0) nRet = ueye.is_SetFrameRate(self.hCam, ueye.IS_PIXELCLOCK_CMD_SET, nFrameRate) if nRet != ueye.IS_SUCCESS: print("is_SetFrameRate ERROR") # Working on exposure time range. Set exposure time to be 20 ms. ms = ueye.DOUBLE(expTime) nRet = ueye.is_Exposure(self.hCam, ueye.IS_EXPOSURE_CMD_SET_EXPOSURE, ms, ueye.sizeof(ms)) if nRet != ueye.IS_SUCCESS: print("is_Exposure ERROR")
def set_pixel_clock(self, clock): val = ueye.UINT(clock) check( ueye.is_PixelClock(self.h_cam, ueye.IS_PIXELCLOCK_CMD_SET, val, ueye.sizeof(val)))
def setPixelClock(self, pxl_clck): val_formated = ctypes.c_uint32(pxl_clck) hasWorked = ueye.is_PixelClock(self.cam, ueye.IS_PIXELCLOCK_CMD_SET, val_formated, ctypes.sizeof(val_formated)) self.check(hasWorked, 'setPixelClock')
def UEye420_Snapper(Exposure, Gain, File_Location, pixel_clock): from pyueye import ueye import ctypes import time saved = False while saved == False: #CCD Settings and Start-Up hcam = ueye.HIDS(0) pccmem = ueye.c_mem_p() memID = ueye.c_int() hWnd = ctypes.c_voidp() ueye.is_InitCamera(hcam, hWnd) ueye.is_SetDisplayMode(hcam, 0) sensorinfo = ueye.SENSORINFO() ueye.is_GetSensorInfo(hcam, sensorinfo) ueye.is_AllocImageMem(hcam, sensorinfo.nMaxWidth, sensorinfo.nMaxHeight, 24, pccmem, memID) ueye.is_SetImageMem(hcam, pccmem, memID) ueye.is_SetDisplayPos(hcam, 100, 100) PIXELCLOCK_CMD_SET = 6 PIXELCLOCK_CMD_GET = 4 pixel = ctypes.c_uint(pixel_clock) ueye.is_PixelClock(hcam, PIXELCLOCK_CMD_SET, pixel, ctypes.sizeof(pixel)) print('PX=', pixel) exposure_time = ctypes.c_double( Exposure) #Exposure time in miliseconds value = ctypes.c_int(Gain) ueye.is_SetHWGainFactor(hcam, ueye.IS_SET_MASTER_GAIN_FACTOR, value) ueye.is_Exposure(hcam, ueye.IS_EXPOSURE_CMD_SET_EXPOSURE, exposure_time, ctypes.sizeof(ctypes.c_double)) print('Exposure (ms) =', exposure_time) print('Gain = ', Gain) time.sleep(float(Exposure * 1e-4) * 1.0 + 0.2) #Some time for CCD to set new exposure time #initially set to float(Exposure*1e-4)*1.0+1.0 and it works then nret = ueye.is_FreezeVideo(hcam, ueye.IS_WAIT) #Freeze/Snap #Save Parameters FileParams = ueye.IMAGE_FILE_PARAMS() FileParams.pwchFileName = (File_Location) FileParams.nFileType = ueye.IS_IMG_BMP FileParams.ppcImageMem = None FileParams.pnImageID = None #IF nret is '1' Image is not saved if nret is "0" Image is saved nret = ueye.is_ImageFile(hcam, ueye.IS_IMAGE_FILE_CMD_SAVE, FileParams, ueye.sizeof(FileParams)) if nret == 0: saved = True print('Image Saved!') if nret == 1: print('Error Image is not Saved!') #Shutting the CCD-Down. ueye.is_FreeImageMem(hcam, pccmem, memID) ueye.is_ExitCamera(hcam)
def set_pixel_clock(self, clock_mhz): clk_float = ueye.INT(clock_mhz) ueye.is_PixelClock(self.hCam, ueye.IS_PIXELCLOCK_CMD_SET, clk_float, ueye.sizeof(clk_float))
def setPixelClock(self, mhz): px_old = ueye.c_uint(0) ueye.is_PixelClock(self.hCam, ueye.IS_PIXELCLOCK_CMD_GET, px_old, ueye.sizeof(px_old)) px = ueye.c_uint(mhz) rv = ueye.is_PixelClock(self.hCam, ueye.IS_PIXELCLOCK_CMD_SET, px, ueye.sizeof(px))