def main(): # we need a QApplication, that runs our QT Gui Framework ##app = PyuEyeQtApp() # a basic qt window #view = PyuEyeQtView() #view.show() #view.user_callback = process_image # camera class to simplify uEye API access cam = Camera(1) cam.init() cam.set_colormode(ueye.IS_CM_BGR8_PACKED) #ret = cam.set_exposure(30.0) #ret = cam.set_LUT() # width, height = cam.get_size() x = 0 y = 0 ret = cam.set_aoi(x, y, width, height) cam.alloc(buffer_count=100) ret = cam.capture_video(True) # start to capture; fourcc = cv2.VideoWriter_fourcc(*'XVID') out = cv2.VideoWriter('_output.avi', fourcc, 20.0, (width, height)) # a thread that waits for new images and processes all connected views #thread = FrameThread(cam) #thread.start() running = True img_buffer = ImageBuffer() DATA = ImageData(cam.handle(), img_buffer) while (ret == 0) and running: #img_buffer = ImageBuffer() ret = ueye.is_WaitForNextImage(cam.handle(), 1000, img_buffer.mem_ptr, img_buffer.mem_id) #print(img_buffer.mem_id) if ret == ueye.IS_SUCCESS: #DATA = ImageData(cam.handle(), img_buffer) DATA.getdata(img_buffer) #print(DATA.array.shape) image = DATA.as_1d_image() DATA.unlock() # make a gray image #imag = cv2.cvtColor(image, cv2.COLOR_BGR) cv2.imshow("Simple_black", image) out.write(image) if cv2.waitKey(1) == 27: break #cv2.Mat(ImageData.array) # cleanup #app.exit_connect(thread.stop) #app.exec_() #thread.stop() #thread.join() cam.stop_video() cam.exit() cv2.destroyAllWindows() out.release()
import cv2 from pyueye import ueye from pyueye_example_camera import Camera from pyueye_example_utils import ImageData, ImageBuffer import time import numpy as np # Initialize camera cam = Camera() cam.init() nRet = ueye.is_ResetToDefault(cam.handle()) # Change the format to 1280x960 formatID = ueye.UINT(8) nRet = ueye.is_ImageFormat(cam.handle(), ueye.IMGFRMT_CMD_SET_FORMAT, formatID, ueye.sizeof(formatID)) cam.alloc() # Allocate image memory # Disable auto exposure dblEnable = ueye.DOUBLE(0) dblDummy = ueye.DOUBLE(0) ueye.is_SetAutoParameter(cam.handle(), ueye.IS_SET_ENABLE_AUTO_SENSOR_GAIN_SHUTTER, dblEnable, dblDummy) newExposure = ueye.DOUBLE(30) ret = ueye.is_Exposure(cam.handle(), ueye.IS_EXPOSURE_CMD_SET_EXPOSURE, newExposure, ueye.sizeof(newExposure)) ueye.is_Focus(cam.handle(), ueye.FOC_CMD_SET_DISABLE_AUTOFOCUS, None, 0) # Disable autofocus focus_overview = ueye.INT(205) # Focus value for overview image (taken from 570mm above table) focus_closeup = ueye.INT(144) # Focus value for closeup image (taken from 190mm above table)