def Set_Exp(self): if self.Movie_Switch == 1: self.exposure = ueye.DOUBLE(float(self.SetExp_lineEdit.text())) self.expms = ueye.DOUBLE(self.exposure) self.nRet = ueye.is_Exposure(self.hcam, ueye.IS_EXPOSURE_CMD_SET_EXPOSURE, self.expms, ueye.sizeof(self.expms))
def get_wb_param(self): pdblRed = ueye.DOUBLE(0) pdblGreen = ueye.DOUBLE(0) pdblBlue = ueye.DOUBLE(0) ret = ueye.is_GetWhiteBalanceMultipliers(self.h_cam, pdblRed, pdblGreen, pdblBlue) return (ret, pdblRed, pdblGreen, pdblBlue)
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_auto_exposure(self, auto=True): # FIXME no effect ? val1 = ueye.DOUBLE(1) val2 = ueye.DOUBLE() if auto == False: val1 = ueye.DOUBLE(0) check( ueye.is_SetAutoParameter(self.h_cam, ueye.IS_SET_ENABLE_AUTO_SHUTTER, val1, val2))
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_exposure(self, verbose=False): ret = ueye.DOUBLE() check( ueye.is_Exposure(self.h_cam, ueye.IS_EXPOSURE_CMD_GET_EXPOSURE, ret, ueye.sizeof(ret))) if verbose: print('Exposure: {}'.format(str(ret))) return ret
def configure(self, parameters): # Exposure varies by camera: 0.020ms to 69.847 for UI-3250 model (check uEye cockpit for specifics) # Gain (master) can be set between 0-100 # Black level can be set between 0-255 # Gamma can be set between 0.01 and 10 #Set dict keys to all lower case parameters = dict((k.lower(), v) for k, v in parameters.items()) if 'exposure' in parameters: #Doesn't do anything err = ueye.is_Exposure( self._cam, ueye.IS_EXPOSURE_CMD_SET_EXPOSURE, ueye.DOUBLE(parameters['exposure']), ueye.sizeof(ueye.DOUBLE(parameters['exposure']))) if err != ueye.IS_SUCCESS: raise CameraException(self._cam, 'ueye>configure>exposure>', err) if 'gain' in parameters: err = ueye.is_SetHardwareGain(self._cam, ueye.INT(parameters['gain']), ueye.IS_IGNORE_PARAMETER, ueye.IS_IGNORE_PARAMETER, ueye.IS_IGNORE_PARAMETER) if err != ueye.IS_SUCCESS: raise CameraException(self._cam, 'ueye>configure>gain>', err) if 'black_level' in parameters: err = ueye.is_Blacklevel( self._cam, ueye.IS_BLACKLEVEL_CMD_SET_OFFSET, ueye.INT(parameters['black_level']), ueye.sizeof(ueye.INT(parameters['black_level']))) if err != ueye.IS_SUCCESS: raise CameraException(self._cam, 'ueye>configure>black_level>', err) if 'gamma' in parameters: # Digital gamma correction err = ueye.is_Gamma( self._cam, ueye.IS_GAMMA_CMD_SET, ueye.INT(int(parameters['gamma'] * 100)), ueye.sizeof(ueye.INT(int(parameters['gamma'] * 100)))) if err != ueye.IS_SUCCESS: raise CameraException(self._cam, 'ueye>configure>gamma>', err)
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 __init__(self, cam_id, name): self._cam = ueye.HIDS(cam_id) self._cam_name = name self._sInfo = ueye.SENSORINFO() self._sFPS = ueye.DOUBLE() self._connect() # Query additional information about the sensor type used in the camera err = ueye.is_GetSensorInfo(self._cam, self._sInfo) if err != ueye.IS_SUCCESS: raise CameraException(self._cam, 'ueye>close>GetSensorInfo>', err) # Reset camera to default settings err = ueye.is_ResetToDefault(self._cam) if err != ueye.IS_SUCCESS: raise CameraException(self._cam, 'ueye>close>ResetToDefault>', err) # Set display mode to DIB err = ueye.is_SetDisplayMode(self._cam, ueye.IS_SET_DM_DIB) if err != ueye.IS_SUCCESS: raise CameraException(self._cam, 'ueye>close>SetDisplayMode>', err) # Core Camera Variables self._width = ueye.INT(self._sInfo.nMaxWidth.value) self._height = ueye.INT(self._sInfo.nMaxHeight.value) self._pitch = ueye.INT() self._ppc_img_mem = ueye.c_mem_p() self._mem_id = ueye.INT() self._nBitsPerPixel = ueye.INT() self._m_nColorMode = ueye.INT() self._bytes_per_pixel = ueye.INT() self._video_capture = False self._done_saving = True # Allicate memory for frames self._allocate_memory() # Start collection of frames self.start_video_capture() # Get frames per second err = ueye.is_GetFramesPerSecond(self._cam, self._sFPS) if err != ueye.IS_SUCCESS: raise CameraException(self._cam, 'ueye>close>GetFramesPerSecond>', err) # Start new thread to save frame threading.Thread(target=self._update).start()
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)
def display_image(self): fps = ueye.DOUBLE() ueye.is_GetFramesPerSecond(self.hCam, fps) timeout = int((5 / fps) * 1000) h_event = None if platform.system() == 'Windows': h_event = win32event.CreateEvent(None, False, False, None) self.event = ueye.HANDLE(int(h_event)) ueye.is_InitEvent(self.hCam, self.event, self.frame_event_id) ueye.is_EnableEvent(self.hCam, self.frame_event_id) while True: ret = None if not self.capturing: break if platform.system() == 'Windows': ret = win32event.WaitForSingleObject(h_event, timeout) elif platform.system() == 'Linux': ret = ueye.is_WaitEvent(self.hCam, self.frame_event_id, timeout) if ret == 0: converted_image_data = self.convert_image_data() self.image_data_copy = ( ueye.CHAR * int(self.img_data.width * self.img_data.height * 3))() ueye.is_CopyImageMem( hCam=self.hCam, pcSource=converted_image_data.memory_pointer, nID=converted_image_data.memory_id, pcDest=self.image_data_copy) bytes_per_pixel = 3 self.image_data_copy = numpy.reshape( self.image_data_copy, (int(self.img_data.height), int( self.img_data.width), bytes_per_pixel)) self.image_data_copy = self.image_data_copy.view(numpy.uint8) self.pil_image = Image.fromarray(self.image_data_copy) self.graphics_scene.clear() self.width, self.height = self.pil_image.size self.qt_image = ImageQt.ImageQt(self.pil_image) self.pix_map = QPixmap.fromImage(self.qt_image) self.graphics_scene.addPixmap(self.pix_map) self.graphics_view.fitInView( QRectF(0, 0, self.width, self.height), Qt.KeepAspectRatio) self.graphics_scene.update() app.processEvents()
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")
nRet = ueye.is_CaptureVideo(hCam, ueye.IS_DONT_WAIT) if nRet != ueye.IS_SUCCESS: print("is_CaptureVideo ERROR") # Enables the queue mode for existing image memory sequences print(hCam, pcImageMemory, MemID, width, height, nBitsPerPixel, pitch) 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 programm") #--------------------------------------------------------------------------------------------------------------------------------------- #экспозиция newFps = ueye.DOUBLE() error = ueye.is_SetFrameRate(hCam, 2, newFps) print("fps", newFps) rangeMin = ueye.DOUBLE(165) er = ueye.is_Exposure(hCam, ueye.IS_EXPOSURE_CMD_GET_EXPOSURE_RANGE_MIN, rangeMin, 8) rangeMax = ueye.DOUBLE(165) er = ueye.is_Exposure(hCam, ueye.IS_EXPOSURE_CMD_GET_EXPOSURE_RANGE_MAX, rangeMax, 8) print("range", rangeMin, rangeMax) ex = ueye.DOUBLE(165) er = ueye.is_Exposure(hCam, ueye.IS_EXPOSURE_CMD_SET_EXPOSURE, ex, 8) print("экспозиция ", ex, er) # Continuous image display
def set_frame_rate(self, fps): dfps = ueye.DOUBLE(0) ueyeFps = ueye.DOUBLE(fps) ueye.is_SetFrameRate(self.hCam, ueyeFps, dfps) print("new Framerate: ", dfps)
def set_exposure(self, exp): exp_double = ueye.DOUBLE(exp) ueye.is_Exposure(self.hCam, ueye.IS_EXPOSURE_CMD_SET_EXPOSURE, exp_double, ueye.sizeof(exp_double)) print("new exposure: ", exp_double)
def get_exposure(self): ms = ueye.DOUBLE(22) ueye.is_Exposure(self.h_cam, ueye.IS_EXPOSURE_CMD_GET_EXPOSURE, ms, ueye.sizeof(ueye.DOUBLE(ms))) return ms.value
def set_exposure(self, ms=0.12): ret = ueye.is_Exposure(self.h_cam, ueye.IS_EXPOSURE_CMD_SET_EXPOSURE, ueye.DOUBLE(ms), ueye.sizeof(ueye.DOUBLE(ms))) if ret: raise Exception('Set Exposure failed')
def set_wb_param(self, pdblRed, pdblGreen, pdblBlue): ret = ueye.is_SetWhiteBalanceMultipliers(self.h_cam, ueye.DOUBLE(pdblRed), ueye.DOUBLE(pdblGreen), ueye.DOUBLE(pdblBlue)) return ret
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()
exposure_high = 66 # Initialize camera import config cam = config.cam gain = ueye.INT(10) #ueye.is_SetHardwareGain(cam.handle(), gain, ueye.IS_IGNORE_PARAMETER, ueye.IS_IGNORE_PARAMETER, #ueye.IS_IGNORE_PARAMETER) # Increment increment = 2 # Loop from lowest possible exposure to highest possible exposure, incremented by 2 (ms) for exposure in range(exposure_low, exposure_high, increment): # Set new exposure newExposure = ueye.DOUBLE(exposure) ret = ueye.is_Exposure(cam.handle(), ueye.IS_EXPOSURE_CMD_SET_EXPOSURE, newExposure, ueye.sizeof(newExposure)) time.sleep(0.05) img = ImageFunctions.capture_image(cam=cam, gripper_height=500) puck_list = QR_Scanner(img) print(puck_list) # Checking exposure d = ueye.DOUBLE() retVal = ueye.is_Exposure(cam.handle(), ueye.IS_EXPOSURE_CMD_GET_EXPOSURE, d, 8) if retVal == ueye.IS_SUCCESS: print('Currently set exposure time %8.3f ms' % d) # Position returns as None if no QR-code is found if puck_list: exposure_values.append(exposure)
def main(): cam = ueye.HIDS() # open first available cam check(ueye.is_InitCamera(cam, None)) # query image size size = ueye.IS_SIZE_2D() check((ueye.is_AOI(cam, ueye.IS_AOI_IMAGE_GET_SIZE, size, ueye.sizeof(size)))) width = size.s32Width height = size.s32Height # allocate memory. we need at least one buffer mem_ptr = ueye.c_mem_p() mem_id = ueye.INT() bits_per_pixel = ueye.INT(24) # assume we have 24 bits per pixel (rgb) check( ueye.is_AllocImageMem(cam, width, height, bits_per_pixel, mem_ptr, mem_id)) # set the image mem active, so we can render into check(ueye.is_SetImageMem(cam, mem_ptr, mem_id)) # we need to get the mem pitch for later usage pitch = ueye.INT() check( ueye.is_InquireImageMem(cam, mem_ptr, mem_id, width, height, bits_per_pixel, pitch)) #expMax = ueye.DOUBLE(0.0) expMax = [10, 20, 30, 40] # now lets capture a contineous video while True: # For loop for i in my_range(0, 4, 1): if i == 4: break # print("i= ",expMax[i]) timeExp = ueye.DOUBLE(expMax[i]) check( ueye.is_Exposure(cam, ueye.IS_EXPOSURE_CMD_SET_EXPOSURE, timeExp, ueye.sizeof(timeExp))) print("Set Exposure :", timeExp) time.sleep(1) # lets capture one image check(ueye.is_FreezeVideo(cam, ueye.IS_WAIT)) # for this we use a function from the pyueye interface get data array = ueye.get_data(mem_ptr, width, height, bits_per_pixel, pitch, copy=False) # we do not want to copy # print(array) # we have to reshape the array frame = np.reshape(array, (height.value, width.value, 3)) # print(frame) framesmall = cv2.resize(frame, (0, 0), fx=0.3, fy=0.3) time.sleep(1) #cv2.imshow('img', framesmall) # Save image OpenCV cv2.imwrite("img_" + str(expMax[i]) + 'ms.jpg', frame) print("save image to file: " + "img_" + str(expMax[i]) + 'ms.jpg') # if the 'q' key is pressed, stop the loop key = cv2.waitKey(1) & 0xFF if cv2.waitKey(1) & 0xFF == ord('q'): break # we have to free our image mem at the end check(ueye.is_FreeImageMem(cam, mem_ptr, mem_id)) check(ueye.is_ExitCamera(cam))
hCam = ueye.HIDS( 0 ) #0: first available camera; 1-254: The camera with the specified camera ID sInfo = ueye.SENSORINFO() cInfo = ueye.CAMINFO() pcImageMemory = ueye.c_mem_p() MemID = ueye.int() rectAOI = ueye.IS_RECT() pitch = ueye.INT() nBitsPerPixel = ueye.INT( 12 ) #24: bits per pixel for color mode; take 8 bits per pixel for monochrome channels = 1 #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) fps = ueye.DOUBLE(2) rangeMin = ueye.DOUBLE() rangeMax = ueye.DOUBLE() ex = ueye.DOUBLE(25) #--------------------------------------------------------------------------------------------------------------------------------------- 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:
else: # 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 = 20 a = ueye.DOUBLE(40) 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() 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 array = ueye.get_data(pcImageMemory, width,
print("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) # 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
print("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) # 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
def auto_configure(self, auto_reference=90, timeout=60): ueye.is_SetAutoParameter(self._cam, ueye.IS_SET_AUTO_WB_ONCE, ueye.DOUBLE(1), ueye.DOUBLE(0)) ueye.is_SetAutoParameter(self._cam, ueye.IS_SET_AUTO_BRIGHTNESS_ONCE, ueye.DOUBLE(1), ueye.DOUBLE(0)) ueye.is_SetAutoParameter(self._cam, ueye.IS_SET_AUTO_REFERENCE, ueye.DOUBLE(auto_reference), ueye.DOUBLE(0)) ueye.is_SetAutoParameter(self._cam, ueye.IS_SET_ENABLE_AUTO_WHITEBALANCE, ueye.DOUBLE(1), ueye.DOUBLE(0)) ueye.is_SetAutoParameter(self._cam, ueye.IS_SET_ENABLE_AUTO_GAIN, ueye.DOUBLE(1), ueye.DOUBLE(0)) err = ueye.is_SetAutoParameter(self._cam, ueye.IS_SET_ENABLE_AUTO_SHUTTER, ueye.DOUBLE(1), ueye.DOUBLE(0)) if err != ueye.IS_SUCCESS: raise CameraException(self._cam, 'ueye>auto_parameters>', err) WB_status = ueye.DOUBLE(1.0) gain_status = ueye.DOUBLE(1.0) shutter_status = ueye.DOUBLE(1.0) timeout += time.time() while WB_status or gain_status or shutter_status: ueye.is_SetAutoParameter(self._cam, ueye.IS_GET_ENABLE_AUTO_WHITEBALANCE, WB_status, ueye.DOUBLE(0)) ueye.is_SetAutoParameter(self._cam, ueye.IS_GET_ENABLE_AUTO_GAIN, gain_status, ueye.DOUBLE(0)) ueye.is_SetAutoParameter(self._cam, ueye.IS_GET_ENABLE_AUTO_SHUTTER, shutter_status, ueye.DOUBLE(0)) if time.time() > timeout: break
def find_correct_exposure(cam, robot): """Auto exposure is not used, as it may fail to identify what the subject is. Instead, a manual exposure value is calculated by capturing images with all possible exposure values and selecting the value that identifies QR codes with most success. """ # If the repeatability test fails, this will exit the program if not robot.is_running(): sys.exit(0) print("---Running find_correct_exposure---") # TODO: Use several pucks to determine the best exposure times. # Input amount of pucks and grade exposure values based on how many of the pucks are found each time abspath = os.path.abspath("image_tools/cam_adjustments.ini") value_pairs = [] puck_list = [] # Exposure range (in ms) exposure_low = 2 exposure_high = 66 increment = 2 # Loop from lowest possible exposure to highest possible exposure, incremented by 2 (ms) for exposure in range(exposure_low, exposure_high, increment): # Set new exposure newExposure = ueye.DOUBLE(exposure) ret = ueye.is_Exposure(cam.hCam, ueye.IS_EXPOSURE_CMD_SET_EXPOSURE, newExposure, ueye.sizeof(newExposure)) img = ImageFunctions.capture_image(cam=cam, gripper_height=500) puck_list = ImageFunctions.QR_Scanner(img) print("Found puck:", puck_list) # Checking exposure d = ueye.DOUBLE() retVal = ueye.is_Exposure(cam.hCam, ueye.IS_EXPOSURE_CMD_GET_EXPOSURE, d, 8) if retVal == ueye.IS_SUCCESS: print('Currently set exposure time %8.3f ms' % d) # Position returns as None if no QR-code is found if puck_list: value_pairs.append((exposure, len(puck_list))) weighted_sum = 0 pucks_found = 0 for value_pair in value_pairs: pucks_found += value_pair[1] weighted_sum += value_pair[0] * value_pair[1] exposure = str(int(weighted_sum / pucks_found)) print(value_pairs[0]) configfile_name = abspath config = configparser.ConfigParser() config.read(configfile_name) cfgfile = open(configfile_name, 'w') # Add content to the file config.set('EXPOSURE', 'exposure', exposure) config.write(cfgfile) cfgfile.close() # Set the correct exposure time cam.set_parameters()
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) """ exp_min = ueye.DOUBLE() ret = ueye.is_Exposure(cam.handle(), ueye.IS_EXPOSURE_CMD_GET_EXPOSURE_RANGE_MIN, exp_min, ueye.sizeof(exp_min))
# 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):
def set_exposure(self, exposure): val = ueye.DOUBLE(exposure) check( ueye.is_Exposure(self.h_cam, ueye.IS_EXPOSURE_CMD_SET_EXPOSURE, val, ueye.sizeof(val)))