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 __init__(self, frames_avg=1): """ Object constructor, called when creating instance of the BaslerCam class """ self.CamID = ueye.HIDS(1) self.intTime = 15000 self.iniFile = "" self.frames_avg = frames_avg self.connected = False self.binningEnabled = False # ctypes process parameters self.memPointer = ueye.c_mem_p() self.memID = ueye.c_int() self.pPitch = ueye.c_int() self.bitdepth = 16 #ueye.c_int(8) self.FPS = 8 self.currentFPS = self.FPS self.pixelClock = 80 # Sensor dimension variables: variable type in native python + fixed sensorSize in ctypes formats self.sensorHeight_ctype = ueye.c_int(3088) self.sensorWidth_ctype = ueye.c_int(2076) self.currentWidth = 3088 self.currentHeight = 2076 # Initialize camera self.connect()
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 main(config_path="/home/oran/Pictures/Settings/default-camera-settings.ini" ): print(config_path) # we need a QApplication, that runs our QT Gui Framework app = PyuEyeQtApp() # a basic qt window view = PyuEyeQtView() view.resize(1920 / 1.5, 1080 / 1.5) view.show() #update_config_gain(update={'red': '0','green' : '0','blue':'0'},set=True) #update_config_exposure(update=70,set=True) # view.user_callback = adjust_manually view.user_callback = print_means # view.user_callback = adjust_manually # camera class to simplify uEye API access cam = Camera() cam.init() # cam.set cam.set_colormode(ueye.IS_CM_BGR8_PACKED) pParam = ueye.wchar_p() pParam.value = config_path ueye.is_ParameterSet(1, ueye.IS_PARAMETERSET_CMD_LOAD_FILE, pParam, 0) # cam.set(cv2.cv.CV_CAP_PROP_EXPOSURE, 10) # cam.__getattribute__('is_CameraStatus') # cam.__setattr__('GetCameraInfo',0) #cam.set_aoi(0,0, 1280, 1024) cam.set_aoi(0, 0, 4912, 3684) cam.alloc() cam.capture_video() ueye._is_GetError ueye.is_Exposure(1, ueye.c_uint(1), ueye.c_void_p(), cbSizeOfParam=ueye.c_int(0)) # ueye.IS_EXPOSURE_CMD_GET_FINE_INCREMENT_RANGE_MIN = 20 # ueye.IS_EXPOSURE_CMD_GET_FINE_INCREMENT_RANGE_MAX = 21 # a thread that waits for new images and processes all connected views thread = FrameThread(cam, view) thread.start() # update_config_gain() # cleanup app.exit_connect(thread.stop) app.exec_() thread.stop() thread.join() cam.stop_video() cam.exit()
def initCamera(self): try: self.hcam = ueye.HIDS(0) self.pccmem = ueye.c_mem_p() self.memID = ueye.c_int() self.hWnd = ctypes.c_voidp() ueye.is_InitCamera(self.hcam, self.hWnd) ueye.is_SetDisplayMode(self.hcam, 0) self.sensorinfo = ueye.SENSORINFO() ueye.is_GetSensorInfo(self.hcam, self.sensorinfo) return self.OP_OK except: return self.OP_ERR
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 __init__(self, serial): nc=ueye.c_int() self.status=True self._bgImage=0 self.bg=0 if ueye.is_GetNumberOfCameras(nc): _logger.error("Error Wrong number of cameras") return lst=ueye.UEYE_CAMERA_LIST((ueye.UEYE_CAMERA_INFO*nc.value)) lst.dwCount=nc.value ueye.is_GetCameraList(lst) index=None for i in range(nc.value): _logger.info("Got the following ccd: %s"%lst.uci[i].SerNo) if (lst.uci[i].SerNo==serial): index=i break if index is None: _logger.error("SerNo %s not found."%serial) return if lst.uci[index].dwStatus: _logger.error("Camera %d is already busy."%index) self.hcam=ueye.HIDS(index) if ueye.is_InitCamera(self.hcam, None): _logger.error("Error inializating camera.") self.status=True return self.bufCount=0 self.bitsPixel=8 self.Imgs=None self.LastSeqBuf1=ueye.c_mem_p(1) self.acq=False self.grabbingCB=dummy self.grabbing=False self.setColorMode(ueye.IS_CM_MONO8) if self.LoadSettings(): _logger.error("error laoding camera settings") sys.exit() self.status=False
def initCamera(self): try: self.hcam = ueye.HIDS(0) self.pccmem = ueye.c_mem_p() self.memID = ueye.c_int() self.hWnd = ctypes.c_voidp() ueye.is_InitCamera(self.hcam, self.hWnd) ueye.is_SetDisplayMode(self.hcam, 0) self.sensorinfo = ueye.SENSORINFO() ueye.is_GetSensorInfo(self.hcam, self.sensorinfo) auto_res = ueye.is_SetAutoParameter(self.hcam, ueye.IS_SET_ENABLE_AUTO_SHUTTER, ctypes.c_double(1), ctypes.c_double(1)) try: auto_res = ueye.GetExposureRange() print auto_res except Exception as Ex: print Ex pass print auto_res return self.OP_OK except Exception as ex: logging.exception("Error during camera initialization!") return self.OP_ERR
import ctypes import numpy as np from pyueye import ueye import copy import time uEyeDll = ctypes.cdll.LoadLibrary(r"C:\Windows\System32\uEye_api_64.dll") cam = ctypes.c_uint32(0) hWnd = ctypes.c_voidp() msg = uEyeDll.is_InitCamera(ctypes.byref(cam), hWnd) uEyeDll.is_EnableAutoExit(cam, ctypes.c_uint(1)) col = ueye.c_int(0) mod = ueye.c_int(0) ueye.is_GetColorDepth(cam, col, mod) ueye.is_SetColorMode(cam, ueye.IS_CM_MONO8) imageSize = ueye.IS_SIZE_2D() imageSize.s32Width = ueye.c_int(224) imageSize.s32Height = ueye.c_int(224) ueye.is_AOI(cam, ueye.IS_AOI_IMAGE_SET_SIZE, imageSize, ueye.sizeof(imageSize)) width_py = imageSize.s32Width height_py = imageSize.s32Height pixels_py = 8 width = width_py height = height_py bitspixel = ctypes.c_int(pixels_py) pcImgMem = ctypes.c_char_p() pid = ctypes.c_int() uEyeDll.is_AllocImageMem(cam, width, height, bitspixel, ctypes.byref(pcImgMem), ctypes.byref(pid)) uEyeDll.is_SetImageMem(cam, pcImgMem, pid)
from pyueye import ueye hcam = ueye.HIDS(0) pccmem = ueye.c_mem_p() memID = ueye.c_int(0) ueye.is_InitCamera(hcam, None) sensorinfo = ueye.SENSORINFO() ueye.is_GetSensorInfo(hcam, sensorinfo) ueye.is_SetColorMode(hcam, ueye.IS_CM_SENSOR_RAW8) ueye.is_AllocImageMem(hcam, sensorinfo.nMaxWidth, sensorinfo.nMaxHeight, 8, pccmem, memID) ueye.is_SetImageMem(hcam, pccmem, memID) ueye.is_SetExternalTrigger(hcam, ueye.IS_SET_TRIGGER_SOFTWARE) wertSet = ueye.c_double(1) nret = ueye.is_Exposure(hcam, ueye.IS_EXPOSURE_CMD_SET_EXPOSURE, wertSet, ueye.sizeof(wertSet)) print(wertSet) help(ueye.is_Exposure) wert = ueye.c_double() sizeo = ueye.sizeof(wert) nret = ueye.is_Exposure(hcam, ueye.IS_EXPOSURE_CMD_GET_EXPOSURE, wert, sizeo) print(wert) nret = ueye.is_FreezeVideo(hcam, ueye.IS_WAIT) print(nret) FileParams = ueye.IMAGE_FILE_PARAMS() FileParams.pwchFileName = "c:\python-test-image.png" FileParams.nFileType = ueye.IS_IMG_PNG FileParams.ppcImageMem = None
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 __init__(self): self.mem_ptr = ueye.c_mem_p() self.mem_id = ueye.int() self.dumy_id = ueye.c_int() self.mem_ptrlast = ueye.c_mem_p()