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 __init__(self, graphic=None, mainf=None): self.camera = False self.graphic = graphic self.mainf = mainf self.detected_devices = {} 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.bytesppixel = int(self.bitspixel / 8) 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() self.maxExp = ueye.double() self.minExp = ueye.double() self.Exp = ueye.double() except: return
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 getSensorInfo(self): self.sensorInfo=ueye.SENSORINFO() if ueye.is_GetSensorInfo(self.hcam, self.sensorInfo): self.status=True _logger.error("Error retriving sensor information.") return True return False
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): 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 __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 __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 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 __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 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, 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 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 __init__(self, device_number=0, nbits=8): Camera.__init__(self) self.initialized = False if nbits not in (8, 10, 12): raise RuntimeError( 'Supporting only 8, 10 or 12 bit depth, requested %d bit' % (nbits)) self.nbits = nbits self.h = ueye.HIDS(device_number) self.check_success(ueye.is_InitCamera(self.h, None)) self.initialized = True # get chip size sensor_info = ueye.SENSORINFO() self.check_success(ueye.is_GetSensorInfo(self.h, sensor_info)) self._chip_size = (sensor_info.nMaxWidth, sensor_info.nMaxHeight) self.sensor_type = sensor_info.strSensorName.decode().split( 'x')[0] + 'x' self.SetROI(0, 0, self._chip_size[0], self._chip_size[1]) self.check_success( ueye.is_SetColorMode(self.h, getattr(ueye, 'IS_CM_MONO%d' % self.nbits))) self.SetAcquisitionMode(self.MODE_CONTINUOUS) self._buffers = [] self.full_buffers = queue.Queue() self.free_buffers = None self.n_full = 0 self.n_accum = 1 self.n_accum_current = 0 self.SetIntegTime(0.1) self.Init()
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 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
# The sole purpose of this program is to show one of the simplest ways to interact with an IDS camera via the uEye API. # (XS cameras are not supported) #--------------------------------------------------------------------------------------------------------------------------------------- #Libraries from pyueye import ueye import numpy as np import cv2 import sys #--------------------------------------------------------------------------------------------------------------------------------------- #Variables 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(8) #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) #--------------------------------------------------------------------------------------------------------------------------------------- print("START") print() # Starts the driver and establishes the connection to the camera
def Cameras_stream(): #Variables hCam1 = ueye.HIDS(1) #0: first available camera; 1-254: The camera with the specified camera ID hCam2 = ueye.HIDS(2) #0: first available camera; 1-254: The camera with the specified camera ID sInfo = ueye.SENSORINFO() cInfo = ueye.CAMINFO() pcImageMemory = ueye.c_mem_p() pcImageMemory2 = ueye.c_mem_p() MemID = ueye.int() MemID2 = ueye.int() rectAOI = ueye.IS_RECT() pitch = ueye.INT() nBitsPerPixel = ueye.INT(24) #24: bits per pixel for color mode; take 8 bits per pixel for monochrome channels = 3 #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) #--------------------------------------------------------------------------------------------------------------------------------------- # print("START") # print() # Starts the driver and establishes the connection to the camera nRet1 = ueye.is_InitCamera(hCam1, None) if nRet1 != ueye.IS_SUCCESS: pass # print("is_InitCamera ERROR") else: print(f'Camera 1 : SUCCESS') nRet2 = ueye.is_InitCamera(hCam2, None) if nRet2 != ueye.IS_SUCCESS: pass # print("is_InitCamera ERROR") else: print(f'Camera 2 : SUCCESS') # Reads out the data hard-coded in the non-volatile camera memory and writes it to the data structure that cInfo points to nRet1 = ueye.is_GetCameraInfo(hCam1, cInfo) if nRet1 != ueye.IS_SUCCESS: print("is_GetCameraInfo ERROR") nRet2 = ueye.is_GetCameraInfo(hCam2, cInfo) if nRet2 != ueye.IS_SUCCESS: print("is_GetCameraInfo ERROR") # You can query additional information about the sensor type used in the camera nRet1 = ueye.is_GetSensorInfo(hCam1, sInfo) if nRet1 != ueye.IS_SUCCESS: print("is_GetSensorInfo ERROR") nRet1 = ueye.is_ResetToDefault( hCam1) if nRet1 != ueye.IS_SUCCESS: print("is_ResetToDefault ERROR") # Set display mode to DIB nRet1 = ueye.is_SetDisplayMode(hCam1, ueye.IS_SET_DM_DIB) nRet2 = ueye.is_SetDisplayMode(hCam2, ueye.IS_SET_DM_DIB) # Set the right color mode if int.from_bytes(sInfo.nColorMode.value, byteorder='big') == ueye.IS_COLORMODE_BAYER: # setup the color depth to the current windows setting ueye.is_GetColorDepth(hCam1, nBitsPerPixel, m_nColorMode) bytes_per_pixel = int(nBitsPerPixel / 8) print("IS_COLORMODE_BAYER: ", ) print("\tm_nColorMode: \t\t", m_nColorMode) print("\tnBitsPerPixel: \t\t", nBitsPerPixel) print("\tbytes_per_pixel: \t\t", bytes_per_pixel) print() elif int.from_bytes(sInfo.nColorMode.value, byteorder='big') == ueye.IS_COLORMODE_CBYCRY: # for color camera models use RGB32 mode m_nColorMode = ueye.IS_CM_BGRA8_PACKED nBitsPerPixel = ueye.INT(32) bytes_per_pixel = int(nBitsPerPixel / 8) print("IS_COLORMODE_CBYCRY: ", ) print("\tm_nColorMode: \t\t", m_nColorMode) print("\tnBitsPerPixel: \t\t", nBitsPerPixel) print("\tbytes_per_pixel: \t\t", bytes_per_pixel) print() elif int.from_bytes(sInfo.nColorMode.value, byteorder='big') == ueye.IS_COLORMODE_MONOCHROME: # for color camera models use RGB32 mode m_nColorMode = ueye.IS_CM_MONO8 nBitsPerPixel = ueye.INT(8) bytes_per_pixel = int(nBitsPerPixel / 8) print("IS_COLORMODE_MONOCHROME: ", ) print("\tm_nColorMode: \t\t", m_nColorMode) print("\tnBitsPerPixel: \t\t", nBitsPerPixel) print("\tbytes_per_pixel: \t\t", bytes_per_pixel) print() else: # for monochrome camera models use Y8 mode m_nColorMode = ueye.IS_CM_MONO8 nBitsPerPixel = ueye.INT(8) bytes_per_pixel = int(nBitsPerPixel / 8) print("else") # Can be used to set the size and position of an "area of interest"(AOI) within an image nRet1 = ueye.is_AOI(hCam1, ueye.IS_AOI_IMAGE_GET_AOI, rectAOI, ueye.sizeof(rectAOI)) if nRet1 != ueye.IS_SUCCESS: print("is_AOI ERROR") width = rectAOI.s32Width height = rectAOI.s32Height # Prints out some information about the camera and the sensor print("Camera model:\t\t", sInfo.strSensorName.decode('utf-8')) print("Camera serial no.:\t", cInfo.SerNo.decode('utf-8')) print("Maximum image width:\t", width) print("Maximum image height:\t", height) print() #--------------------------------------------------------------------------------------------------------------------------------------- # Allocates an image memory for an image having its dimensions defined by width and height and its color depth defined by nBitsPerPixel nRet1 = ueye.is_AllocImageMem(hCam1, width, height, nBitsPerPixel, pcImageMemory, MemID) if nRet1 != ueye.IS_SUCCESS: print("is_AllocImageMem ERROR") else: # Makes the specified image memory the active memory nRet = ueye.is_SetImageMem(hCam1, pcImageMemory, MemID) if nRet != ueye.IS_SUCCESS: print("is_SetImageMem ERROR") else: # Set the desired color mode nRet = ueye.is_SetColorMode(hCam1, m_nColorMode) if nRet1 != ueye.IS_SUCCESS: print("is_AllocImageMem ERROR") else: # Makes the specified image memory the active memory nRet = ueye.is_SetImageMem(hCam1, pcImageMemory, MemID) if nRet != ueye.IS_SUCCESS: print("is_SetImageMem ERROR") else: # Set the desired color mode nRet = ueye.is_SetColorMode(hCam2, m_nColorMode) # Allocates an image memory for an image having its dimensions defined by width and height and its color depth defined by nBitsPerPixel nRet = ueye.is_AllocImageMem(hCam2, width, height, nBitsPerPixel, pcImageMemory2, MemID2) if nRet != ueye.IS_SUCCESS: print("is_AllocImageMem ERROR") else: # Makes the specified image memory the active memory nRet = ueye.is_SetImageMem(hCam2, pcImageMemory2, MemID2) if nRet != ueye.IS_SUCCESS: print("is_SetImageMem ERROR") else: # Set the desired color mode nRet = ueye.is_SetColorMode(hCam2, m_nColorMode) nRet = ueye.is_AllocImageMem(hCam2, width, height, nBitsPerPixel, pcImageMemory2, MemID2) if nRet != ueye.IS_SUCCESS: print("is_AllocImageMem ERROR") else: # Makes the specified image memory the active memory nRet = ueye.is_SetImageMem(hCam2, pcImageMemory2, MemID2) if nRet != ueye.IS_SUCCESS: print("is_SetImageMem ERROR") else: # Set the desired color mode nRet = ueye.is_SetColorMode(hCam2, m_nColorMode) # Activates the camera's live video mode (free run mode) nRet = ueye.is_CaptureVideo(hCam1, ueye.IS_DONT_WAIT) if nRet != ueye.IS_SUCCESS: print("is_CaptureVideo ERROR") nRet = ueye.is_CaptureVideo(hCam2, ueye.IS_DONT_WAIT) if nRet != ueye.IS_SUCCESS: print("is_CaptureVideo ERROR") # Enables the queue mode for existing image memory sequences nRet = ueye.is_InquireImageMem(hCam1, pcImageMemory, MemID, width, height, nBitsPerPixel, pitch) if nRet != ueye.IS_SUCCESS: print("is_InquireImageMem ERROR") else: print("Press q to leave the programm") nRet2 = ueye.is_InquireImageMem(hCam2, pcImageMemory2, MemID, width, height, nBitsPerPixel, pitch) if nRet2 != ueye.IS_SUCCESS: print("is_InquireImageMem ERROR") else: print("Press q to leave the programm") #--------------------------------------------------------------------------------------------------------------------------------------- # Continuous image display while(nRet == ueye.IS_SUCCESS) and (nRet2 == 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, height, nBitsPerPixel, pitch, copy=False) array2 = ueye.get_data(pcImageMemory2, width, height, nBitsPerPixel, pitch, copy=False) # bytes_per_pixel = int(nBitsPerPixel / 8) # ...reshape it in an numpy array... frame = np.reshape(array,(height.value, width.value, bytes_per_pixel)) frame2 = np.reshape(array2,(height.value, width.value, bytes_per_pixel)) # ...resize the image by a half # frame = cv2.resize(frame,(0,0),fx=0.5, fy=0.5) #--------------------------------------------------------------------------------------------------------------------------------------- #Include image data processing here #--------------------------------------------------------------------------------------------------------------------------------------- #...and finally display it if __name__=="__main__": cv2.imshow("SimpleLive_Python_uEye_OpenCV", frame) cv2.imshow("SimpleLive_Python_uEye_OpenCV 2", frame2) # Press q if you want to end the loop if cv2.waitKey(1) & 0xFF == ord('q'): break #--------------------------------------------------------------------------------------------------------------------------------------- # Releases an image memory that was allocated using is_AllocImageMem() and removes it from the driver management ueye.is_FreeImageMem(hCam1, pcImageMemory, MemID) ueye.is_FreeImageMem(hCam2, pcImageMemory2, MemID2) # Disables the hCam camera handle and releases the data structures and memory areas taken up by the uEye camera ueye.is_ExitCamera(hCam1) ueye.is_ExitCamera(hCam2) # Destroys the OpenCv windows cv2.destroyAllWindows() print() print("END")
def __init__(self, deviceID): self.deviceID = deviceID DeviceID = self.deviceID | ueye.IS_USE_DEVICE_ID self.hCam = ueye.HIDS(DeviceID) self.sensorInfo = ueye.SENSORINFO() self.camInfo = ueye.CAMINFO() self.pcImageMemory = ueye.c_mem_p() self.MemID = ueye.int() rectAOI = ueye.IS_RECT() self.pitch = ueye.INT() self.nBitsPerPixel = 10 #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.IS_CM_MONO10 # Y8/RGB16/RGB24/REG32 bytes_per_pixel = int(self.nBitsPerPixel / 8) #nColorMode = IS_CM_MONO10; #self.nBitsPerPixel = 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 self.camInfo points to nRet = ueye.is_GetCameraInfo(self.hCam, self.camInfo) 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.sensorInfo) 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) if int.from_bytes(self.sensorInfo.nColorMode.value, byteorder='big') == ueye.IS_COLORMODE_MONOCHROME: # for color camera models use RGB32 mode m_nColorMode = ueye.IS_CM_MONO10 self.nBitsPerPixel = ueye.INT(10) self.bytes_per_pixel = int(self.nBitsPerPixel / 7) + 1 print("IS_COLORMODE_MONOCHROME: ", ) print("\tm_nColorMode: \t\t", 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 m_nColorMode = ueye.IS_CM_MONO8 self.nBitsPerPixel = ueye.INT(8) self.bytes_per_pixel = int(self.nBitsPerPixel / 8) + 1 print("else") # 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, rectAOI, ueye.sizeof(rectAOI)) if nRet != ueye.IS_SUCCESS: print("is_AOI ERROR") self.width = rectAOI.s32Width self.height = rectAOI.s32Height # Prints out some information about the camera and the sensor print("Camera model:\t\t", self.sensorInfo.strSensorName.decode('utf-8')) print("Camera serial no.:\t", self.camInfo.SerNo.decode('utf-8')) print("Maximum image self.width:\t", self.width) print("Maximum image self.height:\t", self.height) print() #--------------------------------------------------------------------------------------------------------------------------------------- # Allocates an image memory for an image having its dimensions defined by self.width # and self.height and its color depth defined by self.nBitsPerPixel nRet = ueye.is_AllocImageMem(self.hCam, self.width, self.height, self.nBitsPerPixel, self.pcImageMemory, self.MemID) if nRet != ueye.IS_SUCCESS: print("is_AllocImageMem ERROR") else: # Makes the specified image memory the active memory nRet = ueye.is_SetImageMem(self.hCam, self.pcImageMemory, self.MemID) if nRet != ueye.IS_SUCCESS: print("is_SetImageMem ERROR") else: # Set the desired color mode nRet = ueye.is_SetColorMode(self.hCam, m_nColorMode)
def __init__(self, pathToParameterSets, fps): self.hCam = ueye.HIDS(0) 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) self.channels = 3 self.m_nColorMode = ueye.INT() self.bytes_per_pixel = int(self.nBitsPerPixel / 8) self.timeStampsFilePath = "times.txt" self.timeStampsFile = open(self.timeStampsFilePath, 'w') self.FPS = ctypes.c_double(int(fps)) self.pathToParameterSets = pathToParameterSets 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") if 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: ", self.m_nColorMode) 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() #loading parameter set file pParam = ueye.wchar_p() pParam.value = self.pathToParameterSets nRet = ueye.is_ParameterSet(self.hCam, ueye.IS_PARAMETERSET_CMD_LOAD_FILE, pParam, 0) if nRet != ueye.IS_SUCCESS: print("Setting parameter set error") #setting fps newFPS = ctypes.c_double(0) ueye.is_SetFrameRate(self.hCam, self.FPS, newFPS) if nRet != ueye.IS_SUCCESS: print("Setting fps ERROR") else: print("FPS is: ", newFPS) # 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()
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 ueye_get_sensor_info(hcam) -> ueye.SENSORINFO: sensor_info = ueye.SENSORINFO() err = ueye.is_GetSensorInfo(hcam, sensor_info) _throw_if_err(hcam, err) return sensor_info
def cameraInit(load_parameters_EEPROM=load_parameters_EEPROM): """Initializes the camera with the correct parameters""" global mBuff, bpp, pitch, channels, bytes_per_pixel, tt hCam = ueye.HIDS(0) # 0: first available camera; 1-254: The camera with the specified camera ID sInfo = ueye.SENSORINFO() cInfo = ueye.CAMINFO() # Starts the driver and establishes the connection to the camera nRet = ueye.is_InitCamera(hCam, None) logger.debug("Setting Camera Data") if nRet != ueye.IS_SUCCESS: logger.info("is_InitCamera ERROR, camera not connected?") return -1, 0 # 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: logger.info("is_GetCameraInfo ERROR") # You can query additional information about the sensor type used in the camera nRet = ueye.is_GetSensorInfo(hCam, sInfo) if nRet != ueye.IS_SUCCESS: logger.info("is_GetSensorInfo ERROR") nRet = ueye.is_ResetToDefault(hCam) if nRet != ueye.IS_SUCCESS: logger.info("is_ResetToDefault ERROR") # Set display mode to DIB nRet = ueye.is_SetDisplayMode(hCam, ueye.IS_SET_DM_DIB) if int.from_bytes(sInfo.nColorMode.value, byteorder='big') == ueye.IS_COLORMODE_MONOCHROME: # for color camera models use RGB32 mode logger.info("Setting colormode to black and white") m_nColorMode = ueye.IS_CM_MONO8 nBitsPerPixel = ueye.INT(8) bytes_per_pixel = int(nBitsPerPixel / 8) logger.info(f"IS_COLORMODE_MONOCHROME: ") logger.info(f"\tm_nColorMode: \t\t{m_nColorMode}") logger.info(f"\tnBitsPerPixel: \t\t{nBitsPerPixel}") logger.info(f"\tbytes_per_pixel: \t\t {bytes_per_pixel}") if load_parameters_EEPROM: logger.debug("Loading parameters from EEPROM") nullint = ueye._value_cast(0, ueye.ctypes.c_uint) rvv = ueye.is_ParameterSet(hCam, ueye.IS_PARAMETERSET_CMD_LOAD_EEPROM, nullint, nullint) # Can be used to set the size and position of an "area of interest"(AOI) within an image nRet = ueye.is_AOI(hCam, ueye.IS_AOI_IMAGE_GET_AOI, rectAOI, ueye.sizeof(rectAOI)) if nRet != ueye.IS_SUCCESS: logger.error("is_AOI ERROR") width = rectAOI.s32Width height = rectAOI.s32Height # Prints out some information about the camera and the sensor logger.info(f"Camera model:\t\t {sInfo.strSensorName.decode('utf-8')}") logger.info(f"Camera serial no.:\t {cInfo.SerNo.decode('utf-8')}") logger.info(f"Maximum image width:\t {width}") logger.info(f"Maximum image height:\t {height}") # --------------------------------------------------------------------------------------------------------------------------------------- # Allocates an image memory for an image having its dimensions defined by width and height and its color depth defined by nBitsPerPixel nRet = ueye.is_AllocImageMem(hCam, width, height, nBitsPerPixel, pcImageMemory, MemID) if nRet != ueye.IS_SUCCESS: logger.info("is_AllocImageMem ERROR") else: # Makes the specified image memory the active memory nRet = ueye.is_SetImageMem(hCam, pcImageMemory, MemID) if nRet != ueye.IS_SUCCESS: logger.info("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) nRet = ueye.is_CaptureVideo(hCam, ueye.IS_DONT_WAIT) if nRet != ueye.IS_SUCCESS: logger.info("is_CaptureVideo ERROR") # 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: logger.info("is_InquireImageMem ERROR") else: logger.info("Press q to leave the programm") # --------------------------------------------------------------------------------------------------------------------------------------- # shutter = int.from_bytes(sInfo.bGlobShutter.value, byteorder='big') # rvv = ueye.is_ParameterSet(hCam,ueye.IS_PARAMETERSET_CMD_LOAD_EEPROM,nullint,nullint) # Continuous image display tt = ueye.is_AOI(hCam, ueye.IS_AOI_IMAGE_GET_AOI, rect_aoi, ueye.sizeof(rect_aoi)) width = rect_aoi.s32Width.value height = rect_aoi.s32Height.value for i in range(numBuffers): buff = ImageBuffer() ueye.is_AllocImageMem(hCam, width, height, bpp, buff.mem_ptr, buff.mem_id) ueye.is_AddToSequence(hCam, buff.mem_ptr, buff.mem_id) buffs.append(buff) rvIQ = ueye.is_InitImageQueue(hCam, 0) nRet = ueye.IS_SUCCESS ret = ueye.is_WaitForNextImage(hCam, 100, mBuff.mem_ptr, mBuff.mem_id) rr = ueye.is_GetActSeqBuf(hCam, buffCurrent.mem_id, buffLast.mem_ptr, buffLast.mem_ptr) if (not ret): # cnt+=1 array = ueye.get_data(mBuff.mem_ptr, width, height, bpp, pitch, copy=True) ueye.is_UnlockSeqBuf(hCam, mBuff.mem_id, mBuff.mem_ptr) return nRet, hCam
def __init__(self, cam_num=0): self.name = f"IDS Camera {cam_num:}" self.hCam = ueye.HIDS(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 ) # 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) # Starts the driver and establishes the connection to the camera nRet = ueye.is_InitCamera(self.hCam, None) if nRet != ueye.IS_SUCCESS: raise RuntimeError(f"is_InitCamera ERROR {nRet:}") # 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: raise RuntimeError("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: raise RuntimeError("is_GetSensorInfo ERROR") nRet = ueye.is_ResetToDefault(self.hCam) if nRet != ueye.IS_SUCCESS: raise RuntimeError("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.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") # 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() nRet = ueye.is_AllocImageMem( self.hCam, self.width, self.height, self.nBitsPerPixel, self.pcImageMemory, self.MemID, ) if nRet != ueye.IS_SUCCESS: print("is_AllocImageMem ERROR") else: # Makes the specified image memory the active memory nRet = ueye.is_SetImageMem(self.hCam, self.pcImageMemory, self.MemID) if nRet != ueye.IS_SUCCESS: print("is_SetImageMem ERROR") else: # Set the desired color mode nRet = ueye.is_SetColorMode(self.hCam, self.m_nColorMode)
def main(): from pyueye import ueye import numpy as np import cv2 import sys import os import tensorflow as tf import SoundTheAlarm import time # --------------------------------------------------------------------------------------------------------------------------------------- # This is needed since the notebook is stored in the object_detection folder. sys.path.append("..") # Import utilites from utils import label_map_util from utils import visualization_utils as vis_util # Name of the directory containing the object detection module we're using MODEL_NAME = 'inference_graph' # Grab path to current working directory CWD_PATH = os.getcwd() # Path to frozen detection graph .pb file, which contains the model that is used # for object detection. PATH_TO_CKPT = os.path.join(CWD_PATH, MODEL_NAME, 'frozen_inference_graph.pb') # Path to label map file PATH_TO_LABELS = os.path.join(CWD_PATH, 'training', 'labelmap.pbtxt') # Number of classes the object detector can identify NUM_CLASSES = 3 ## Load the label map. # Label maps map indices to category names, so that when our convolution # network predicts `5`, we know that this corresponds to `king`. # Here we use internal utility functions, but anything that returns a # dictionary mapping integers to appropriate string labels would be fine label_map = label_map_util.load_labelmap(PATH_TO_LABELS) categories = label_map_util.convert_label_map_to_categories(label_map, max_num_classes=NUM_CLASSES, use_display_name=True) category_index = label_map_util.create_category_index(categories) # Load the Tensorflow model into memory. detection_graph = tf.Graph() with detection_graph.as_default(): od_graph_def = tf.GraphDef() with tf.gfile.GFile(PATH_TO_CKPT, 'rb') as fid: serialized_graph = fid.read() od_graph_def.ParseFromString(serialized_graph) tf.import_graph_def(od_graph_def, name='') sess = tf.Session(graph=detection_graph) # Define input and output tensors (i.e. data) for the object detection classifier # Input tensor is the image image_tensor = detection_graph.get_tensor_by_name('image_tensor:0') # Output tensors are the detection boxes, scores, and classes # Each box represents a part of the image where a particular object was detected detection_boxes = detection_graph.get_tensor_by_name('detection_boxes:0') # Each score represents level of confidence for each of the objects. # The score is shown on the result image, together with the class label. detection_scores = detection_graph.get_tensor_by_name('detection_scores:0') detection_classes = detection_graph.get_tensor_by_name('detection_classes:0') # Number of objects detected num_detections = detection_graph.get_tensor_by_name('num_detections:0') # Variables 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(24) # 24: bits per pixel for color mode; take 8 bits per pixel for monochrome channels = 3 # 3: channels for color mode(RGB); take 1 channel for monochrome m_nColorMode = ueye.INT() # Y8/RGB16/RGB24/REG32 ueye.is_SetColorMode(hCam, ueye.IS_CM_BGR8_PACKED) bytes_per_pixel = int(nBitsPerPixel / 8) # --------------------------------------------------------------------------------------------------------------------------------------- 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: print("is_GetCameraInfo ERROR") # You can query additional information about the sensor type used in the camera nRet = ueye.is_GetSensorInfo(hCam, sInfo) if nRet != ueye.IS_SUCCESS: print("is_GetSensorInfo ERROR") nRet = ueye.is_ResetToDefault(hCam) if nRet != ueye.IS_SUCCESS: print("is_ResetToDefault ERROR") # Set display mode to DIB nRet = ueye.is_SetDisplayMode(hCam, ueye.IS_SET_DM_DIB) # Set the right color mode if int.from_bytes(sInfo.nColorMode.value, byteorder='big') == ueye.IS_COLORMODE_BAYER: # setup the color depth to the current windows setting ueye.is_GetColorDepth(hCam, nBitsPerPixel, m_nColorMode) bytes_per_pixel = int(nBitsPerPixel / 8) print("IS_COLORMODE_BAYER: ", ) print("\tm_nColorMode: \t\t", m_nColorMode) print("\tnBitsPerPixel: \t\t", nBitsPerPixel) print("\tbytes_per_pixel: \t\t", bytes_per_pixel) print() elif int.from_bytes(sInfo.nColorMode.value, byteorder='big') == ueye.IS_COLORMODE_CBYCRY: # for color camera models use RGB32 mode m_nColorMode = ueye.IS_CM_BGRA8_PACKED nBitsPerPixel = ueye.INT(32) bytes_per_pixel = int(nBitsPerPixel / 8) print("IS_COLORMODE_CBYCRY: ", ) print("\tm_nColorMode: \t\t", m_nColorMode) print("\tnBitsPerPixel: \t\t", nBitsPerPixel) print("\tbytes_per_pixel: \t\t", bytes_per_pixel) print() elif int.from_bytes(sInfo.nColorMode.value, byteorder='big') == ueye.IS_COLORMODE_MONOCHROME: # for color camera models use RGB32 mode m_nColorMode = ueye.IS_CM_MONO8 nBitsPerPixel = ueye.INT(8) bytes_per_pixel = int(nBitsPerPixel / 8) print("IS_COLORMODE_MONOCHROME: ", ) print("\tm_nColorMode: \t\t", m_nColorMode) print("\tnBitsPerPixel: \t\t", nBitsPerPixel) print("\tbytes_per_pixel: \t\t", bytes_per_pixel) print() else: # for monochrome camera models use Y8 mode m_nColorMode = ueye.IS_CM_MONO8 nBitsPerPixel = ueye.INT(8) bytes_per_pixel = int(nBitsPerPixel / 8) print("else") # Can be used to set the size and position of an "area of interest"(AOI) within an image nRet = ueye.is_AOI(hCam, ueye.IS_AOI_IMAGE_GET_AOI, rectAOI, ueye.sizeof(rectAOI)) if nRet != ueye.IS_SUCCESS: print("is_AOI ERROR") width = rectAOI.s32Width height = rectAOI.s32Height # Prints out some information about the camera and the sensor print("Camera model:\t\t", sInfo.strSensorName.decode('utf-8')) print("Camera serial no.:\t", cInfo.SerNo.decode('utf-8')) print("Maximum image width:\t", width) print("Maximum image height:\t", height) print() # --------------------------------------------------------------------------------------------------------------------------------------- # Allocates an image memory for an image having its dimensions defined by width and height and its color depth defined by nBitsPerPixel nRet = ueye.is_AllocImageMem(hCam, width, height, nBitsPerPixel, pcImageMemory, MemID) if nRet != ueye.IS_SUCCESS: print("is_AllocImageMem ERROR") else: # Makes the specified image memory the active memory nRet = ueye.is_SetImageMem(hCam, pcImageMemory, MemID) if nRet != ueye.IS_SUCCESS: 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) 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 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") # -----------------------------------start image loop--------------------------------------------------------------- # Continuous image display 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, height, nBitsPerPixel, pitch, copy=False) # bytes_per_pixel = int(nBitsPerPixel / 8) # ...reshape it in an numpy array... frame = np.reshape(array, (height.value, width.value, bytes_per_pixel)) frame = cv2.cvtColor(frame, cv2.COLOR_GRAY2BGR) # ------------------------------------------network_run--------------------------------------------------------- frame_expanded = np.expand_dims(frame, axis=0) # Perform the actual detection by running the model with the image as input (boxes, scores, classes, num) = sess.run( [detection_boxes, detection_scores, detection_classes, num_detections], feed_dict={image_tensor: frame_expanded}) # print("check this point-2") # Draw the results of the detection (aka 'visualize the results') vis_util.visualize_boxes_and_labels_on_image_array( frame, np.squeeze(boxes), np.squeeze(classes).astype(np.int32), np.squeeze(scores), category_index, use_normalized_coordinates=True, line_thickness=8, min_score_thresh=0.85) counter = [] add = 0 while add < (NUM_CLASSES + 1): counter.append(0) add += 1 element = 0 # i used this loop to configure the alarm for i in classes[0]: # it uses the variables to count how many of each object appear in each image if (scores[0][element]) > 0.85: #=min_score_thresh # use it to feed an alarm detector script based on counter[int(i)] += 1 # what "should" and "shouldn't" appear element += 1 else: break #the break stops from iterating through the entire array, which is uneccessary ####---the alarm protocol---#### #if counter[2] and counter[3]: #if not counter[1]: #SoundTheAlarm.sound_loop() print("number of each class", counter) # All the results have been drawn on the frame, so it's time to display it. frame = cv2.resize(frame, None, fx=0.5, fy=0.5) cv2.destroyAllWindows() # -------------------------------------------------------------------------------------------------------------- # ...and finally display it cv2.imshow("SimpleLive_Python_uEye_OpenCV", frame) # Press q if you want to end the loop if cv2.waitKey(1) & 0xFF == ord('q'): break time.sleep(0.5) # ------------------------------------------------------------------------------------------------------------------ # Releases an image memory that was allocated using is_AllocImageMem() and removes it from the driver management ueye.is_FreeImageMem(hCam, pcImageMemory, MemID) # Disables the hCam camera handle and releases the data structures and memory areas taken up by the uEye camera ueye.is_ExitCamera(hCam) # Destroys the OpenCv windows cv2.destroyAllWindows() print() print("END")
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()
class CameraApi: #Variables 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( 24 ) #24: bits per pixel for color mode; take 8 bits per pixel for monochrome channels = 3 #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) nRet = "" width = rectAOI.s32Width height = rectAOI.s32Height @staticmethod def initialize_camera(): #--------------------------------------------------------------------------------------------------------------------------------------- print("START") print() # Starts the driver and establishes the connection to the camera CameraApi.nRet = ueye.is_InitCamera(CameraApi.hCam, None) if CameraApi.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 CameraApi.nRet = ueye.is_GetCameraInfo(CameraApi.hCam, CameraApi.cInfo) if CameraApi.nRet != ueye.IS_SUCCESS: print("is_GetCameraInfo ERROR") # You can query additional information about the sensor type used in the camera CameraApi.nRet = ueye.is_GetSensorInfo(CameraApi.hCam, CameraApi.sInfo) if CameraApi.nRet != ueye.IS_SUCCESS: print("is_GetSensorInfo ERROR") CameraApi.nRet = ueye.is_ResetToDefault(CameraApi.hCam) if CameraApi.nRet != ueye.IS_SUCCESS: print("is_ResetToDefault ERROR") # Set display mode to DIB CameraApi.nRet = ueye.is_SetDisplayMode(CameraApi.hCam, ueye.IS_SET_DM_DIB) # Set the right color mode if int.from_bytes(CameraApi.sInfo.nColorMode.value, byteorder='big') == ueye.IS_COLORMODE_BAYER: # setup the color depth to the current windows setting ueye.is_GetColorDepth(CameraApi.hCam, CameraApi.nBitsPerPixel, CameraApi.m_nColorMode) CameraApi.bytes_per_pixel = int(CameraApi.nBitsPerPixel / 8) print("IS_COLORMODE_BAYER: ", ) print("\tm_nColorMode: \t\t", CameraApi.m_nColorMode) print("\tnBitsPerPixel: \t\t", CameraApi.nBitsPerPixel) print("\tbytes_per_pixel: \t\t", CameraApi.bytes_per_pixel) print() elif int.from_bytes(CameraApi.sInfo.nColorMode.value, byteorder='big') == ueye.IS_COLORMODE_CBYCRY: # for color camera models use RGB32 mode m_nColorMode = ueye.IS_CM_BGRA8_PACKED nBitsPerPixel = ueye.INT(32) CameraApi.bytes_per_pixel = int(nBitsPerPixel / 8) print("IS_COLORMODE_CBYCRY: ", ) print("\tm_nColorMode: \t\t", m_nColorMode) print("\tnBitsPerPixel: \t\t", nBitsPerPixel) print("\tbytes_per_pixel: \t\t", CameraApi.bytes_per_pixel) print() elif int.from_bytes(CameraApi.sInfo.nColorMode.value, byteorder='big') == ueye.IS_COLORMODE_MONOCHROME: # for color camera models use RGB32 mode m_nColorMode = ueye.IS_CM_MONO8 nBitsPerPixel = ueye.INT(8) CameraApi.bytes_per_pixel = int(nBitsPerPixel / 8) print("IS_COLORMODE_MONOCHROME: ", ) print("\tm_nColorMode: \t\t", m_nColorMode) print("\tnBitsPerPixel: \t\t", nBitsPerPixel) print("\tbytes_per_pixel: \t\t", CameraApi.bytes_per_pixel) print() else: # for monochrome camera models use Y8 mode m_nColorMode = ueye.IS_CM_MONO8 nBitsPerPixel = ueye.INT(8) CameraApi.bytes_per_pixel = int(nBitsPerPixel / 8) print("else") # Can be used to set the size and position of an "area of interest"(AOI) within an image CameraApi.nRet = ueye.is_AOI(CameraApi.hCam, ueye.IS_AOI_IMAGE_GET_AOI, CameraApi.rectAOI, ueye.sizeof(CameraApi.rectAOI)) if CameraApi.nRet != ueye.IS_SUCCESS: print("is_AOI ERROR") CameraApi.width = CameraApi.rectAOI.s32Width CameraApi.height = CameraApi.rectAOI.s32Height # Prints out some information about the camera and the sensor print("Camera model:\t\t", CameraApi.sInfo.strSensorName.decode('utf-8')) print("Camera serial no.:\t", CameraApi.cInfo.SerNo.decode('utf-8')) print("Maximum image width:\t", CameraApi.width) print("Maximum image height:\t", CameraApi.height) print() #--------------------------------------------------------------------------------------------------------------------------------------- # Allocates an image memory for an image having its dimensions defined by width and height and its color depth defined by nBitsPerPixel CameraApi.nRet = ueye.is_AllocImageMem(CameraApi.hCam, CameraApi.width, CameraApi.height, CameraApi.nBitsPerPixel, CameraApi.pcImageMemory, CameraApi.MemID) if CameraApi.nRet != ueye.IS_SUCCESS: print("is_AllocImageMem ERROR") else: # Makes the specified image memory the active memory CameraApi.nRet = ueye.is_SetImageMem(CameraApi.hCam, CameraApi.pcImageMemory, CameraApi.MemID) if CameraApi.nRet != ueye.IS_SUCCESS: print("is_SetImageMem ERROR") else: # Set the desired color mode CameraApi.nRet = ueye.is_SetColorMode(CameraApi.hCam, CameraApi.m_nColorMode) # Activates the camera's live video mode (free run mode) CameraApi.nRet = ueye.is_CaptureVideo(CameraApi.hCam, ueye.IS_DONT_WAIT) if CameraApi.nRet != ueye.IS_SUCCESS: print("is_CaptureVideo ERROR") # Enables the queue mode for existing image memory sequences CameraApi.nRet = ueye.is_InquireImageMem( CameraApi.hCam, CameraApi.pcImageMemory, CameraApi.MemID, CameraApi.width, CameraApi.height, CameraApi.nBitsPerPixel, CameraApi.pitch) if CameraApi.nRet != ueye.IS_SUCCESS: print("is_InquireImageMem ERROR") else: print("Press q to leave the programm")
def getMaxSize(self): sensorinfo = ueye.SENSORINFO() ueye.is_GetSensorInfo(self.vc, sensorinfo) return (sensorinfo.nMaxWidth.value,sensorinfo.nMaxHeight.value)
def __init__(self, index): self.hCam = ueye.HIDS( index ) # 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 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) # --------------------------------------------------------------------------------------------------------------------------------------- # print( "START" ) # print() # Starts the driver and establishes the connection to the camera self.nRet = ueye.is_InitCamera(self.hCam, None) if self.nRet != ueye.IS_SUCCESS: raise Exception("is_InitCamera ERROR") # Reads out the data hard-coded in the non-volatile camera memory and writes it to the data structure that self.cInfo # points to self.nRet = ueye.is_GetCameraInfo(self.hCam, self.cInfo) if self.nRet != ueye.IS_SUCCESS: raise Exception("is_GetCameraInfo ERROR") # You can query additional information about the sensor type used in the camera self.nRet = ueye.is_GetSensorInfo(self.hCam, self.sInfo) if self.nRet != ueye.IS_SUCCESS: raise Exception("is_GetSensorInfo ERROR") self.nRet = ueye.is_ResetToDefault(self.hCam) if self.nRet != ueye.IS_SUCCESS: raise Exception("is_ResetToDefault ERROR") # Set display mode to DIB self.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.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") # Can be used to set the size and position of an "area of interest"(AOI) within an image self.nRet = ueye.is_AOI(self.hCam, ueye.IS_AOI_IMAGE_GET_AOI, self.rectAOI, ueye.sizeof(self.rectAOI)) if self.nRet != ueye.IS_SUCCESS: raise Exception("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() # --------------------------------------------------------------------------------------------------------------------------------------- # Allocates an image memory for an image having its dimensions defined by width and height and its color depth # defined by nBitsPerPixel self.nRet = ueye.is_AllocImageMem(self.hCam, self.width, self.height, self.nBitsPerPixel, self.pcImageMemory, self.MemID) if self.nRet != ueye.IS_SUCCESS: raise Exception("is_AllocImageMem ERROR") else: # Makes the specified image memory the active memory self.nRet = ueye.is_SetImageMem(self.hCam, self.pcImageMemory, self.MemID) if self.nRet != ueye.IS_SUCCESS: raise Exception("is_SetImageMem ERROR") else: # Set the desired color mode self.nRet = ueye.is_SetColorMode(self.hCam, self.m_nColorMode) # Activates the camera's live video mode (free run mode) self.nRet = ueye.is_CaptureVideo(self.hCam, ueye.IS_DONT_WAIT) if self.nRet != ueye.IS_SUCCESS: raise Exception("is_CaptureVideo ERROR") # Enables the queue mode for existing image memory sequences self.nRet = ueye.is_InquireImageMem(self.hCam, self.pcImageMemory, self.MemID, self.width, self.height, self.nBitsPerPixel, self.pitch) if self.nRet != ueye.IS_SUCCESS: raise Exception("is_InquireImageMem ERROR") else: print("Camera Connection success")
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)