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_hw_gain(self, gain): """ Set the master amplification. It can be tuned between 0% and 100%. :param gain: amplification to be set :return: None """ gn = ueye.UINT(int(gain)) # nRet = ueye.is_SetHWGainFactor(self.cam, ueye.IS_SET_MASTER_GAIN_FACTOR, gn) # if not ueye.is_SetHardwareGain(self.cam, gn, ueye.IS_IGNORE_PARAMETER, ueye.IS_IGNORE_PARAMETER, # ueye.IS_IGNORE_PARAMETER) == ueye.IS_SUCCESS: if not ueye.is_SetHardwareGain(self.cam, gn, ueye.UINT(int(0)), ueye.INT(int(0)), ueye.INT(int(0))) == ueye.IS_SUCCESS: raise RuntimeError("Gain not set") print("Master gain set to", gn.value)
def set_parameters(self, disable_exposure=True): # Change image format # formatID = ueye.UINT(5) # Change image format to 2048x1536 formatID = ueye.UINT(8) # Change image format to 1280x960 nRet = ueye.is_ImageFormat(self.hCam, ueye.IMGFRMT_CMD_SET_FORMAT, formatID, ueye.sizeof(formatID)) if disable_exposure: # Disable auto exposure dblEnable = ueye.DOUBLE(0) dblDummy = ueye.DOUBLE(0) ueye.is_SetAutoParameter( self.hCam, ueye.IS_SET_ENABLE_AUTO_SENSOR_GAIN_SHUTTER, dblEnable, dblDummy) # Set new exposure value from .ini-file config = configparser.ConfigParser() config.read('image_tools/cam_adjustments.ini') exposure = float(config['EXPOSURE']['exposure']) newExposure = ueye.DOUBLE(exposure) ret = ueye.is_Exposure(self.hCam, ueye.IS_EXPOSURE_CMD_SET_EXPOSURE, newExposure, ueye.sizeof(newExposure)) # Disable autofocus ueye.is_Focus(self.hCam, ueye.FOC_CMD_SET_DISABLE_AUTOFOCUS, None, 0)
def __set_black_level(self, level): bl = ueye.UINT(int(level)) if not ueye.is_Blacklevel(self.cam, ueye.IS_BLACKLEVEL_CMD_SET_OFFSET, bl, ueye.ctypes.sizeof(bl)) == ueye.IS_SUCCESS: raise RuntimeError("IS_BLACKLEVEL_CMD_SET_OFFSET failed") return bl.value
def calculate_focus(cam, working_distance): """This characteristic belongs to the IDS XS camera with serial code 4102885308. As stated by IDS themselves the characteristic is not robust and could vary between different cameras. The characteristic was made based on images up to a working distance of 620mm. """ # TODO: Make characteristics for all IDS XS cameras at UiS. # By checking the serial code through ueye.SENSORINFO, one would know which specific camera is in use if working_distance >= 357.5: focus_value = 204 elif 237 <= working_distance < 357.5: focus_value = 192 elif 169 <= working_distance < 237: focus_value = 180 elif 131.5 <= working_distance < 169: focus_value = 168 elif 101.5 <= working_distance < 131.5: focus_value = 156 elif 86.5 <= working_distance < 101.5: focus_value = 144 elif 72 <= working_distance < 86.5: focus_value = 128 elif 42.5 <= working_distance < 72: focus_value = 112 else: print("Too close to subject. Focus value not found. Default value: 204") focus_value = 204 # Set the correct focus value focus_UINT = ueye.UINT(focus_value) ueye.is_Focus(cam.hCam, ueye.FOC_CMD_SET_MANUAL_FOCUS, focus_UINT, ueye.sizeof(focus_UINT)) time.sleep(0.3)
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 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_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_format_list(self): count = ueye.UINT() check(ueye.is_ImageFormat(self.h_cam, ueye.IMGFRMT_CMD_GET_NUM_ENTRIES, count, ueye.sizeof(count))) format_list = ueye.IMAGE_FORMAT_LIST(ueye.IMAGE_FORMAT_INFO * count.value) format_list.nSizeOfListEntry = ueye.sizeof(ueye.IMAGE_FORMAT_INFO) format_list.nNumListElements = count.value check(ueye.is_ImageFormat(self.h_cam, ueye.IMGFRMT_CMD_GET_LIST, format_list, ueye.sizeof(format_list))) return format_list
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 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 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 ueye_get_image_formats(hcam): fcnt = ueye.UINT() cmd = ueye.IMGFRMT_CMD_GET_NUM_ENTRIES err = ueye.is_ImageFormat(hcam, cmd, fcnt, ueye.sizeof(fcnt)) _throw_if_err(hcam, err) fl = ueye.IMAGE_FORMAT_LIST((ueye.IMAGE_FORMAT_INFO * fcnt)) fl.nSizeOfListEntry = ueye.sizeof(ueye.IMAGE_FORMAT_INFO) fl.nNumListElements = fcnt cmd = ueye.IMGFRMT_CMD_GET_LIST err = ueye.is_ImageFormat(hcam, cmd, fl, ueye.sizeof(fl)) # aufschluesseln auf human readable fl2 = {fi.nFormatID.value: fi for fi in fl.FormatInfo} ret = {} for k, v in sorted(fl2.items()): ret[k] = v.strFormatName.decode("utf-8") return ret
def disable_full_auto(self): print("full auto") disable = ueye.DOUBLE(0) enable = ueye.DOUBLE(1) zero = ueye.DOUBLE(0) awb_type = ueye.void_p ret = ueye.is_SetAutoParameter(self.h_cam, ueye.IS_SET_ENABLE_AUTO_GAIN, disable, zero) print('A_GAIN:', ret) ret = ueye.is_SetAutoParameter(self.h_cam, ueye.IS_SET_ENABLE_AUTO_SHUTTER, disable, zero) print('A_SHUTTER:', ret) ret = ueye.is_SetAutoParameter(self.h_cam, ueye.IS_SET_ENABLE_AUTO_WHITEBALANCE, disable, zero) print('A_WB:', ret) ret = ueye.is_AutoParameter(self.h_cam, ueye.IS_AWB_CMD_GET_TYPE, awb_type, ueye.UINT(0)) print('current A_WB_TYPE:', ret, awb_type)
# Activates the camera's live video mode (free run mode) # 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: print("is_InquireImageMem ERROR") else: print("Press q to leave the program") a=20 a=ueye.DOUBLE(30) c=ueye.DOUBLE() b=ueye.UINT(8) thing=ueye.is_Exposure(hCam,ueye.IS_EXPOSURE_CMD_SET_EXPOSURE, a,b ) thing=ueye.is_Exposure(hCam,ueye.IS_EXPOSURE_CMD_GET_EXPOSURE, c,b ) print(c) gain=ueye.UINT(80) thingy=ueye.is_SetHardwareGain(hCam,gain, ueye.IS_IGNORE_PARAMETER, ueye.IS_IGNORE_PARAMETER, ueye.IS_IGNORE_PARAMETER) #--------------------------------------------------------------------------------------------------------------------------------------- nRet = ueye.is_FreezeVideo(hCam, ueye.IS_WAIT) Iinfo=ueye.UEYEIMAGEINFO() n=1 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
import cv2 from pyueye import ueye from pyueye_example_camera import Camera from pyueye_example_utils import ImageData, ImageBuffer import time import numpy as np # Initialize camera cam = Camera() cam.init() nRet = ueye.is_ResetToDefault(cam.handle()) # Change the format to 1280x960 formatID = ueye.UINT(8) nRet = ueye.is_ImageFormat(cam.handle(), ueye.IMGFRMT_CMD_SET_FORMAT, formatID, ueye.sizeof(formatID)) cam.alloc() # Allocate image memory # Disable auto exposure dblEnable = ueye.DOUBLE(0) dblDummy = ueye.DOUBLE(0) ueye.is_SetAutoParameter(cam.handle(), ueye.IS_SET_ENABLE_AUTO_SENSOR_GAIN_SHUTTER, dblEnable, dblDummy) newExposure = ueye.DOUBLE(30) ret = ueye.is_Exposure(cam.handle(), ueye.IS_EXPOSURE_CMD_SET_EXPOSURE, newExposure, ueye.sizeof(newExposure)) ueye.is_Focus(cam.handle(), ueye.FOC_CMD_SET_DISABLE_AUTOFOCUS, None, 0) # Disable autofocus focus_overview = ueye.INT(205) # Focus value for overview image (taken from 570mm above table) focus_closeup = ueye.INT(144) # Focus value for closeup image (taken from 190mm above table)
# Set the desired color mode nRet = ueye.is_SetColorMode(hCam, m_nColorMode) # Activates the camera's live video mode (free run mode) # 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: print("is_InquireImageMem ERROR") else: print("Press q to leave the program") a = ueye.DOUBLE(10) c = ueye.DOUBLE() b = ueye.UINT(8) thing = ueye.is_Exposure(hCam, ueye.IS_EXPOSURE_CMD_SET_EXPOSURE, a, b) thing = ueye.is_Exposure(hCam, ueye.IS_EXPOSURE_CMD_GET_EXPOSURE, c, b) print(c) #--------------------------------------------------------------------------------------------------------------------------------------- nRet = ueye.is_FreezeVideo(hCam, ueye.IS_WAIT) Iinfo = ueye.UEYEIMAGEINFO() count = 0 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 nRet = ueye.is_FreezeVideo(hCam, ueye.IS_WAIT) array = ueye.get_data(pcImageMemory,
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.')
# Set the desired color mode nRet = ueye.is_SetColorMode(hCam, m_nColorMode) # Activates the camera's live video mode (free run mode) # 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: print("is_InquireImageMem ERROR") else: print("Press q to leave the program") a = ueye.DOUBLE(20) c = ueye.DOUBLE() b = ueye.UINT(8) gain = ueye.UINT(100) thing = ueye.is_Exposure(hCam, ueye.IS_EXPOSURE_CMD_SET_EXPOSURE, a, b) thing = ueye.is_Exposure(hCam, ueye.IS_EXPOSURE_CMD_GET_EXPOSURE, c, b) print(c) thingy = ueye.is_SetHardwareGain(hCam, gain, ueye.IS_IGNORE_PARAMETER, ueye.IS_IGNORE_PARAMETER, ueye.IS_IGNORE_PARAMETER) #--------------------------------------------------------------------------------------------------------------------------------------- nRet = ueye.is_FreezeVideo(hCam, ueye.IS_WAIT) Iinfo = ueye.UEYEIMAGEINFO() count = 0 while (nRet == ueye.IS_SUCCESS):
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)))