Ejemplo 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)
Ejemplo n.º 2
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"
Ejemplo n.º 3
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"
Ejemplo n.º 4
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()
Ejemplo n.º 5
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)
Ejemplo n.º 6
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()