Ejemplo n.º 1
0
class idscamera(object):
    def __init__(self,
                 camhand=1,
                 AOIwidth=1280,
                 AOIheight=1024,
                 buffer_count=100):
        self.camhandle = camhand
        self.cam = Camera(self.camhandle)
        self.cam.init()
        self.cam.set_colormode(ueye.IS_CM_BGR8_PACKED)
        # ret = self.cam.set_exposure(30.0)
        #ret = cam.set_LUT()
        # ret = self.cam.set_aoi(0, 0, AOIwidth, AOIheight)
        self.cam.alloc(buffer_count)
        ret = self.cam.capture_video(True)  # start to capture;
        self.img_buffer = ImageBuffer()
        self.DATA = ImageData(self.camhandle, self.img_buffer)

    def extract(self):

        ret = ueye.is_GetActSeqBuf(self.camhandle, self.img_buffer.mem_id,
                                   self.img_buffer.mem_ptr,
                                   self.img_buffer.mem_ptrlast)

        # ret = ueye.is_WaitForNextImage(self.camhandle,
        #                                100,
        #                                self.img_buffer.mem_ptr,
        #                                self.img_buffer.mem_id)
        # print(self.img_buffer.mem_id)
        if ret == ueye.IS_SUCCESS:
            #DATA = ImageData(cam.handle(), img_buffer)
            self.DATA.lock()
            self.DATA.getdata(self.img_buffer)
            image = self.DATA.as_1d_image()
            #print(DATA.array.shape)
            self.DATA.unlock()

            return image
        else:
            return None

    def get_size(self):
        return self.cam.get_size()

    def stop(self):
        self.cam.stop_video()
        self.cam.exit()
Ejemplo n.º 2
0
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()