Commit 15e47db7 authored by William Michalski's avatar William Michalski
Browse files

parent 553b2ede
# Credit: Adrian Rosebrock
# 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"])
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)
res 480
rate = 40#FPS
fichier = open("mesure_tps_par_resolution.txt", "a")
# Initialize the camera
camera = PiCamera()
# 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
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), (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
# 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