Ejemplo n.º 1
0
 def shot(self):
     while ArducamSDK.Py_ArduCam_availableImage(self.handle) > 0:
         ArducamSDK.Py_ArduCam_del(self.handle)
     while ArducamSDK.Py_ArduCam_availableImage(self.handle) < 2: pass
     ArducamSDK.Py_ArduCam_del(self.handle)
     rtn_val, data, rtn_cfg = ArducamSDK.Py_ArduCam_readImage(self.handle)
     ArducamSDK.Py_ArduCam_del(self.handle)
     datasize = rtn_cfg['u32Size']
     if rtn_val != 0 or datasize == 0:
         ArducamSDK.Py_ArduCam_del(self.handle)
         print("read data fail!")
     image = convert_image(data, rtn_cfg, self.color_mode)
     return image
Ejemplo n.º 2
0
def readImage_thread():
    global handle, running, Width, Height, save_flag, cfg, color_mode, save_raw
    global COLOR_BayerGB2BGR, COLOR_BayerRG2BGR, COLOR_BayerGR2BGR, COLOR_BayerBG2BGR
    count = 0
    totalFrame = 0
    time0 = time.time()
    time1 = time.time()
    data = {}
    cv2.namedWindow("ArduCam Demo", 1)
    if not os.path.exists("images"):
        os.makedirs("images")
    while running:
        display_time = time.time()
        if ArducamSDK.Py_ArduCam_availableImage(handle) > 0:
            rtn_val, data, rtn_cfg = ArducamSDK.Py_ArduCam_readImage(handle)
            datasize = rtn_cfg['u32Size']
            if rtn_val != 0 or datasize == 0:
                ArducamSDK.Py_ArduCam_del(handle)
                print("read data fail!")
                continue

            image = convert_image(data, rtn_cfg, color_mode)

            time1 = time.time()
            if time1 - time0 >= 1:
                print("%s %d %s\n" % ("fps:", count, "/s"))
                count = 0
                time0 = time1
            count += 1
            if save_flag:
                cv2.imwrite("images/image%d.jpg" % totalFrame, image)
                if save_raw:
                    with open("images/image%d.raw" % totalFrame, 'wb') as f:
                        f.write(data)
                totalFrame += 1

            image = cv2.resize(image, (640, 480),
                               interpolation=cv2.INTER_LINEAR)

            cv2.imshow("ArduCam Demo", image)
            cv2.waitKey(10)
            ArducamSDK.Py_ArduCam_del(handle)
            #print("------------------------display time:",(time.time() - display_time))
        else:
            time.sleep(0.001)