Exemplo n.º 1
0
def takeVideo():
    st = datetime.datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d_%Hh%Mmin%Ssec')
    string="\n Prises du {} (avec find contours) sur {} itérations\n".format(st,tools.ITERATIONS)
    string+="***Comparaison des filtres sur algos***"
    i = 0
    camera = cv2.VideoCapture(0)
    nbImgSec = 0
    tag = None
    print "Starting video"
    dt = st = time.time()
    #camera.start_preview()
    # capture frames from the camera
    while (True):
        # time.sleep(0.1)
        # Capture frame-by-frame
        _, image = camera.read()
        nbImgSec += 1
        i += 1
        string += "\n--------> Prise n°{}".format(i)
        # time.sleep(0.1)

        # tests sur l'image
        # tps = tg.found_tag_img_comp(image)
        dt = time.time()
        results = tg.found_tag_img(image)
        tps = "\nTemps = "+str(time.time() - dt)
        # writing if there was or not any tag in the image
        if results==[]:
            tps+= " ---> No tag found"
        else:
            tps += " ---> Tags found:"+str(results)
        print "Résultats = ",results
        #time.sleep(0.5)
        string += str(tps)
        if tag is None:
            # continue
            tag = image.copy()
        ft = time.time()
        # print 'Temps mis = {}'.format(ft-dt)
        # show the frame
        # cv2.imshow("origin", image)
        # cv2.imshow("fin", tag)
        key = cv2.waitKey(1) & 0xFF

        dt = time.time()
        # if the `q` key was pressed, break from the loop
        if key == ord("q") or i>=tools.ITERATIONS:
            break
        if(dt-st>=1):
            string+= "\n\t1 seconde écoulée : {} images prises".format(nbImgSec)
            st=ft
            nbImgSec = 0

    # end with
    print "\nFin prise"
    # When everything done, release the capture
    #camera.stop_preview()
    cv2.destroyAllWindows()
    io.writeOutputFile(string)
Exemplo n.º 2
0
def run(thymio, expected=[], demo=False):
    STOP = False
    print "Raspberry in process"
    i = 0
    nbImgSec = 0
    camera, rawCapture = initCam()
    st = dt = time.time()
    print "\nStarting vizualization!"
    for frame in camera.capture_continuous(rawCapture,
                                           format="bgr",
                                           use_video_port=True):
        if STOP:
            break
        # grab the raw NumPy array representing the image, then initialize the timestamp
        # and occupied/unoccupied text
        image = frame.array
        nbImgSec += 1
        i += 1
        if i % tools.BRIGHTNESS_CHECK != 0:
            verif = tools.verify_brightness(image)
        else:
            verif = tools.verify_brightness(image, go=True)
        # there were a modification
        if verif != 0:
            camera.brightness += verif
            print "Brightness", camera.brightness
        # tests sur l'image
        results = tg.found_tag_img(image, demo=demo)
        print "\nTemps = " + str(time.time() - dt)
        # writing if there was or not any tag in the image
        if results == []:
            print " ---> No tag found"
        elif any([x in expected for x in results]):
            #self.thy_controller.found_good()
            print "GOOD -> Robot seen : ", results
        else:
            #self.thy_controller.found_wrong()
            print "WRONG -> Robot seen : ", results
        # show the frame
        key = cv2.waitKey(1) & 0xFF
        rawCapture.truncate(0)
        # not working : cv2 not showing
        # if the `q` key was pressed, break from the loop
        if key == ord("q"):  #or i>=tools.ITERATIONS:
            STOP = True
            break
        dt = time.time()
        """
		if(dt-st>=1):
		#print "\n1seconde ecoulee : {} images prises".format(nbImgSec)
		st=ft
		nbImgSec = 0
		"""
    # end with
    print "\nEnd vizualization"
    # When everything's done, release the capture
    #camera.stop_preview()
    cv2.destroyAllWindows()
Exemplo n.º 3
0
def test_images(classification, directory):
    ststr = datetime.datetime.fromtimestamp(
        time.time()).strftime('%Y-%m-%d_%Hh%Mmin%Ssec')
    string = "\n Prises du {} \n".format(ststr)
    string += "***Calculs des true/false-positives/negatives***"
    print "\nDébut tests"
    nbImgSec = 0
    st = time.time()
    #accepted = [(3,"10"),(12,"10"),(10,"00"),(0,"00")]
    list_img = sorted(os.listdir(tools.IMG_PATH + str(directory)))
    for i, img_name in enumerate(list_img):
        img = cv2.imread(tools.IMG_PATH + str(directory) + img_name)
        nbImgSec += 1
        string += "\n--------> Prise n°{}".format(i)
        dt = time.time()
        # showing what's found
        results = tg.found_tag_img(img, demo=True)
        ft = time.time()
        tps = "\nTemps = " + str(ft - dt)
        if results == []:
            tps += " ---> No tag found"
        else:
            tps += " ---> Tags found:" + str(results)
        #print "Résultats image",i," = ", results
        cv2.imshow("image", img)
        string += str(tps)
        solution = classification[img_name]
        # categorizing
        if results == [] and solution == []:
            tools.TRUE_NEG += 1
        elif results == []:
            tools.FALSE_NEG += 1
        elif solution == []:
            tools.FALSE_POS += 1
        else:
            resIn = all([x in solution for x in results])
            solIn = all([x in results for x in solution])
            if solIn and resIn:
                # it is a good good one
                tools.TRUE_POS += 1
            elif solIn:
                tools.FALSE_NEG += 1
            elif resIn:
                tools.FALSE_POS += 1
        if cv2.waitKey(1) & 0XFF == ord('q'):
            break
        if (dt - st >= 1):
            print "\n\t1 seconde écoulée : {} images testées".format(nbImgSec)
            string += "\n\t1 seconde écoulée : {} images testées".format(
                nbImgSec)
            st = time.time()
            nbImgSec = 0

    cv2.destroyAllWindows()
    #io.writeOutputFile(string)
    #plt.results_pie_chart()
    print "\nFin tests"
Exemplo n.º 4
0
def run(thymio, expected = [], demo = False):
	STOP = False
	print "Raspberry in process"
	i = 0
	nbImgSec = 0
	camera,rawCapture = initCam()
	st = dt = time.time()
	print "\nStarting vizualization!"
	for frame in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True):
		if STOP:
			break
		# grab the raw NumPy array representing the image, then initialize the timestamp
		# and occupied/unoccupied text
		image = frame.array
		nbImgSec += 1
		i += 1
		if i%tools.BRIGHTNESS_CHECK!=0:
			verif = tools.verify_brightness(image)
		else:
			verif = tools.verify_brightness(image,go=True)
		# there were a modification
		if verif!=0:
			camera.brightness += verif            
			print "Brightness",camera.brightness
		# tests sur l'image
		results = tg.found_tag_img(image, demo = demo)
		print "\nTemps = "+str(time.time() - dt)
		# writing if there was or not any tag in the image
		if results==[]:
			print " ---> No tag found"
		elif any([x in expected for x in results]):
			#self.thy_controller.found_good()
			print "GOOD -> Robot seen : ",results
		else:
			#self.thy_controller.found_wrong()
			print "WRONG -> Robot seen : ",results
		# show the frame
		key = cv2.waitKey(1) & 0xFF
		rawCapture.truncate(0)
		# not working : cv2 not showing
		# if the `q` key was pressed, break from the loop
		if key == ord("q") :#or i>=tools.ITERATIONS:
			STOP = True
			break
		dt = time.time()
		"""
		if(dt-st>=1):
		#print "\n1seconde ecoulee : {} images prises".format(nbImgSec)
		st=ft
		nbImgSec = 0
		"""
	# end with
	print "\nEnd vizualization"
	# When everything's done, release the capture
	#camera.stop_preview()
	cv2.destroyAllWindows()
Exemplo n.º 5
0
def test_images(classification,directory):
    ststr = datetime.datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d_%Hh%Mmin%Ssec')
    string="\n Prises du {} \n".format(ststr)
    string+="***Calculs des true/false-positives/negatives***"
    print "\nDébut tests"
    nbImgSec = 0
    st = time.time()
    #accepted = [(3,"10"),(12,"10"),(10,"00"),(0,"00")]
    list_img = sorted(os.listdir(tools.IMG_PATH+str(directory)))
    for i,img_name in enumerate(list_img):
        img = cv2.imread(tools.IMG_PATH+str(directory)+img_name)
        nbImgSec += 1
        string += "\n--------> Prise n°{}".format(i)
        dt = time.time()
        # showing what's found
        results = tg.found_tag_img(img,demo=True)
        ft = time.time()
        tps = "\nTemps = " + str(ft - dt)
        if results == []:
            tps += " ---> No tag found"
        else:
            tps += " ---> Tags found:" + str(results)
        #print "Résultats image",i," = ", results
        cv2.imshow("image",img)
        string += str(tps)
        solution = classification[img_name]
        # categorizing
        if results==[] and solution==[]:
            tools.TRUE_NEG+=1
        elif results==[]:
            tools.FALSE_NEG+=1
        elif solution==[]:
            tools.FALSE_POS+=1
        else:
            resIn = all([x in solution for x in results])
            solIn = all([x in results for x in solution])
            if solIn and resIn:
            # it is a good good one
                tools.TRUE_POS+=1
            elif solIn :
                tools.FALSE_NEG+=1
            elif resIn :
                tools.FALSE_POS+=1
        if cv2.waitKey(1) & 0XFF == ord('q'):
            break
        if (dt - st >= 1):
            print "\n\t1 seconde écoulée : {} images testées".format(nbImgSec)
            string += "\n\t1 seconde écoulée : {} images testées".format(nbImgSec)
            st = time.time()
            nbImgSec = 0

    cv2.destroyAllWindows()
    #io.writeOutputFile(string)
    #plt.results_pie_chart()
    print "\nFin tests"
Exemplo n.º 6
0
def test_images():
    ststr = datetime.datetime.fromtimestamp(
        time.time()).strftime('%Y-%m-%d_%Hh%Mmin%Ssec')
    string = "\n Prises du {} \n".format(ststr)
    string += "***Calculs des true/false-positives/negatives***"
    print "\nDébut tests"
    nbImgSec = 0
    st = time.time()
    accepted = [(3, "10"), (12, "10"), (10, "00"), (0, "00")]
    list_img = sorted(os.listdir(tools.IMG_PATH))
    for i, img_name in enumerate(list_img):
        img = cv2.imread(tools.IMG_PATH + img_name)
        nbImgSec += 1
        string += "\n--------> Prise n°{}".format(i)

        dt = time.time()
        results = tg.found_tag_img(img)
        ft = time.time()
        tps = "\nTemps = " + str(ft - dt)
        if results == []:
            tps += " ---> No tag found"
        else:
            tps += " ---> Tags found:" + str(results)
        #print "Résultats image",i," = ", results
        string += str(tps)
        if results == []:
            tools.FALSE_NEG += 1
        else:
            if not any([x in accepted for x in results]):
                # there is no good one
                tools.FALSE_NEG += 1
            else:
                tools.TRUE_POS += 1
        if cv2.waitKey(1) & 0XFF == ord('q'):
            break
        if (dt - st >= 1):
            string += "\n\t1 seconde écoulée : {} images prises".format(
                nbImgSec)
            st = time.time()
            nbImgSec = 0

    #print list_img
    cv2.destroyAllWindows()
    io.writeOutputFile(string)

    print "\nFin tests"
Exemplo n.º 7
0
def test_images():
    ststr = datetime.datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d_%Hh%Mmin%Ssec')
    string="\n Prises du {} \n".format(ststr)
    string+="***Calculs des true/false-positives/negatives***"
    print "\nDébut tests"
    nbImgSec = 0
    st = time.time()
    accepted = [(3,"10"),(12,"10"),(10,"00"),(0,"00")]
    list_img = sorted(os.listdir(tools.IMG_PATH))
    for i,img_name in enumerate(list_img):
        img = cv2.imread(tools.IMG_PATH+img_name)
        nbImgSec += 1
        string += "\n--------> Prise n°{}".format(i)

        dt = time.time()
        results = tg.found_tag_img(img)
        ft = time.time()
        tps = "\nTemps = " + str(ft - dt)
        if results == []:
            tps += " ---> No tag found"
        else:
            tps += " ---> Tags found:" + str(results)
        #print "Résultats image",i," = ", results
        string += str(tps)
        if results == []:
            tools.FALSE_NEG+=1
        else:
            if not any([x in accepted for x in results]):
                # there is no good one
                tools.FALSE_NEG+=1
            else:
                tools.TRUE_POS+=1
        if cv2.waitKey(1) & 0XFF == ord('q'):
            break
        if (dt - st >= 1):
            string += "\n\t1 seconde écoulée : {} images prises".format(nbImgSec)
            st = time.time()
            nbImgSec = 0

    #print list_img
    cv2.destroyAllWindows()
    io.writeOutputFile(string)

    print "\nFin tests"
Exemplo n.º 8
0
def takeVideo(demo=False, comparison=False, distance=False):
    ststr = datetime.datetime.fromtimestamp(
        time.time()).strftime('%Y-%m-%d_%Hh%Mmin%Ssec')
    string = "\n Prises du {} sur {} itérations\n".format(
        ststr, tools.ITERATIONS)
    string += "\n***Comparaison des filtres sur algos***"
    if distance:
        tools.DIST_ANGLE = True
        string += "Avec calcul de la distance"
    i = 0
    nbImgSec = 0
    tag = None
    st = dt = time.time()
    camera, rawCapture = initCam()
    print "Starting video"
    # camera.start_preview()
    # capture frames from the camera
    for frame in camera.capture_continuous(rawCapture,
                                           format="bgr",
                                           use_video_port=True):
        # grab the raw NumPy array representing the image, then initialize the timestamp
        # and occupied/unoccupied text
        image = frame.array
        nbImgSec += 1
        i += 1
        string += "\n--------> Prise n°{}".format(i)
        print "\ntemps ++", time.time() - dt
        dt = time.time()
        if i % tools.BRIGHTNESS_CHECK != 0:
            verif = tools.verify_brightness(image)
        else:
            verif = tools.verify_brightness(image, go=True)
        # there were a modification
        if verif != 0:
            camera.brightness += verif
        print "tps bright", time.time() - dt
        # tests sur l'image
        results = []
        if comparison:
            tps = tg.found_tag_img_comps(image)
        else:
            results = tg.found_tag_img(image, demo=demo)
        tps = "\nTemps = " + str(time.time() - dt)
        # writing if there was or not any tag in the image
        if results == []:
            tps += " ---> No tag found"
        else:
            tps += " ---> Tags found:" + str(results)
            print "Résultats = ", results
        string += str(tps)
        if tag is None:
            # continue
            tag = image
        ft = time.time()
        print 'Temps mis = {}'.format(ft - dt)
        # show the frame
        key = cv2.waitKey(1) & 0xFF

        rawCapture.truncate(0)
        dt = time.time()
        # if the `q` key was pressed, break from the loop
        if key == ord("q"):  #or i>=tools.ITERATIONS:
            break
        # to save the image
        if (dt - st >= 1):
            print "\n\t1 seconde écoulée : {} images prises".format(nbImgSec)
            string += "\n\t1 seconde écoulée : {} images prises".format(
                nbImgSec)
            st = ft
            nbImgSec = 0

    # end for
    print "\nFin prise"
    # When everything's done, release the capture
    #camera.stop_preview()
    cv2.destroyAllWindows()
    if comparison:
        io.writeOutputFile(string)
        plt.plotBestTime()
        plt.boxPlotBestTime()
Exemplo n.º 9
0
def takeVideo():
    st = datetime.datetime.fromtimestamp(
        time.time()).strftime('%Y-%m-%d_%Hh%Mmin%Ssec')
    string = "\n Prises du {} (avec find contours) sur {} itérations\n".format(
        st, tools.ITERATIONS)
    string += "***Comparaison des filtres sur algos***"
    i = 0
    camera = cv2.VideoCapture(0)
    nbImgSec = 0
    tag = None
    print "Starting video"
    dt = st = time.time()
    #camera.start_preview()
    # capture frames from the camera
    while (True):
        # time.sleep(0.1)
        # Capture frame-by-frame
        _, image = camera.read()
        nbImgSec += 1
        i += 1
        string += "\n--------> Prise n°{}".format(i)
        # time.sleep(0.1)

        # tests sur l'image
        # tps = tg.found_tag_img_comp(image)
        dt = time.time()
        results = tg.found_tag_img(image)
        tps = "\nTemps = " + str(time.time() - dt)
        # writing if there was or not any tag in the image
        if results == []:
            tps += " ---> No tag found"
        else:
            tps += " ---> Tags found:" + str(results)
        print "Résultats = ", results
        #time.sleep(0.5)
        string += str(tps)
        if tag is None:
            # continue
            tag = image.copy()
        ft = time.time()
        # print 'Temps mis = {}'.format(ft-dt)
        # show the frame
        # cv2.imshow("origin", image)
        # cv2.imshow("fin", tag)
        key = cv2.waitKey(1) & 0xFF

        dt = time.time()
        # if the `q` key was pressed, break from the loop
        if key == ord("q") or i >= tools.ITERATIONS:
            break
        if (dt - st >= 1):
            string += "\n\t1 seconde écoulée : {} images prises".format(
                nbImgSec)
            st = ft
            nbImgSec = 0

    # end with
    print "\nFin prise"
    # When everything done, release the capture
    #camera.stop_preview()
    cv2.destroyAllWindows()
    io.writeOutputFile(string)
Exemplo n.º 10
0
def takeVideo(demo=False,comparison=False,distance=False):
    ststr = datetime.datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d_%Hh%Mmin%Ssec')
    string="\n Prises du {} sur {} itérations\n".format(ststr,tools.ITERATIONS)
    string+="\n***Comparaison des filtres sur algos***"
    if distance:
        tools.DIST_ANGLE = True
        string+="Avec calcul de la distance"
    i = 0
    nbImgSec = 0
    tag = None
    st = dt = time.time()
    camera, rawCapture = initCam()
    print "Starting video"
    # camera.start_preview()
    # capture frames from the camera
    for frame in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True):
        # grab the raw NumPy array representing the image, then initialize the timestamp
        # and occupied/unoccupied text
        image = frame.array
        nbImgSec += 1
        i += 1
        string += "\n--------> Prise n°{}".format(i)
        print "\ntemps ++", time.time()-dt
        dt = time.time()
        if i%tools.BRIGHTNESS_CHECK!=0:
            verif = tools.verify_brightness(image)
        else:
            verif = tools.verify_brightness(image,go=True)
        # there were a modification
        if verif!=0:
            camera.brightness += verif
        print "tps bright",time.time()-dt
        # tests sur l'image
        results = []
        if comparison:
            tps = tg.found_tag_img_comps(image)
        else:
            results = tg.found_tag_img(image, demo = demo)
        tps = "\nTemps = "+str(time.time() - dt)
        # writing if there was or not any tag in the image
        if results==[]:
            tps+= " ---> No tag found"
        else:
            tps += " ---> Tags found:"+str(results)
            print "Résultats = ",results
        string += str(tps)
        if tag is None:
            # continue
            tag = image
        ft = time.time()
        print 'Temps mis = {}'.format(ft-dt)
        # show the frame
        key = cv2.waitKey(1) & 0xFF

        rawCapture.truncate(0)
        dt = time.time()
        # if the `q` key was pressed, break from the loop
        if key == ord("q") :#or i>=tools.ITERATIONS:
            break
        # to save the image
        if(dt-st>=1):
            print "\n\t1 seconde écoulée : {} images prises".format(nbImgSec)
            string+= "\n\t1 seconde écoulée : {} images prises".format(nbImgSec)
            st=ft
            nbImgSec = 0

    # end for
    print "\nFin prise"
    # When everything's done, release the capture
    #camera.stop_preview()
    cv2.destroyAllWindows()
    if comparison:
        io.writeOutputFile(string)
        plt.plotBestTime()
        plt.boxPlotBestTime()