Commit bc2b1ad6 authored by William Michalski's avatar William Michalski
Browse files

Ajout du dossier Mesures_temps, avec les résultats de vitesse par résolution du mardi 30 Mars

parent 80de36aa
# Credit: Adrian Rosebrock
# https://www.pyimagesearch.com/2015/03/30/accessing-the-raspberry-pi-camera-with-opencv-and-python/
# import the necessary packages
from picamera.array import PiRGBArray # Generates a 3D RGB array
from picamera import PiCamera # Provides a Python interface for the RPi Camera Module
import time # Provides time-related functions
import cv2 # OpenCV library
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
from math import sqrt
def centroid(img):
M = cv2.moments(img)
if M["m00"] != 0:
cX = int(M["m10"] / M["m00"])
cY = int(M["m01"] / M["m00"])
else:
cX, cY = 0, 0
return cX, cY
red_lower = np.array([136, 50, 50], np.uint8)
red_upper = np.array([180, 255, 255], np.uint8)
limit_time = 15#Temps d'une mesure
rate = 40#FPS
fichier = open("mesure_tps_par_resolution.txt", "a")
# Initialize the camera
camera = PiCamera()
for res in range(128,496,32):#Boucle pour tester plusieurs resolution
# Set the camera resolution
camera.resolution = (res,res)
# Set the number of frames per second
camera.framerate = rate
# Generates a 3D RGB array and stores it in rawCapture
raw_capture = PiRGBArray(camera, size=(res,res))
# Wait a certain number of seconds to allow the camera time to warmup
time.sleep(2)
aux = 0
time_mean = 0
time_var = 0
loaded = False
exec_time = 0
exec_begin = time.time()
# Capture frames continuously from the camera
for frame in camera.capture_continuous(raw_capture, format="bgr", use_video_port=True):
# Grab the raw NumPy array representing the image
img = frame.array
#A decommenter pour mesurer avec le temps de detection de la bille
# img_hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)#Espace HSV, plus simple de separer les couleurs
# img_red = cv2.inRange(img_hsv, red_lower, red_upper)
# rX,rY = centroid(img_red)
#
#
# cv2.circle(img, (rX,rY), 4, (0,233,255),-1)#Ajout d'un point sur l'image d'origine, pour montrer ou ce trouve le centre detecte
# #
#A decommenter pour voir la video, mais penser que ça fausse la vitesse d'execution
# cv2.imshow("Frame", img)
#
# Wait for keyPress for 1 millisecond
key = cv2.waitKey(1) & 0xFF
# Clear the stream in preparation for the next frame
raw_capture.truncate(0)
if loaded:#Permet d'eliminer la premiere boucle, tps aberant, faussant l'estimation
end = time.time()#Ligne a deplacer selon ce que l'on souhaite mesurer comme temps
#print(end-begin)
time_mean += (end - begin)
time_var += (end-begin)**2
aux += 1
elif aux == 0:
loaded = True
begin = time.time()#Pas besoin d'etre deplace normalement
# If the `q` key was pressed, break from the loop
exec_time = time.time() - exec_begin
if key == ord("q") or exec_time >= limit_time:
break
time_mean = time_mean/aux
time_var = abs(time_var/aux - time_mean**2)
fichier.write("__________\n\nRes : " + str((res,res)) + " | FPS : " + str(rate) + " | Tps d'acq : " + str(exec_time) + "\n__________\nTps moyen estimé(ms): " + str(time_mean*1000) + "\nEcart-type (ms): " + str(sqrt(time_var)*1000) + "\nEcart-type relatif : " + str(sqrt(time_var)/time_mean*100) + "%\n")
fichier.close()
Mardi 30 Mars 2021
Estimation du tps d'une boucle pour acquérir une frame (SANS traitement pour detecter la bille), pour différentes résolution.
Le framerate est fixé à 40 (c'est le maximum qu'on pourra avoir), donc on peut au mieux avoir une vitesse moyenne de 25ms.
__________
Res : (80, 80) | FPS : 40 | Tps d'acq : 15.015199899673462
__________
Tps moyen estimé(ms): 24.97427650604503
Ecart-type (ms): 2.16492486468452
Ecart-type relatif : 8.668618945419698%
__________
Res : (96, 96) | FPS : 40 | Tps d'acq : 15.019232749938965
__________
Tps moyen estimé(ms): 24.973948133210705
Ecart-type (ms): 2.691753358621537
Ecart-type relatif : 10.778245170782611%
__________
Res : (112, 112) | FPS : 40 | Tps d'acq : 15.017590284347534
__________
Tps moyen estimé(ms): 24.978343950886163
Ecart-type (ms): 2.372500377362636
Ecart-type relatif : 9.498229274236838%
__________
Res : (128, 128) | FPS : 40 | Tps d'acq : 15.009831666946411
__________
Tps moyen estimé(ms): 24.962083326158222
Ecart-type (ms): 2.2543150632210227
Ecart-type relatif : 9.03095720724033%
__________
Res : (160, 160) | FPS : 40 | Tps d'acq : 15.016599178314209
__________
Tps moyen estimé(ms): 24.967391821299252
Ecart-type (ms): 2.5825330670046243
Ecart-type relatif : 10.343623737268022%
__________
Res : (192, 192) | FPS : 40 | Tps d'acq : 15.016087770462036
__________
Tps moyen estimé(ms): 24.967094892651488
Ecart-type (ms): 2.6142976731606447
Ecart-type relatif : 10.470972631782264%
__________
Res : (224, 224) | FPS : 40 | Tps d'acq : 15.018326759338379
__________
Tps moyen estimé(ms): 24.967265646525334
Ecart-type (ms): 2.3953651955166433
Ecart-type relatif : 9.594022947603008%
__________
Res : (256, 256) | FPS : 40 | Tps d'acq : 15.018805980682373
__________
Tps moyen estimé(ms): 24.967469038668778
Ecart-type (ms): 2.603577032731257
Ecart-type relatif : 10.427877285835116%
__________
Res : (288, 288) | FPS : 40 | Tps d'acq : 15.019755601882935
__________
Tps moyen estimé(ms): 24.96756655544988
Ecart-type (ms): 2.502899595777577
Ecart-type relatif : 10.024603680214273%
__________
Res : (320, 320) | FPS : 40 | Tps d'acq : 15.02054238319397
__________
Tps moyen estimé(ms): 25.03937013584565
Ecart-type (ms): 3.4286567729304926
Ecart-type relatif : 13.69306318141815%
__________
Res : (352, 352) | FPS : 40 | Tps d'acq : 15.026089429855347
__________
Tps moyen estimé(ms): 25.0191182197137
Ecart-type (ms): 3.1827412935360377
Ecart-type relatif : 12.721236878077546%
__________
Res : (384, 384) | FPS : 40 | Tps d'acq : 15.024237155914307
__________
Tps moyen estimé(ms): 25.051658077655325
Ecart-type (ms): 3.6056565633685924
Ecart-type relatif : 14.392885900772518%
__________
Res : (416, 416) | FPS : 40 | Tps d'acq : 15.02318549156189
__________
Tps moyen estimé(ms): 25.30524734716528
Ecart-type (ms): 4.735182100281792
Ecart-type relatif : 18.712253768237645%
__________
Res : (448, 448) | FPS : 40 | Tps d'acq : 15.003667116165161
__________
Tps moyen estimé(ms): 31.78004761959644
Ecart-type (ms): 16.14140418204272
Ecart-type relatif : 50.791000615397095%
__________
Res : (480, 480) | FPS : 40 | Tps d'acq : 15.021708488464355
__________
Tps moyen estimé(ms): 39.13737654061842
Ecart-type (ms): 21.134156744412902
Ecart-type relatif : 53.99993206616438%
......@@ -24,15 +24,15 @@ def centroid(img):
red_lower = np.array([136, 50, 50], np.uint8)
red_upper = np.array([180, 255, 255], np.uint8)
limit_time = 15
rate = 40
limit_time = 15#Temps d'une mesure
rate = 40#FPS
fichier = open("data_res.txt", "a")
# Initialize the camera
camera = PiCamera()
for res in range(128,496,32):
for res in range(128,496,32):#Boucle pour tester plusieurs résolution
# Set the camera resolution
camera.resolution = (res,res)
# Set the number of frames per second
......@@ -55,6 +55,7 @@ for res in range(128,496,32):
# Grab the raw NumPy array representing the image
img = frame.array
#A decommenter pour mesurer avec le temps de detection de la bille
# img_hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)#Espace HSV, plus simple de separer les couleurs
# img_red = cv2.inRange(img_hsv, red_lower, red_upper)
# rX,rY = centroid(img_red)
......@@ -62,9 +63,9 @@ for res in range(128,496,32):
#
# cv2.circle(img, (rX,rY), 4, (0,233,255),-1)#Ajout d'un point sur l'image d'origine, pour montrer ou ce trouve le centre detecte
# #
# # Display the frame using OpenCV
#
#cv2.imshow("Frame", img)
#A decommenter pour voir la video, mais penser que ça fausse la vitesse d'execution
# cv2.imshow("Frame", img)
#
# Wait for keyPress for 1 millisecond
......@@ -74,7 +75,7 @@ for res in range(128,496,32):
raw_capture.truncate(0)
if loaded:#Permet d'eliminer la premiere boucle, tps aberant, faussant l'estimation
end = time.time()
end = time.time()#Ligne a deplacer selon ce que l'on souhaite mesurer comme temps
#print(end-begin)
time_mean += (end - begin)
time_var += (end-begin)**2
......@@ -82,7 +83,7 @@ for res in range(128,496,32):
elif aux == 0:
loaded = True
begin = time.time()
begin = time.time()#Pas besoin d'etre deplace normalement
# If the `q` key was pressed, break from the loop
exec_time = time.time() - exec_begin
if key == ord("q") or exec_time >= limit_time:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment