def readThread(threadName,read_Flag): global flag,handle count = 0 time0 = time.time() time1 = time.time() data = {} cv2.namedWindow("MT9M001",1) cv2.setMouseCallback("MT9M001",mouse_callback) while flag: if ArducamSDK.Py_ArduCam_available(handle) > 0: res,data = ArducamSDK.Py_ArduCam_read(handle,Width * Height) if res == 0: count += 1 time1 = time.time() ArducamSDK.Py_ArduCam_del(handle) else: print "read data fail!" else: print "is not available" if len(data) >= Width * Height: if time1 - time0 >= 1: print "%s %d %s\n"%("fps:",count,"/s") count = 0 time0 = time1 show(data) else: print "data length is not enough!" if flag == False: break
def show2(): global flag, regArr, handle global W_zoom, H_zoom, V_value, H_value, lx, ly, downFlag, saveFlag, saveNum regNum = 0 res, handle = ArducamSDK.Py_ArduCam_autoopen(cfg) if res == 0: openFlag = True print "device open success!" while (regArr[regNum][0] != 0xFFFF): ArducamSDK.Py_ArduCam_writeSensorReg(handle, regArr[regNum][0], regArr[regNum][1]) regNum = regNum + 1 res = ArducamSDK.Py_ArduCam_beginCapture(handle) if res == 0 and flag: print "transfer task create success!" res = ArducamSDK.Py_ArduCam_capture(handle) if ArducamSDK.Py_ArduCam_available(handle) > 0: print "estou available" res, data = ArducamSDK.Py_ArduCam_read(handle, Width * Height) image = Image.frombuffer("L", (Width, Height), data) img = np.array(image) height, width = img.shape[:2] img2 = cv2.cvtColor(img, COLOR_BYTE2RGB) if args.name and capture: cv2.imwrite(args.name + "." + args.type, img2) if not args.show: return if saveFlag: saveFlag = False saveNum += 1 name = "" if "bmp" == args.type: name = str(saveNum) + ".bmp" if "png" == args.type: name = str(saveNum) + ".png" if "jpg" == args.type: name = str(saveNum) + ".jpg" cv2.imwrite(name, img2) if res != 0: print "capture fail!" return if flag == False: return else: print "transfer task create fail!" res = ArducamSDK.Py_ArduCam_close(handle) if res == 0: openFlag = False print "device close success!" else: print "device close fail!" else: print "device open fail!"
def readThread(threadName, read_Flag): global flag, handle, storeFlag, bufferData, openFlag global a_lock count = 0 time0 = time.time() time1 = time.time() data = {} # Wait for the arducam object to be ready while openFlag == False: time1 = time.time() if time1 - time0 > 20: #timeout exit while flag: res = ArducamSDK.Py_ArduCam_available(handle) #~ print "Available frames %d"%(res) if res > 0: res, data = ArducamSDK.Py_ArduCam_read(handle, Width * Height) if res == 0: count += 1 time1 = time.time() ArducamSDK.Py_ArduCam_del(handle) else: print("read data fail!") else: #print "No data availiable" time.sleep(.01) if len(data) >= Width * Height: if time1 - time0 >= 5: print("%s %f %s\n" % ("fps:", count * 1.0 / (time1 - time0), "/s")) count = 0 time0 = time1 a_lock.acquire() bufferData = data data = [] storeFlag = True a_lock.release() #show(data) #else: # print "data length is not enough!" if flag == False: break
def readThread(threadName,read_Flag): global flag,handle data = {} cv2.namedWindow("MT9F002",1) while flag: if ArducamSDK.Py_ArduCam_available(handle) > 0: res,data = ArducamSDK.Py_ArduCam_read(handle,Width * Height) if res == 0: ArducamSDK.Py_ArduCam_del(handle) else: print "read data fail!" else: print "is not available" if len(data) >= Width * Height: show(data) flag = False else: print "data length is not enough!" if flag == False: break