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): ret = ueye.is_InitCamera(self.h_cam, None) if ret != ueye.IS_SUCCESS: self.h_cam = None raise uEyeException(ret) return ret
def grabanimage(): camera_port = 0 ramp_frames = 40 camera = cv2.VideoCapture(camera_port) ################## original (access camera thru cv2) ########################## # def get_image(): # retval, im = camera.read() # return im # # for i in xrange(ramp_frames): # temp = get_image() # print("Taking image...") ## Take the actual image we want to keep # camera_capture = get_image() # file = "USBtemp.png" ## A nice feature of the imwrite method is that it will automatically choose the ## correct format based on the file extension you provide. Convenient! # cv2.imwrite(file, camera_capture) ############# reading from IDS camera (added 6/1/19 by Abner) ################# def get_image(w, h): im = ueye.get_data(mem_ptr, w, h, bitspixel, lineinc, copy=True) return im # init camera hcam = ueye.HIDS(0) initTrigger = ueye.is_InitCamera(hcam, None) # load camera parameters memory = ueye.int(128) # cameraSettingFile = ueye.wchar_p('/media/pi/USB30FD/Frostad Research Group/Biofilm Project/Code/FINAL_Biofilm Project.ini') ret = ueye.is_ParameterSet(hcam, ueye.IS_PARAMETERSET_CMD_LOAD_FILE, cameraSettingFile, memory) # set color mode ret = ueye.is_SetColorMode(hcam, ueye.IS_CM_BGR8_PACKED) # set width and height -- FIND FUNCTION TO OUTPUT IMAGE RESOLUTION width = 2560 height = 1920 # allocate memory mem_ptr = ueye.c_mem_p() mem_id = ueye.int() bitspixel = 24 # for colormode = IS_CM_BGR8_PACKED ret = ueye.is_AllocImageMem(hcam, width, height, bitspixel, mem_ptr, mem_id) # set active memory region ret = ueye.is_SetImageMem(hcam, mem_ptr, mem_id) # continuous capture to memory ret = ueye.is_CaptureVideo(hcam, ueye.IS_DONT_WAIT) # get data from camera and display lineinc = width * int((bitspixel + 7) / 8) for i in xrange(ramp_frames): temp = get_image(width, height) print("Taking image...") # Take the actual image we want to keep camera_capture = get_image(width, height) file = "USBtemp.png"
def Init_Cam(width=640, heigth=480, gain_boost=1): """inits the uEye camera""" # inits next available cam cam = ueye.HIDS(0) ueye.is_InitCamera(cam, None) ueye.is_EnableAutoExit(cam, ueye.IS_ENABLE_AUTO_EXIT) # sets the Colourmode of the camera ueye.is_SetColorMode(cam, ueye.IS_CM_SENSOR_RAW8) # sets the trigger ret = ueye.is_SetExternalTrigger(cam, ueye.IS_SET_TRIGGER_SOFTWARE) mode = ueye.int(0) # sets the blacklevel ueye.is_Blacklevel(cam, ueye.IS_BLACKLEVEL_CMD_SET_MODE, mode, ueye.sizeof(mode)) # sets the size of the image rectAOI = ueye.IS_RECT() rectAOI.s32X = 44 rectAOI.s32Y = 0 rectAOI.s32Width = 480 rectAOI.s32Height = 480 ueye.is_AOI(cam, ueye.IS_AOI_IMAGE_SET_AOI, rectAOI, ueye.sizeof(rectAOI)) # allocates memory with given size width = ueye.int(width) heigth = ueye.int(heigth) bitspixel = ueye.int(8) pcImgMem = ueye.c_mem_p() pid = ueye.int() ueye.is_AllocImageMem(cam, 480, heigth, bitspixel, pcImgMem, pid) # sets the image memory as active ueye.is_SetImageMem(cam, pcImgMem, pid) # activates video mode ueye.is_CaptureVideo(cam, ueye.IS_DONT_WAIT) # sets gain boost mode if gain_boost == 1: ueye.is_SetGainBoost(cam, ueye.IS_SET_GAINBOOST_ON) else: ueye.is_SetGainBoost(cam, ueye.IS_SET_GAINBOOST_OFF) return cam, ret, pcImgMem, pid
def show_image(self): nRet = ueye.is_InitCamera(self.h_cam, None) nRet = ueye.is_SetDisplayMode(self.h_cam, ueye.IS_SET_DM_DIB) nRet = ueye.is_AOI(self.h_cam, ueye.IS_AOI_IMAGE_GET_AOI, self.rectAOI, ueye.sizeof(self.rectAOI)) self.width = self.rectAOI.s32Width self.height = self.rectAOI.s32Height nRet = ueye.is_AllocImageMem(self.h_cam, self.width, self.height, self.nBitsPerPixel, self.pcImageMemory, self.MemID) nRet = ueye.is_SetImageMem(self.h_cam, self.pcImageMemory, self.MemID) nRet = ueye.is_SetColorMode(self.h_cam, self.ColorMode) nRet = ueye.is_CaptureVideo(self.h_cam, ueye.IS_DONT_WAIT) nRet = ueye.is_InquireImageMem(self.h_cam, self.pcImageMemory, self.MemID, self.width, self.height, self.nBitsPerPixel, self.pitch) while nRet == ueye.IS_SUCCESS: array = ueye.get_data(self.pcImageMemory, self.width, self.height, self.nBitsPerPixel, self.pitch, copy=False) frame = np.reshape( array, (self.height.value, self.width.value, self.bytes_per_pixel)) frame = cv2.resize(frame, (0, 0), fx=0.5, fy=0.5) size = (self.height, self.width) new_camera_matrix, roi = cv2.getOptimalNewCameraMatrix( self.camera_matrix, self.dist_coeff, size, 1, size) dst = cv2.undistort(frame, self.camera_matrix, self.dist_coeff, None, new_camera_matrix) x, y, w, h = roi self.dst = dst[y:y + h, x:x + w] self.detect_colors() self.extrinsic_calibration() cv2.imshow("camera", self.dst) if cv2.waitKey(1) & 0xFF == ord('q'): break elif cv2.waitKey(1) & 0xFF == ord('t'): cv2.imwrite("/home/lennart/dorna/camera/images/gps.bmp", self.dst) elif cv2.waitKey(100) & 0xFF == ord('l'): self.found_container = False self.container_world_position.clear() print("Behälterposition zurückgesetzt") ueye.is_FreeImageMem(self.h_cam, self.pcImageMemory, self.MemID) ueye.is_ExitCamera(self.h_cam) cv2.destroyAllWindows()
def init(self): ret = ueye.is_InitCamera(self.h_cam, None) if ret != ueye.IS_SUCCESS: self.h_cam = None print("Problem connecting with the camera") raise uEyeException(ret) return ret
def init(self): ret = ueye.is_InitCamera(self.h_cam, self.h_wnd) if ret != ueye.IS_SUCCESS: self.h_cam = None raise uEyeException(ret) self.enable_message(self.h_wnd) return ret
def init(self): # 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") nRet = ueye.is_ResetToDefault(self.hCam) if nRet != ueye.IS_SUCCESS: print("is_ResetToDefault ERROR")
def open(self): '''Opens and initializes ueye camera.''' # initialize camera if(ueye.is_InitCamera(self.input, None) != ueye.IS_SUCCESS): log.error("is_InitCamera ERROR") self.initialize_color_mode() self.initialize_dimensions() self.initialize_memory() self.initialize_modes() self.initialize_camera_settings()
def get_camera_status(self, n_device_id=5): print_style("Camera Status", color="blue") for i in range(n_device_id): hcam = ueye.HIDS(i) ret = ueye.is_InitCamera(hcam, None) self.cam_status[i] = not bool(ret) if ret == ueye.IS_SUCCESS: print_style("Camera ID:", i, " Available", color="green") else: print_style("Camera ID:", i, " Unavailable", color="red")
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 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): 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 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 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
def Camera_Initialization(self): self.hcam = ueye.HIDS(0) self.ret = ueye.is_InitCamera(self.hcam, None) self.ret = ueye.is_SetColorMode(self.hcam, ueye.IS_CM_MONO12) self.IDS_FPS = float(50) self.newrate = ueye.DOUBLE(self.IDS_FPS) self.rate = ueye.DOUBLE(self.IDS_FPS) self.IDS_exposure = float(20) self.width = 2056 self.height = 1542 self.rect_aoi = ueye.IS_RECT() self.rect_aoi.s32X = ueye.int(0) self.rect_aoi.s32Y = ueye.int(0) self.rect_aoi.s32Width = ueye.int(self.width) self.rect_aoi.s32Height = ueye.int(self.height) ueye.is_AOI(self.hcam, ueye.IS_AOI_IMAGE_SET_AOI, self.rect_aoi, ueye.sizeof(self.rect_aoi)) self.mem_ptr = ueye.c_mem_p() self.mem_id = ueye.int() self.bitspixel = 16 self.ret = ueye.is_AllocImageMem(self.hcam, self.width, self.height, self.bitspixel, self.mem_ptr, self.mem_id) self.ret = ueye.is_SetImageMem(self.hcam, self.mem_ptr, self.mem_id) self.ret = ueye.is_CaptureVideo(self.hcam, ueye.IS_DONT_WAIT) #self.lineinc = self.width * int((self.bitspixel + 7) / 8) self.lineinc = self.width * int(self.bitspixel / 8) self.nRet = ueye.is_SetFrameRate(self.hcam, self.rate, self.newrate) self.expms = ueye.DOUBLE(self.IDS_exposure) self.nRet = ueye.is_Exposure(self.hcam, ueye.IS_EXPOSURE_CMD_SET_EXPOSURE, self.expms, ueye.sizeof(self.expms)) self.pixelclock = ueye.c_uint(197) self.nRet = ueye.is_PixelClock(self.hcam, ueye.IS_PIXELCLOCK_CMD_SET, self.pixelclock, 4) #pixelclock = ueye.c_uint() #ueye.is_PixelClock(hcam, ueye.IS_PIXELCLOCK_CMD_GET, pixelclock, 4) self.nRet = ueye.is_SetHardwareGain(self.hcam, 100, ueye.IS_IGNORE_PARAMETER, ueye.IS_IGNORE_PARAMETER, ueye.IS_IGNORE_PARAMETER) #gg = ueye.c_uint() #ueye.is_SetHWGainFactor(hcam, ueye.IS_GET_MASTER_GAIN_FACTOR, gg) self.nRet = ueye.is_SetHardwareGamma(self.hcam, ueye.IS_SET_HW_GAMMA_ON)
def init(self): """ Initialize a connection to the camera. Returns ======= ret: integer Return code from the camera. """ ret = ueye.is_InitCamera(self.h_cam, None) if ret != ueye.IS_SUCCESS: self.h_cam = None raise uEyeException(ret) return ret
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 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 initialize(self): # --- using pyueye --- # self.cam = ueye.HIDS(self.cam_id) self.frame_buffer = [] # --- --- # ret = ueye.is_InitCamera( self.cam, None) # init camera and return 0,1 according to if it worked if ret != ueye.IS_SUCCESS: self.cam = None self.addToLog('Camera initation: failed.') self.isCameraInit = False self.close_camera() return None self.isCameraInit = True
def init(self): h_cam = ueye.HIDS(0 | ueye.IS_USE_DEVICE_ID) ret = ueye.is_InitCamera(h_cam, None) if ret != ueye.IS_SUCCESS: error_message = QMessageBox() result = QMessageBox.critical(error_message, 'Error', "Invalid device id!", buttons=QMessageBox.Ok) if result == QMessageBox.Ok: exit() self.hCam = h_cam return h_cam
def __init__(self, _camID): self.camID=_camID self.vc = ueye.HIDS(_camID) if not (ueye.is_InitCamera(self.vc, None)==0): raise ValueError('Failed to open camera') #reserve memory self.mem_size = self.getMaxSize() ueye.is_AllocImageMem(self.vc, self.mem_size[0], self.mem_size[1],24,self.mem_ptr, self.mem_id) #set active memory region ueye.is_SetImageMem(self.vc, self.mem_ptr, self.mem_id) #continuous capture to memory ueye.is_CaptureVideo(self.vc, ueye.IS_DONT_WAIT)
def run(self): a = ueye.is_InitCamera(self.hCam, None) b = ueye.is_GetCameraInfo(self.hCam, self.cInfo) c = ueye.is_GetSensorInfo(self.hCam, self.sInfo) d = ueye.is_ResetToDefault(self.hCam) e = ueye.is_SetDisplayMode(self.hCam, ueye.IS_SET_DM_DIB) g = 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 h = ueye.is_AllocImageMem(self.hCam, self.width, self.height, self.nBitsPerPixel, self.pcImageMemory, self.MemID) i = ueye.is_SetImageMem(self.hCam, self.pcImageMemory, self.MemID) f = ueye.is_SetColorMode(self.hCam, ueye.IS_CM_MONO12) ueye.is_CaptureVideo(self.hCam, ueye.IS_WAIT) j = ueye.is_InquireImageMem(self.hCam, self.pcImageMemory, self.MemID, self.width, self.height, self.nBitsPerPixel, self.pitch) self.IMAGE_FILE_PARAMS = ueye.IMAGE_FILE_PARAMS( self.pcImageMemory, self.MemID) self.IMAGE_FILE_PARAMS.nFileType = ueye.IS_IMG_PNG self.k = ueye.sizeof(self.IMAGE_FILE_PARAMS) # ueye.is_AutoParameter(self.hCam, ueye.IS_AES_CMD_SET_ENABLE, self.autoParameter, ueye.sizeof(self.autoParameter)) while self.flag: self.data = np.ctypeslib.as_array( ctypes.cast(self.pcImageMemory, ctypes.POINTER(ctypes.c_ubyte)), (self.height * self.pitch, )) self.data.dtype = 'uint16' self.CameraSignal.emit(self.data) time.sleep(0.1) ueye.is_FreeImageMem(self.hCam, self.pcImageMemory, self.MemID) ueye.is_ExitCamera(self.hCam)
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
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, serial): nc=ueye.c_int() self.status=True self._bgImage=0 self.bg=0 if ueye.is_GetNumberOfCameras(nc): _logger.error("Error Wrong number of cameras") return lst=ueye.UEYE_CAMERA_LIST((ueye.UEYE_CAMERA_INFO*nc.value)) lst.dwCount=nc.value ueye.is_GetCameraList(lst) index=None for i in range(nc.value): _logger.info("Got the following ccd: %s"%lst.uci[i].SerNo) if (lst.uci[i].SerNo==serial): index=i break if index is None: _logger.error("SerNo %s not found."%serial) return if lst.uci[index].dwStatus: _logger.error("Camera %d is already busy."%index) self.hcam=ueye.HIDS(index) if ueye.is_InitCamera(self.hcam, None): _logger.error("Error inializating camera.") self.status=True return self.bufCount=0 self.bitsPixel=8 self.Imgs=None self.LastSeqBuf1=ueye.c_mem_p(1) self.acq=False self.grabbingCB=dummy self.grabbing=False self.setColorMode(ueye.IS_CM_MONO8) if self.LoadSettings(): _logger.error("error laoding camera settings") sys.exit() self.status=False
def init(self): ret = ueye.is_InitCamera(self.h_cam, None) if ret != ueye.IS_SUCCESS: self.h_cam = None raise uEyeException(ret) else: print('Initialising cam ', self.h_cam) ret = ueye.is_SetGainBoost(self.h_cam, ueye.IS_SET_GAINBOOST_ON) print('GAINBOOST:', ret) # ms = ueye.DOUBLE(20) # rate = ueye.DOUBLE(10) # newrate = ueye.DOUBLE() # number = ueye.UINT() # # ret = ueye.is_SetFrameRate(self.h_cam, rate, newrate); # print('FR:',ret,newrate) # ret = ueye.is_Exposure(self.h_cam, ueye.IS_EXPOSURE_CMD_GET_EXPOSURE, ms, ueye.sizeof(ms)); # print('EXP:',ret,ms) # ret = ueye.is_PixelClock(self.h_cam, ueye.IS_PIXELCLOCK_CMD_GET_NUMBER, number, ueye.sizeof(number)) # print('PxCLK #:',ret, number) # PCrange = (ctypes.c_uint * 3)() # ret = ueye.is_PixelClock(self.h_cam, ueye.IS_PIXELCLOCK_CMD_GET_RANGE, PCrange, 3*ueye.sizeof(number)) # print('PxCLK range:', ret, PCrange[0], PCrange[1], PCrange[2]) # list_pixel_clocks = (ctypes.c_uint * 150)() # ret = ueye.is_PixelClock(self.h_cam, ueye.IS_PIXELCLOCK_CMD_GET_LIST, list_pixel_clocks, number*ueye.sizeof(number)) # list_np = np.frombuffer(list_pixel_clocks, int) # print('PxCLK list:', ret, list_np[0:number.value]) # ret = ueye.is_PixelClock(self.h_cam, ueye.IS_PIXELCLOCK_CMD_GET, number, ueye.sizeof(number)) # print('PxCLK current:',ret, number) # ret = ueye.is_PixelClock(self.h_cam, ueye.IS_PIXELCLOCK_CMD_GET_DEFAULT, number, ueye.sizeof(number)) # print('PxCLK default:',ret, number) # ret = ueye.is_PixelClock(self.h_cam, ueye.IS_PIXELCLOCK_CMD_SET, ueye.UINT(20), ueye.sizeof(number)) # print('PxCLK set:',ret, number) # ret = ueye.is_PixelClock(self.h_cam, ueye.IS_PIXELCLOCK_CMD_GET, number, ueye.sizeof(number)) # print('PxCLK current:',ret, number) # # self.set_colormode(ueye.IS_CM_BGR8_PACKED) # self.set_displaymode(ueye.IS_SET_DM_DIB) # self.set_aoi(0,0, 1936, 1216) return ret
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 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:
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)