Commit 1296ed03 authored by William Michalski's avatar William Michalski
Browse files

Travail sur graphe pour rapport : etude FPS selon résolution

parent 65ad7fd3
D'après le code de la librarie (camera.py), le framerate max de la caméra est de 120fps.
Askip résolution min = (160,128) (à vérifier). C'est celle qui est choisis ici
Temps de calcul du barycentre (ms):
Tps moyen estimé(ms): 1.8078284385876777
Ecart-type (ms): 0.32829097548285235
Ecart-type relatif : 18.159409846396805%
(Temps d'acquisition : 10.009903907775879)
Temps pour afficher le résultat à l'écran (cv2.circle + cv2.imshow) :
Tps moyen estimé(ms): 0.22734583491254645
Ecart-type (ms): 0.03637447336120714
Ecart-type relatif : 15.999621622801833%
(Temps d'acquisition : 10.04136872291565)
Pour les temps d'acquistion d'image et temps total il faudrait tracer une courbe en fonction du framerate. On devrait avoir tps total =(+/-) tps_calc_bary + tps_affichage + tps_acq
Tps total pour framerate = 100:
Tps moyen estimé(ms): 22.98700357500411
Ecart-type (ms): 13.915232669519979
Ecart-type relatif : 60.535217755181%
(Temps d'acquisition : 10.003296613693237)
Tps d'acquisiton pour framerate = 100 :
Tps moyen estimé(ms): 21.61410522047196
Ecart-type (ms): 13.677788928832038
Ecart-type relatif : 63.28177266333015%
(Temps d'acquisition : 10.010605812072754)
Vérifier pertinence, gros écart type et grosse variation entre différentes mesures.
\ No newline at end of file
# 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("data_res.txt", "a")
# Initialize the camera
camera = PiCamera()
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
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()
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