def __init__(self, parent=None): self.converted_memory_pointer = ueye.c_mem_p() self.converted_memory_id = ueye.int() self.img_data = ImageData() self.capturing = False self.hCam = 0 self.init() ueye.is_SetColorMode(self.hCam, ueye.IS_CM_RGB8_PACKED) self.alloc(self.hCam) self.qt_image = None ueye.is_CaptureVideo(self.hCam, Wait=True) QWidget.__init__(self, parent, flags=Qt.Widget) self.graphics_scene = QGraphicsScene() self.graphics_view = QGraphicsView(self.graphics_scene) self.graphics_view.setViewportUpdateMode( QGraphicsView.FullViewportUpdate) self.start_stop_button = QPushButton("start/stop") self.event = ueye.HANDLE(int()) self.frame_event_id = ueye.IS_SET_EVENT_FRAME self.image_data_copy = None self.pil_image = None self.pix_map = None self.width = 0 self.height = 0 self.threads = [] layout = QVBoxLayout() layout.addWidget(self.start_stop_button, alignment=Qt.AlignTop) layout.addWidget(self.graphics_view) self.setLayout(layout) self.start_stop_button.clicked.connect(self.switch_capturing)
def init_cam(hcam): # get fps # hcam_fps = is_GetFramesPerSecond(hcam, None) # set color mode ueye.is_SetColorMode(hcam, ueye.IS_CM_BGR8_PACKED) # set region of interest rect_aoi = ueye.IS_RECT() rect_aoi.s32X = ueye.int(0) rect_aoi.s32Y = ueye.int(0) rect_aoi.s32Width = ueye.int(width) rect_aoi.s32Height = ueye.int(height) ueye.is_AOI(hcam, ueye.IS_AOI_IMAGE_SET_AOI, rect_aoi, ueye.sizeof(rect_aoi)) # allocate memory mem_ptr = ueye.c_mem_p() mem_id = ueye.int() ueye.is_AllocImageMem(hcam, width, height, bitspixel, mem_ptr, mem_id) ueye.is_SetImageMem(hcam, mem_ptr, mem_id) # continuous capture to memory ueye.is_CaptureVideo(hcam, ueye.IS_DONT_WAIT) return mem_ptr
def switch_capturing(self): if self.capturing: ueye.is_StopLiveVideo(self.hCam, Wait=True) self.capturing = False else: ueye.is_CaptureVideo(self.hCam, Wait=True) self.capturing = True self.display_image()
def init_cam(hcam): # get fps # hcam_fps = is_GetFramesPerSecond(hcam, None) # set color mode ueye.is_SetColorMode(hcam, ueye.IS_CM_BGR8_PACKED) # set region of interest rect_aoi = ueye.IS_RECT() rect_aoi.s32X = ueye.int(0) rect_aoi.s32Y = ueye.int(0) rect_aoi.s32Width = ueye.int(width) rect_aoi.s32Height = ueye.int(height) ueye.is_AOI(hcam, ueye.IS_AOI_IMAGE_SET_AOI, rect_aoi, ueye.sizeof(rect_aoi)) # # # set parameters, see ids doc for parameter setting flow chart # ueye.is_PixelClock(hcam, ueye.IS_PIXELCLOCK_CMD_GET, exp, ueye.sizeof(pclock)) # pclock = ueye.int(220) # ueye.is_PixelClock(hcam, ueye.IS_PIXELCLOCK_CMD_GET, pclock, ueye.sizeof(pclock)) # # expo_rng = ueye.is_Exposure(hcam, IS_EXPOSURE_CMD_GET_CAPS, ncap, size(ncap)) # ftime_rng = ueye.is_GetFrameTimeRange() # expo_rng = (expo_rng[0], max(expo_rng[1], ftime_rng[1])) # # fps_actual = ueye.cdouble() # ueye.is_SetFrameRate(hcam, ueye.cdouble(fps_set), byref(fps_actual)) # # exp_cap = ueye.uint32() # ueye.is_Exposure(hcam, ueye.IS_EXPOSURE_GET_EXPOSURE_RANGE, ueye.byref(exp_cap), ueye.sizeof(exp_cap)) # exp_cur = ueye.cdouble() # in s # ueye.is_Exposure(hcam, ueye.IS_EXPOSURE_SET_EXPOSURE, ueye.byref(exp_cur), ueye.sizeof(exp_cur)) # ueye.is_SetGainBoost() # ueye.is_Gamma() # ueye.is_SetHWGainFactor() # # allocate memory mem_ptr = ueye.c_mem_p() mem_id = ueye.int() ueye.is_AllocImageMem(hcam, width, height, bitspixel, mem_ptr, mem_id) ueye.is_SetImageMem(hcam, mem_ptr, mem_id) # continuous capture to memory ueye.is_CaptureVideo(hcam, ueye.IS_DONT_WAIT) return mem_ptr
def setMemroyForVideoCapture(self): 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) # Activates the camera's live video mode (free run mode) nRet = ueye.is_CaptureVideo(self.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(self.hCam, self.pcImageMemory, self.MemID, self.width, self.height, self.nBitsPerPixel, self.pitch) if nRet != ueye.IS_SUCCESS: print("is_InquireImageMem ERROR") else: print("Press q to leave the programm")
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__(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 allocateMemory(self): # Allocates an image memory for an image having its dimensions defined by self.width and 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, self.m_nColorMode) # Activates the camera's live video mode (free run mode) nRet = ueye.is_CaptureVideo(self.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(self.hCam, self.pcImageMemory, self.MemID, self.width, self.height, self.nBitsPerPixel, self.pitch) if nRet != ueye.IS_SUCCESS: print("is_InquireImageMem ERROR")
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 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 capture_video(self, wait=True): """ Begin capturing a video in trigger mode (wait=True) or free run (wait=False). Parameters ========== wait: boolean To wait or not for the camera frames (default to True). """ wait_param = ueye.IS_WAIT if wait else ueye.IS_DONT_WAIT return ueye.is_CaptureVideo(self.cam, wait_param)
def capture_video(self): # Activates the camera's live video mode (free run mode) nRet = ueye.is_CaptureVideo(self.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(self.hCam, self.pcImageMemory, self.MemID, self.rectAOI.s32Width, self.rectAOI.s32Height, self.nBitsPerPixel, self.pitch) if nRet != ueye.IS_SUCCESS: print("is_InquireImageMem ERROR")
def acquireimage(self): self.ret = ueye.is_CaptureVideo(self.hcam, ueye.IS_DONT_WAIT) if self.ret != ueye.IS_SUCCESS: print("is Error") self.ret = ueye.is_InquireImageMem(self.hcam, self.pcImageMemory, self.MemID, self.width, self.height, self.nBitsPerPixel, self.pitch) if self.ret != ueye.IS_SUCCESS: print("is_InquireImageMem ERROR") else: print("Press q to leave the programm")
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 capture_video(self, wait=False): """ Begin capturing a video. Parameters ========== wait: boolean To wait or not for the camera frames (default to False). """ self.alloc() wait_param = ueye.IS_WAIT if wait else ueye.IS_DONT_WAIT return ueye.is_CaptureVideo(self.h_cam, wait_param)
def init_acquisition(self): """ Allocate the computer memory according to the size of the image and start the acquisition. """ # Allocate memory for the acquisition # ----------------------------------- self.width = self.rectAOI.s32Width self.height = self.rectAOI.s32Height Allocate_memory = ueye.is_AllocImageMem(self.hcam, self.width, self.height, self.nBitsPerPixel, self.pcImageMemory, self.MemID) if Allocate_memory != ueye.IS_SUCCESS: print("is_AllocImageMem ERROR") return else: # Makes the specified image memory the active memory Allocate_memory = ueye.is_SetImageMem(self.hcam, self.pcImageMemory, self.MemID) if Allocate_memory != ueye.IS_SUCCESS: print("is_SetImageMem ERROR") return else: # Set the desired color mode Color_mode = ueye.is_SetColorMode(self.hcam, self.m_nColorMode) # Activates the camera's live video mode (free run mode) # ------------------------------------------------------ Launch_capture = ueye.is_CaptureVideo(self.hcam, ueye.IS_DONT_WAIT) if Launch_capture != ueye.IS_SUCCESS: print("is_CaptureVideo ERROR") return # Enables the queue mode for existing image memory sequences nRet = ueye.is_InquireImageMem(self.hcam, self.pcImageMemory, self.MemID, self.width, self.height, self.nBitsPerPixel, self.pitch) if nRet != ueye.IS_SUCCESS: print("is_InquireImageMem ERROR") return # Launch the live acquisition # --------------------------- self.acquire()
def showVideo(cam): nRet = ueye.is_CaptureVideo(cam.handle(), ueye.IS_DONT_WAIT) img_buffer = ImageBuffer() img_data = ImageData(cam.handle(), img_buffer) while True: nRet = ueye.is_WaitForNextImage(cam.handle(), 1000, img_buffer.mem_ptr, img_buffer.mem_id) array = img_data.as_1d_image() #scanned_img = QR_Scanner_visualized(array) cv2.imshow("hei", array) img_data.unlock() if cv2.waitKey(10) & 0xFF == ord('q'): break
def go_live(self): if not ueye.is_CaptureVideo(self.cam, ueye.IS_DONT_WAIT) == ueye.IS_SUCCESS: raise RuntimeError("Capture mode failed") if not ueye.is_InquireImageMem(self.cam, self.image_memory, self.memory_id, self.width, self.height, self.bits_per_pixel, self.pitch) == ueye.IS_SUCCESS: raise RuntimeError("Memory inquiry failed") print("Pitch is {}".format(self.pitch)) print("Camera in live mode")
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 StartExposure(self): logger.debug('StartAq') if self._poll: # stop, we'll allocate buffers and restart self.StopAq() # allocate at least 2 seconds of buffers buffer_size = int(max(2 * self.GetFPS(), 50)) self.InitBuffers(buffer_size, buffer_size) event_log.logEvent('StartAq', '') if self._cont_mode: self.check_success(ueye.is_CaptureVideo(self.h, ueye.IS_DONT_WAIT)) else: self.check_success(ueye.is_FreezeVideo(self.h, ueye.IS_DONT_WAIT)) return 0
def give_da_stream(): hCam, sInfo, cInfo, pcImageMemory, MemID, rectAOI, pitch, nBitsPerPixel, channels, m_nColorMode, bytes_per_pixel, height, width = init_camera( ) nRet = ueye.is_CaptureVideo(hCam, ueye.IS_DONT_WAIT) nRet = ueye.is_InquireImageMem(hCam, pcImageMemory, MemID, width, height, nBitsPerPixel, pitch) try: 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)) # ...resize the image by a half # frame = cv2.resize(frame,(0,0),fx=0.5, fy=0.5) # Press q if you want to end the loop # Press q if you want to end the loop yield frame # --------------------------------------------------------------------------------------------------------------------------------------- # Include image data processing here # --------------------------------------------------------------------------------------------------------------------------------------- finally: # 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)
def initialize_modes(self): ''' Enables live video mode. Enables queue mode. Sets: self.pitch ''' # Activates the camera's live video mode (free run mode) nRet = ueye.is_CaptureVideo(self.input, ueye.IS_DONT_WAIT) if nRet != ueye.IS_SUCCESS: log.error("is_CaptureVideo ERROR") # Enables the queue mode for existing image memory sequences self.pitch = ueye.INT() nRet = ueye.is_InquireImageMem(self.input, self.mem_image, self.mem_id, self.width, self.height, self.bits_per_pixel, self.pitch) if nRet != ueye.IS_SUCCESS: log.error("is_InquireImageMem ERROR")
def start_video_capture(self): # Activates the camera's live video mode (free run mode) err = pue.is_CaptureVideo(self._cam, pue.IS_DONT_WAIT) if err != pue.IS_SUCCESS: raise CameraException(self._cam, 'ueye>video_capture', err, False) self._pitch = pue.INT() err = pue.is_InquireImageMem( self._cam, self._ppc_img_mem, self._mem_id, self._c_width, self._c_height, self._c_pixel_bits, self._pitch, ) if err != pue.IS_SUCCESS: raise CameraException(self._cam, 'ueye>video_capture', err, False) self._video_capture = True
def start_video_capture(self): # Activates the camera's live video mode (free run mode) err = ueye.is_CaptureVideo(self._cam, ueye.IS_WAIT) if err != ueye.IS_SUCCESS: raise CameraException(self._cam, 'ueye>video_capture>', err, False) err = ueye.is_InquireImageMem( self._cam, self._ppc_img_mem, self._mem_id, self._width, self._height, self._nBitsPerPixel, self._pitch, ) if err != ueye.IS_SUCCESS: raise CameraException(self._cam, 'ueye>video_capture>', err, False) self._video_capture = True
def capture_video(self, wait=False): wait_param = ueye.IS_WAIT if wait else ueye.IS_DONT_WAIT return ueye.is_CaptureVideo(self.h_cam, wait_param)
def configure_device(self): """ Configure camera. """ self.nRet = ueye.is_ResetToDefault(self.hid) if self.nRet != ueye.IS_SUCCESS: print('Reset ERROR') ueye.is_Exposure(self.hid, ueye.IS_EXPOSURE_CMD_GET_EXPOSURE_RANGE_MIN, self.minExp, 8) ueye.is_Exposure(self.hid, ueye.IS_EXPOSURE_CMD_GET_EXPOSURE_RANGE_MAX, self.maxExp, 8) self.nRet = ueye.is_SetDisplayMode(self.hid, ueye.IS_SET_DM_DIB) if self.nRet != ueye.IS_SUCCESS: print('Display Mode ERROR') ueye.is_Exposure(self.hid, ueye.IS_EXPOSURE_CMD_SET_EXPOSURE, self.minExp, 8 ) ueye.is_Exposure(self.hid, ueye.IS_EXPOSURE_CMD_GET_EXPOSURE, self.Exp, 8 ) # 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.hid, self.bitspixel, self.colorm) self.bytesppixel = int(self.bitspixel / 8) elif int.from_bytes(self.sinfo.nColorMode.value, byteorder='big') == ueye.IS_COLORMODE_CBYCRY: # for color camera models use RGB32 mode self.colorm = ueye.IS_CM_BGRA8_PACKED self.bitspixel = ueye.INT(32) self.bytesppixel = int(self.bitspixel / 8) elif int.from_bytes(self.sinfo.nColorMode.value, byteorder='big') == ueye.IS_COLORMODE_MONOCHROME: # for color camera models use RGB32 mode self.colorm = ueye.IS_CM_MONO8 self.bitspixel = ueye.INT(8) self.bytesppixel = int(self.bitspixel / 8) else: # for monochrome camera models use Y8 mode self.colorm = ueye.IS_CM_MONO8 self.bitspixel = ueye.INT(8) self.bytesppixel = int(self.bitspixel / 8) self.nRet = ueye.is_AOI(self.hid, ueye.IS_AOI_IMAGE_GET_AOI, self.rect, ueye.sizeof(self.rect)) self.width = self.rect.s32Width self.height = self.rect.s32Height self.pixelSizeMicron = self.sinfo.wPixelSize.value / 100 if self.nRet != ueye.IS_SUCCESS: print('AOI ERROR') self.nRet = ueye.is_AllocImageMem(self.hid, self.width, self.height, self.bitspixel, self.ppcImgMem, self.MemID) if self.nRet != ueye.IS_SUCCESS: print('AllocImageMem ERROR') else: self.nRet = ueye.is_SetImageMem(self.hid, self.ppcImgMem, self.MemID) if self.nRet != ueye.IS_SUCCESS: print('SetImageMem ERROR') else: self.nRet = ueye.is_SetColorMode(self.hid, self.colorm) self.nRet = ueye.is_CaptureVideo(self.hid, ueye.IS_DONT_WAIT) #if self.nRet != ueye.IS_SUCCESS: #print('CaptureVideo ERROR') self.nRet = ueye.is_InquireImageMem(self.hid, self.ppcImgMem, self.MemID, self.width, self.height, self.bitspixel, self.pitch) if self.nRet != ueye.IS_SUCCESS: print('InquireImageMem ERROR')
def capture_video(self, wait=False): wait_param = ueye.IS_WAIT if wait else ueye.IS_DONT_WAIT # over er pythons variant av ternary operator "?:" i C # se Python 3.6 documentation, kap. 6.12. Conditional expressions: # https://docs.python.org/3.6/reference/expressions.html#grammar-token-or_test return ueye.is_CaptureVideo(self.h_cam, wait_param)
width = 1280 height = 720 #Allocate memory mem_ptr = ueye.c_mem_p() mem_id = ueye.int() #For colormode = IS_CM_BGR8_PACKED bitspixel = ueye.INT(24) ueye.is_AllocImageMem(hcam, width, height, bitspixel, mem_ptr, mem_id) #Set active memory region ueye.is_SetImageMem(hcam, mem_ptr, mem_id) #Continuous capture to memory ueye.is_CaptureVideo(hcam, ueye.IS_DONT_WAIT) #Get data from camera lineinc = width * int((bitspixel + 7) / 8) #Calibrate camera tmp = calib() while(count < 5): cv2.waitKey(100) count+=1 display() cv2.waitKey(0) (blue_xiyi, blue_angle, green_xiyi, green_angle) = markers_cycle_horizontal()
def grab(self): """ Grabs live image from camera feed. """ # init camera self.hcam = ueye.HIDS(0) self.initTrigger = ueye.is_InitCamera(self.hcam, None) # set color mode ret = ueye.is_SetColorMode(self.hcam, ueye.IS_CM_BGR8_PACKED) # set region of interest rect_aoi = ueye.IS_RECT() rect_aoi.s32X = ueye.int(0) rect_aoi.s32Y = ueye.int(0) rect_aoi.s32Width = ueye.int(self.width) rect_aoi.s32Height = ueye.int(self.height) ueye.is_AOI(self.hcam, ueye.IS_AOI_IMAGE_SET_AOI, rect_aoi, ueye.sizeof(rect_aoi)) # allocate memory mem_ptr = ueye.c_mem_p() mem_id = ueye.int() bitspixel = 24 # for colormode = IS_CM_BGR8_PACKED ret = ueye.is_AllocImageMem(self.hcam, self.width, self.height, bitspixel, mem_ptr, mem_id) # set active memory region ret = ueye.is_SetImageMem(self.hcam, mem_ptr, mem_id) # continuous capture to memory ret = ueye.is_CaptureVideo(self.hcam, ueye.IS_DONT_WAIT) # get data from camera and display lineinc = self.width * int((bitspixel + 7) / 8) #initialize counter j = 1 while(self.running): frame = {} if j == 1: startTime = time.time() endTime = time.time() img = ueye.get_data(mem_ptr, self.width, self.height, bitspixel, lineinc, copy=True) img = np.reshape(img, (self.height, self.width, 3)) blkImg = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) #Check for edge detector toggle state if self.outline: img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) #create threshold on image to detect edges ret,thresh = cv2.threshold(img,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU) edges = cv2.findContours(thresh,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)[0] if edges: #change to size based on contour area contour = max(edges,key=cv2.contourArea) else: contour = None img = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR) if contour is not None: cv2.drawContours(img,contour,-1,(0,255,0),6) #Check for event - taking capillary image if self.capillary: # load capillary image and store in dictionary self.capImage = copy.copy(blkImg) self.data['capImage'] = self.capImage # toggle capillary capture off self.capillary = False #Check for event - gather droplet data (volume and bond number) if self.dropletAnalysis: # load drop image self.dropImage = copy.copy(blkImg) vals = np.array([self.deltaRho,self.capillaryDiameter,self.thermalExpCoeff, self.trueSyringeRotation,self.deltaT]) ret = dropletQuickAnalysis.get_droplet_geometry(vals,self.capImage,self.dropImage) # output droplet geometry parameters self.vol = ret[0] self.bond = ret[1] if self.recording: # grab timestamp timeVal = endTime - startTime # output droplet images and timestamp and store in dictionary self.data['dropImage'][j] = self.dropImage self.data['time'][j] = timeVal j=j+1 # write image to frame dictionary frame['img'] = img # sleep command to avoid build up in queue time.sleep(0.01) # write image to frame if self.q.qsize() < 10: self.q.put(frame) if self.save: saveFile = self.folderName + '/outputData.pickle' with open(saveFile, 'wb') as handle: pkl.dump(self.data, handle)