def __init__(self): self.cam = ueye.HIDS(0) self.cam_info = ueye.CAMINFO() self.sensor_info = ueye.SENSORINFO() self.image_memory = ueye.c_mem_p() self.memory_id = ueye.int() self.rect_aoi = ueye.IS_RECT() self.bits_per_pixel = ueye.INT(24) self.bytes_per_pixel = int(self.bits_per_pixel / 8) self.pitch = ueye.INT() self.color_mode = ueye.INT() self.width = 0 self.height = 0 self.status = 'IDLE' self.data = [] self.lock = Lock() self.pipe = 0 self.offset_x = 2 self.offset_y = 2 self.__init_camera() self.__get_camera_info() self.__get_sensor_info() #self.__default() self.__display_mode() self.__get_color_mode() self.__get_dimensions() self.__memory_allocation() self.__set_color_mode() self.__set_events() self.__mandatory_shit() print("Color mode {}".format(self.color_mode)) print("Bits per pixel {}".format(self.bits_per_pixel)) print("Bytes per pixel {}".format(self.bytes_per_pixel))
def initialize_color_mode(self): ''' Initializes color mode. Sets: self.m_nColorMode self.bits_per_pixel self.bytes_per_pixel ''' # get color mode sensor_info = ueye.SENSORINFO() color_mode = int.from_bytes(sensor_info.nColorMode.value, byteorder='big') self.m_nColorMode = ueye.INT() # determine the number of bits/bytes per pixel through the color mode bits_per_pixel = ueye.INT(24) if color_mode == ueye.IS_COLORMODE_BAYER: # setup the color depth to the current windows setting ueye.is_GetColorDepth(self.input, bits_per_pixel, self.m_nColorMode) # TODO: unimplemented bayer pixel format elif color_mode == ueye.IS_COLORMODE_CBYCRY: self.m_nColorMode = ueye.IS_CM_BGRA8_PACKED bits_per_pixel = ueye.INT(32) # TODO: test this once we get a suitable camera self.config['pixel_format'] = 'bgra' else: self.m_nColorMode = ueye.IS_CM_MONO8 bits_per_pixel = ueye.INT(8) self.config['pixel_format'] = 'gray' self.bytes_per_pixel = int(bits_per_pixel / 8) self.bits_per_pixel = bits_per_pixel
def __init__(self): self.hCam = ueye.HIDS( 1 ) # 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.f_length = (652.7396, 653.3803) # FocalLength self.p_center = (321.8104, 259.7124) # PrincipalPoint self.intrinsic = np.array( [[self.f_length[0], 0, self.p_center[0]], [0, self.f_length[1], self.p_center[1]], [0, 0, 1]], dtype=np.float) self.offset = [0, 0, 50] #milimeter # --------------------------------------------------------------------------------------------------------------------------------------- print("In hand camera initilized")
def convert_image_data(self): rect_aoi = ueye.IS_RECT() bits_per_pixel = 24 converted_image_data = ImageData() conversion_params = ueye.BUFFER_CONVERSION_PARAMS() ueye.is_AOI(self.hCam, ueye.IS_AOI_IMAGE_GET_AOI, rect_aoi, ueye.sizeof(rect_aoi)) converted_image_data.memory_pointer = self.converted_memory_pointer converted_image_data.memory_id = self.converted_memory_id converted_image_data.width = rect_aoi.s32Width converted_image_data.height = rect_aoi.s32Height converted_image_data.bits_per_pixel = bits_per_pixel conversion_params.nDestPixelFormat = ueye.IS_CM_RGB8_PACKED conversion_params.pSourceBuffer = self.img_data.memory_pointer conversion_params.pDestBuffer = converted_image_data.memory_pointer conversion_params.nDestPixelConverter = ueye.IS_CONV_MODE_SOFTWARE_3X3 conversion_params.nDestColorCorrectionMode = ueye.IS_CCOR_DISABLE conversion_params.nDestGamma = ueye.INT(100) conversion_params.nDestSaturationU = ueye.INT(100) conversion_params.nDestSaturationV = ueye.INT(100) conversion_params.nDestEdgeEnhancement = ueye.INT(0) ueye.is_Convert(self.hCam, ueye.IS_CONVERT_CMD_APPLY_PARAMS_AND_CONVERT_BUFFER, conversion_params, ueye.sizeof(conversion_params)) return converted_image_data
def __init__(self): # Variabeln für Kameraverarbeitung self.h_cam = ueye.HIDS(0) self.pitch = ueye.INT() self.ColorMode = ueye.IS_CM_BGRA8_PACKED self.nBitsPerPixel = ueye.INT(32) self.bytes_per_pixel = int(self.nBitsPerPixel / 8) self.pitch = ueye.INT() self.pcImageMemory = ueye.c_mem_p() self.rectAOI = ueye.IS_RECT() self.MemID = ueye.int() self.width = None self.height = None self.size_of_square = 3.6 # Zentimeter self.nx = 8 self.ny = 6 self.n_im = 0 self.gray = None self.objectpoints = None self.imagepoints = None self.camera_matrix = None self.dist_coeff = None self.mean_error = 0 # Pfad zum Speichern der Bilder angeben self.path = os.path.dirname(os.path.abspath(sys.argv[0])) + "/images/"
def __init__(self, camID, buffer_count=3): # Variables self.cam = ueye.HIDS(camID) 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(8) self.channels = 3 self.m_nColorMode = ueye.IS_CM_SENSOR_RAW8 self.bytes_per_pixel = int(self.nBitsPerPixel / 8) self.buffer_count = buffer_count self.img_buffer = [] self.mode_filename = 0 self.pixelclock = 0 self.exposure = 0 self.width = 0 self.height = 0 self.nRet = 0 self.camID = camID self.current_fps = 0 self.FPS = 0 self.gain = 0 self.rGain = 0 self.bGain = 0 self.gGain = 0
def __init__(self): # Variabeln für Kameraverarbeitung self.h_cam = ueye.HIDS(0) self.pitch = ueye.INT() self.ColorMode = ueye.IS_CM_BGRA8_PACKED self.nBitsPerPixel = ueye.INT(32) self.bytes_per_pixel = int(self.nBitsPerPixel / 8) self.pitch = ueye.INT() self.pcImageMemory = ueye.c_mem_p() self.rectAOI = ueye.IS_RECT() self.MemID = ueye.int() self.width = None self.height = None self.dst = None self.path_images = os.path.dirname(os.path.abspath( sys.argv[0])) + "/images/" # laden der intrinsischen Kalibriermatrix self.load_calibration_config() # Variabeln zur Farberkennung self.found_container = False self.contours_rectangle = [] blue_lower = [50, 0, 0] blue_upper = [255, 75, 75] self.boundaries = [(blue_lower, blue_upper)] self.cX = None self.cY = None self.cX_container = None self.cY_container = None # Variablen zur Positionsbestimmung self.container_world_position = [] self.ball_position = [] self.container_position = [] self.qr_centres = [] self.world_points = [] self.qr_codes = None self.image_points_of_qr_codes = None self.localization_qr_codes = [] self.world_localization_qr_codes = [] self.increment = 0.25 self.results = 0 # Wahl des Ansatzes self.method = 0 while self.method <= 0 or self.method >= 4: try: self.method = eval( input( "Mit welchem Ansatz sollen die Positionen ermittelt werden?\n (1) GPS-Ansatz\n " "(2) Vergleichsansattz\n (3) Berechnen der Weltkoordinaten\n" )) except NameError: self.method = 0 except SyntaxError: self.method = 0 except TypeError: self.method = 0
def __init__(self): super(CamDialog, self).__init__() loadUi('cam.ui', self) self.image=None self.roi_color=None self.startButton.clicked.connect(self.start_webcam) self.stopButton.clicked.connect(self.stop_webcam) # self.detectButton.setCheckable(True) # self.detectButton.toggled.connect(self.detect_webcam_face) self.face_Enabled=False self.faceCascade=cv2.CascadeClassifier('haarcascade_frontalface_default.xml') 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.nRet = ueye.is_InitCamera(self.hCam, None) self.nRet = ueye.is_GetCameraInfo(self.hCam, self.cInfo) self.nRet = ueye.is_GetSensorInfo(self.hCam, self.sInfo) self.nRet = ueye.is_ResetToDefault(self.hCam) self.nRet = ueye.is_SetDisplayMode(self.hCam, ueye.IS_SET_DM_DIB) ueye.is_GetColorDepth(self.hCam, self.nBitsPerPixel, self.m_nColorMode) self.nRet = ueye.is_AOI(self.hCam, ueye.IS_AOI_IMAGE_GET_AOI, self.rectAOI, ueye.sizeof(self.rectAOI)) self.width = self.rectAOI.s32Width self.height = self.rectAOI.s32Height self.nRet = ueye.is_AllocImageMem(self.hCam, self.width, self.height, self.nBitsPerPixel, self.pcImageMemory, self.MemID) self.nRet = ueye.is_SetImageMem(self.hCam, self.pcImageMemory, self.MemID) self.nRet = ueye.is_SetColorMode(self.hCam, self.m_nColorMode) self.nRet = ueye.is_CaptureVideo(self.hCam, ueye.IS_DONT_WAIT) self.nRet = ueye.is_InquireImageMem(self.hCam, self.pcImageMemory, self.MemID, self.width, self.height, self.nBitsPerPixel, self.pitch) self.xp=[] self.yp=[] self.lxp=[] self.lyp = [] self.rxp = [] self.ryp = [] self.sx = 200 self.sy = 150 self.endx = 600 self.endy = 450 # self.avgx = 0 # self.avgy = 0 self.holeflag = 0 self.lflag = 0 self.rflag = 0
def get_bit_per_pixel(self, color_mode): """ Returns the number of bits per pixel for the given color mode. """ if color_mode not in bits_per_pixel.keys(): print(f"Unknown color mode: {color_mode}") print("It will be set to default value") self.bits_per_pixel = ueye.INT(bits_per_pixel[11]) self.m_nColorMode = ueye.IS_CM_SENSOR_RAW8 else: self.bits_per_pixel = ueye.INT(bits_per_pixel[color_mode])
def init(self): ret = ueye.is_InitCamera(self.h_cam, None) if ret != ueye.IS_SUCCESS: self.h_cam = None raise uEyeException(ret) check( ueye.is_ParameterSet(self.h_cam, ueye.IS_PARAMETERSET_CMD_LOAD_EEPROM, ueye.INT(0), ueye.INT(0))) return ret
def __init__(self, cam_ID = 0): # Several parameters are unused, but may be needed in the future self.hCam = ueye.HIDS(cam_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(32) # 32 bits for color camera self.channels = 3 # 3: channels for color mode(RGB); take 1 channel for monochrome self.m_nColorMode = ueye.IS_CM_BGRA8_PACKED # RGB32 self.bytes_per_pixel = int(self.nBitsPerPixel / 8)
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 __init__(self): # Variabeln für Kameraverarbeitung self.h_cam = ueye.HIDS(0) self.pitch = ueye.INT() self.ColorMode = ueye.IS_CM_BGRA8_PACKED self.nBitsPerPixel = ueye.INT(32) self.bytes_per_pixel = int(self.nBitsPerPixel / 8) self.pitch = ueye.INT() self.pcImageMemory = ueye.c_mem_p() self.rectAOI = ueye.IS_RECT() self.MemID = ueye.int() self.width = None self.height = None self.dst = None self.path_images = os.path.dirname(os.path.abspath( sys.argv[0])) + "/images/" # laden der intrinsischen Kalibriermatrix self.load_calibration_config() # Variabeln zur Farberkennung blue_lower = [50, 0, 0] blue_upper = [255, 75, 75] red_lower = [0, 0, 100] red_upper = [50, 50, 255] green_lower = [0, 75, 50] green_upper = [50, 255, 150] self.blue_boundaries = [(blue_lower, blue_upper)] self.red_boundaries = [(red_lower, red_upper)] self.green_boundaries = [(green_lower, green_upper)] # Variablen zur Positionsbestimmung self.found_blue_container = False self.found_red_container = False self.found_green_container = False self.qr_centres = [] self.world_points = [] self.localization_qr_codes = [] self.world_localization_qr_codes = [] self.results = 0 # Farbbereiche self.blue = Color(self.blue_boundaries, "blue") self.red = Color( self.red_boundaries, "red", ) self.green = Color(self.green_boundaries, "green")
def __device_feature(self, value=1): param = ueye.INT(int(value)) nRet = ueye.is_DeviceFeature(self.cam, ueye.IS_DEVICE_FEATURE_CMD_SET_LOG_MODE, param, ueye.sizeof(param)) if nRet != ueye.IS_SUCCESS: raise RuntimeError("IS_DEVICE_FEATURE_CMD_SET_LOG_MODE failed")
def _allocate_memory(self): # Allocates memory on the PC and camera # 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._cam, self._nBitsPerPixel, self._m_nColorMode) self._bytes_per_pixel = self._nBitsPerPixel / 8 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 = self._nBitsPerPixel / 8 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 = self._nBitsPerPixel / 8 else: # for monochrome camera models use Y8 mode self._m_nColorMode = ueye.IS_CM_MONO8 self._nBitsPerPixel = ueye.INT(8) self._bytes_per_pixel = self._nBitsPerPixel / 8 # allocate memory for an image err = ueye.is_AllocImageMem( self._cam, self._width, self._height, self._nBitsPerPixel, self._ppc_img_mem, self._mem_id, ) if err != ueye.IS_SUCCESS: raise CameraException(self._cam, 'ueye>_allocate_memory>', err) # make the image memory 'active' err = ueye.is_SetImageMem(self._cam, self._ppc_img_mem, self._mem_id) if err != ueye.IS_SUCCESS: raise CameraException(self._cam, 'ueye>_allocate_memory>', err)
def __init__(self, graphic=None, mainf=None): """ Constructor. """ self.camera = False self.graphic = graphic self.mainf = mainf self.detected_devices = {} self.hid = ueye.HIDS() self.sinfo = ueye.SENSORINFO() self.hwnd = ueye.HWND() self.width = None self.height = None self.psize = None self.bitspixel = ueye.INT(24) self.bytesppixel = int(self.bitspixel/8) self.ppcImgMem = ueye.c_mem_p() self.MemID = ueye.int() self.colorm = ueye.INT() self.pitch = ueye.INT() self.rect = ueye.IS_RECT() self.maxExp = ueye.double() self.minExp = ueye.double() self.Exp = ueye.double() self.nRet = None try: self.hid = ueye.HIDS() self.sinfo = ueye.SENSORINFO() self.hwnd = ueye.HWND() self.width = ueye.INT() self.height = ueye.INT() self.psize = None self.bitspixel = ueye.INT(24) self.ppcImgMem = ueye.c_mem_p() self.pid = ueye.INT() self.MemID = ueye.INT() self.colorm = ueye.INT() self.pitch = ueye.INT() self.rect = ueye.IS_RECT() except: return
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 __init__(self): rospy.init_node("coordinates_publisher") self.coordinates_pub = rospy.Publisher("/coordinates", Coordinates, queue_size=1) self.coordinates_msg = Coordinates() self.h_cam = ueye.HIDS(0) self.pitch = ueye.INT() self.ColorMode = ueye.IS_CM_BGRA8_PACKED self.nBitsPerPixel = ueye.INT(32) self.bytes_per_pixel = int(self.nBitsPerPixel / 8) self.pitch = ueye.INT() self.pcImageMemory = ueye.c_mem_p() self.rectAOI = ueye.IS_RECT() self.MemID = ueye.int() self.width = None self.height = None self.dst = None self.load_calibration_config() self.found_container = False self.contours_rectangle = [] blue_lower = [51, 0, 0] blue_upper = [255, 62, 62] self.boundaries = [(blue_lower, blue_upper)] self.cX = None self.cY = None self.cX_container = None self.cY_container = None self.container_world_position = [] self.ball_position = [] self.container_position = [] self.qr_centres = [] self.world_points = [] self.qr_codes = None self.image_points_of_qr_codes = None self.localization_qr_codes = [] self.world_localization_qr_codes = [] self.increment = 0.25
def initialize(self): self.hcam = ueye.HIDS(self.cam_num) 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) # 8 bit for monochrome 24 for color self.channels = 3 # 3: for color mode(RGB); 1 channel for monochrome self.m_nColorMode = ueye.INT(24) # Y8/RGB16/RGB24/REG32 self.bytes_per_pixel = int(self.nBitsPerPixel / 8) self.ret = ueye.is_InitCamera(self.hcam, None) if self.ret != ueye.IS_SUCCESS: print("is_InitCamera ERROR") self.setAOI() self.setmemory() self.acquireimage()
def __get_color_mode(self): # Set the right color mode if int.from_bytes(self.sensor_info.nColorMode.value, byteorder='big') == ueye.IS_COLORMODE_BAYER: ueye.is_GetColorDepth(self.cam, self.bits_per_pixel, self.color_mode) self.bytes_per_pixel = int(self.bits_per_pixel / 8) print("IS_COLORMODE_BAYER: ", ) print("\tcolor_mode: \t\t", self.color_mode) print("\tnBitsPerPixel: \t\t", self.bits_per_pixel) print("\tbytes_per_pixel: \t\t", self.bytes_per_pixel) print() elif int.from_bytes(self.sensor_info.nColorMode.value, byteorder='big') == ueye.IS_COLORMODE_CBYCRY: # for color camera models use RGB32 mode self.color_mode = ueye.IS_CM_BGRA8_PACKED self.bits_per_pixel = ueye.INT(32) self.bytes_per_pixel = int(self.bits_per_pixel / 8) print("IS_COLORMODE_CBYCRY: ", ) print("\tcolor_mode: \t\t", self.color_mode) print("\tnBitsPerPixel: \t\t", self.bits_per_pixel) print("\tbytes_per_pixel: \t\t", self.bytes_per_pixel) print() elif int.from_bytes(self.sensor_info.nColorMode.value, byteorder='big') == ueye.IS_COLORMODE_MONOCHROME: # for color camera models use RGB32 mode self.color_mode = ueye.IS_CM_MONO10 self.bits_per_pixel = ueye.INT(16) self.bytes_per_pixel = int(self.bits_per_pixel / 8) print("IS_COLORMODE_MONOCHROME: ", ) print("\tcolor_mode: \t\t", self.color_mode) print("\tnBitsPerPixel: \t\t", self.bits_per_pixel) print("\tbytes_per_pixel: \t\t", self.bytes_per_pixel) print() else: self.color_mode = ueye.IS_CM_MONO8 self.bits_per_pixel = ueye.INT(8) self.bytes_per_pixel = int(self.bits_per_pixel / 8)
def return_devices(self, variable): cam_num = ueye.INT() ueye.is_GetNumberOfCameras(cam_num) for i in range(cam_num.value): hid = ueye.HIDS(cam_num) s = ueye.is_InitCamera(self.hid, self.hwnd) r = ueye.is_GetSensorInfo(self.hid, self.sinfo) sname = self.sinfo.strSensorName.decode('UTF-8') self.detected_devices[sname] = i + 1 variable.insert('end', sname) ueye.is_ExitCamera(self.hid)
def __init__(self): super().__init__() 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( 16) # take 8 bits per pixel for monochrome self.m_nColorMode = ueye.INT() # Y8/RGB16/RGB24/REG32 self.bytes_per_pixel = ueye.INT() self.width = None self.height = None self.data = None self.data1 = None self.data2 = None self.flag = True self.autoParameter = ctypes.c_int(ueye.IS_AUTOPARAMETER_ENABLE)
def connect_device(self, name): """ Connect to camera specified by name. """ cam_num = self.detected_devices[name] cam_num = ueye.INT(cam_num) ueye.is_GetNumberOfCameras(cam_num) s = ueye.is_InitCamera(self.hid, self.hwnd) r = ueye.is_GetSensorInfo(self.hid, self.sinfo) self.configure_device() self.camera = True
def connect_device(self, variable): if not variable.curselection(): messagebox.showinfo(title='Error', message='No' + 'device selected!') return index = variable.curselection()[0] name = variable.get(index) cam_num = self.detected_devices[name] cam_num = ueye.INT(cam_num) ueye.is_GetNumberOfCameras(cam_num) s = ueye.is_InitCamera(self.hid, self.hwnd) r = ueye.is_GetSensorInfo(self.hid, self.sinfo) self.configure_device() self.configure_graph() self.camera = True
def _allocate_memory(self): """ Allocates memory on the PC and camera """ # init c-values self._c_width = pue.INT(self._width) self._c_height = pue.INT(self._height) self._c_pixel_bits = pue.INT(self._color_mode.bits_per_pixel) self._bytes_per_pixel = self._color_mode.bits_per_pixel / 8 # the starting memory address for the image, will be returned self._ppc_img_mem = pue.c_mem_p() # the ID for the allocated image, will be returned self._mem_id = pue.INT() # allocate memory for an image err = pue.is_AllocImageMem( self._cam, self._c_width, self._c_height, self._c_pixel_bits, self._ppc_img_mem, self._mem_id, ) if err != pue.IS_SUCCESS: raise CameraException(self._cam, 'ueye>_allocate_memory>', err) # make the image memory 'active' err = pue.is_SetImageMem(self._cam, self._ppc_img_mem, self._mem_id) if err != pue.IS_SUCCESS: raise CameraException(self._cam, 'ueye>_allocate_memory>', err) # create an array in python to which to copy the image self.image_data = np.zeros( (self._height, self._width, self._color_mode.channels), dtype=self._color_mode.dtype, )
def __init__(self, camID): super().__init__() # Define the variables that will be used to retrieve the properties # of the camera (generic dictionnaries from ueye) # ----------------------------------------------- self.hcam = ueye.HIDS( camID ) # 0 for the first available camera - 1-254 when we already have a specified ID self.sensor_info = ueye.SENSORINFO() self.cam_info = ueye.CAMINFO() self.rectAOI = ueye.IS_RECT() self.pcImageMemory = ueye.c_mem_p() self.MemID = ueye.int() self.pitch = ueye.INT()
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 initialize_modes(self): ''' Enables live video mode. Enables queue mode. Sets: self.pitch ''' # Activates the camera's live video mode (free run mode) nRet = ueye.is_CaptureVideo(self.input, ueye.IS_DONT_WAIT) if nRet != ueye.IS_SUCCESS: log.error("is_CaptureVideo ERROR") # Enables the queue mode for existing image memory sequences self.pitch = ueye.INT() nRet = ueye.is_InquireImageMem(self.input, self.mem_image, self.mem_id, self.width, self.height, self.bits_per_pixel, self.pitch) if nRet != ueye.IS_SUCCESS: log.error("is_InquireImageMem ERROR")
def start_video_capture(self): # Activates the camera's live video mode (free run mode) err = pue.is_CaptureVideo(self._cam, pue.IS_DONT_WAIT) if err != pue.IS_SUCCESS: raise CameraException(self._cam, 'ueye>video_capture', err, False) self._pitch = pue.INT() err = pue.is_InquireImageMem( self._cam, self._ppc_img_mem, self._mem_id, self._c_width, self._c_height, self._c_pixel_bits, self._pitch, ) if err != pue.IS_SUCCESS: raise CameraException(self._cam, 'ueye>video_capture', err, False) self._video_capture = True
def return_devices(self): """ Return list of connected camera. """ varOut = [] cam_num = ueye.INT() ueye.is_GetNumberOfCameras(cam_num) for i in range(cam_num.value): hid = ueye.HIDS(cam_num) s = ueye.is_InitCamera(self.hid, self.hwnd) r = ueye.is_GetSensorInfo(self.hid, self.sinfo) sname = self.sinfo.strSensorName.decode('UTF-8') self.detected_devices[sname] = i+1 varOut.append(sname) ueye.is_ExitCamera(self.hid) return varOut