Ejemplo n.º 1
0
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():
    global timestamps, images

    handle = {}
    data = {}
    
    regNum = 0
    res, handle = ArducamSDK.Py_ArduCam_autoopen(cfg)
    #print(handle)
    #print(3)
    if res == 0:
        print("device open success!")
        while (regArr[regNum][0] != 0xFFFF):
            ArducamSDK.Py_ArduCam_writeSensorReg(handle, regArr[regNum][0], regArr[regNum][1])
            regNum = regNum + 1
        #print(32143)
        res = ArducamSDK.Py_ArduCam_beginCapture(handle)
        if res == 0:
            print("transfer task create success!")
            while not rospy.is_shutdown():
                #print(2134124)
                res = ArducamSDK.Py_ArduCam_capture(handle)
                #print(res)
                if res == 0:
                    timestamp = rospy.Time.now()
                    #print(7324627864)
                    res, data = ArducamSDK.Py_ArduCam_read(handle, Width * Height)
                    #print(34242)
                    if res == 0:
                        #print(3746827346782)
                        ArducamSDK.Py_ArduCam_del(handle)
                        #print(374623846278)
                        timestamps.put(timestamp)
                        #print(3742846237846)
                        images.put(data)
                        #print(382746278346782)
                        time.sleep(0.03)
                    else:
                        print("read data fail!")
                if res != 0:
                    print("capture fail!")
                    break
        else:
            print("transfer task create fail!")

        res = ArducamSDK.Py_ArduCam_close(handle)
        if res == 0:
            print("device close success!")
        else:
            print("device close fail!")
    else:
        print("device open fail!")
Ejemplo n.º 4
0
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_availiable(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 availiable"
        if len(data) >= Width * Height:
            show(data)
            flag = False
        else:
            print "data length is not enough!"
        if flag == False:
            break