Initial commit

This commit is contained in:
2026-03-31 13:28:59 +02:00
commit 7ec43ca17d
314 changed files with 189852 additions and 0 deletions

View File

@@ -0,0 +1,17 @@
# Tutoriel OpenCV
## Détection d'objet avec la fonction detectMultiScale
Si vous souhaitez me soutenir: <https://fr.tipeee.com/l42-project>
Pour utiliser OpenCV, il suffit d'installer le package suivant:
`# pip install opencv-python`
Je vous conseille aussi d'installer:
`# pip install opencv-contrib-python`
La vidéo du tutoriel est à l'adresse:
https://www.youtube.com/watch?v=-3xbAkCWJCc

View File

@@ -0,0 +1,19 @@
import cv2
face_cascade=cv2.CascadeClassifier("./haarcascade_fullbody.xml")
cap=cv2.VideoCapture(0)
while True:
ret, frame=cap.read()
tickmark=cv2.getTickCount()
gray=cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
face=face_cascade.detectMultiScale(gray, scaleFactor=1.2, minNeighbors=3)
for x, y, w, h in face:
cv2.rectangle(frame, (x, y), (x+w, y+h), (255, 0, 0), 2)
if cv2.waitKey(1)&0xFF==ord('q'):
break
fps=cv2.getTickFrequency()/(cv2.getTickCount()-tickmark)
cv2.putText(frame, "FPS: {:05.2f}".format(fps), (10, 30), cv2.FONT_HERSHEY_PLAIN, 2, (255, 0, 0), 2)
cv2.imshow('video', frame)
cap.release()
cv2.destroyAllWindows()

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:57b6dc1aa21d50310d46a63a8cbd4ac47843c9195fac1be8259d6e1e604c4372
size 81001739

20
OpenCV/tutoriel3/cars.py Normal file
View File

@@ -0,0 +1,20 @@
import cv2
import numpy as np
object_cascade=cv2.CascadeClassifier("./cars.xml")
cap=cv2.VideoCapture('cars.mp4')
while True:
ret, frame=cap.read()
tickmark=cv2.getTickCount()
gray=cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
object=object_cascade.detectMultiScale(gray, scaleFactor=1.10, minNeighbors=3)
for x, y, w, h in object:
cv2.rectangle(frame, (x, y), (x+w, y+h), (255, 0, 0), 2)
fps=cv2.getTickFrequency()/(cv2.getTickCount()-tickmark)
cv2.putText(frame, "FPS: {:05.2f}".format(fps), (10, 30), cv2.FONT_HERSHEY_PLAIN, 2, (255, 0, 0), 2)
cv2.imshow('video', frame)
if cv2.waitKey(1)&0xFF==ord('q'):
break
cap.release()
cv2.destroyAllWindows()

3654
OpenCV/tutoriel3/cars.xml Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,19 @@
import cv2
face_cascade=cv2.CascadeClassifier("./haarcascade_frontalface_alt2.xml")
cap=cv2.VideoCapture(0)
while True:
ret, frame=cap.read()
tickmark=cv2.getTickCount()
gray=cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
face=face_cascade.detectMultiScale(gray, scaleFactor=1.2, minNeighbors=3)
for x, y, w, h in face:
cv2.rectangle(frame, (x, y), (x+w, y+h), (255, 0, 0), 2)
if cv2.waitKey(1)&0xFF==ord('q'):
break
fps=cv2.getTickFrequency()/(cv2.getTickCount()-tickmark)
cv2.putText(frame, "FPS: {:05.2f}".format(fps), (10, 30), cv2.FONT_HERSHEY_PLAIN, 2, (255, 0, 0), 2)
cv2.imshow('video', frame)
cap.release()
cv2.destroyAllWindows()

View File

@@ -0,0 +1,27 @@
import numpy as np
import cv2
import picamera
import picamera.array
WIDTH=640
HEIGHT=480
face_cascade=cv2.CascadeClassifier("./haarcascade_frontalface_alt2.xml")
with picamera.PiCamera() as camera:
with picamera.array.PiRGBArray(camera) as stream:
camera.resolution=(WIDTH, HEIGHT)
while True:
camera.capture(stream, 'bgr', use_video_port=True)
tickmark=cv2.getTickCount()
gray=cv2.cvtColor(stream.array, cv2.COLOR_BGR2GRAY)
face=face_cascade.detectMultiScale(gray, scaleFactor=1.3, minNeighbors=4)
for x, y, w, h in face:
cv2.rectangle(stream.array, (x, y), (x+w, y+h), (255, 0, 0), 2)
if cv2.waitKey(1)&0xFF==ord('q'):
break
fps=cv2.getTickFrequency()/(cv2.getTickCount()-tickmark)
cv2.putText(stream.array, "FPS: {:05.2f}".format(fps), (10, 30), cv2.FONT_HERSHEY_PLAIN, 2, (255, 0, 0), 2)
cv2.imshow('video', stream.array)
stream.seek(0)
stream.truncate()
cv2.destroyAllWindows()

View File

@@ -0,0 +1,37 @@
import cv2
import operator
face_cascade=cv2.CascadeClassifier("./haarcascade_frontalface_alt2.xml")
profile_cascade=cv2.CascadeClassifier("./haarcascade_profileface.xml")
cap=cv2.VideoCapture(0)
width=int(cap.get(3))
marge=70
while True:
ret, frame=cap.read()
tab_face=[]
tickmark=cv2.getTickCount()
gray=cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
face=face_cascade.detectMultiScale(gray, scaleFactor=1.2, minNeighbors=4, minSize=(5, 5))
for x, y, w, h in face:
tab_face.append([x, y, x+w, y+h])
face=profile_cascade.detectMultiScale(gray, scaleFactor=1.2, minNeighbors=4)
for x, y, w, h in face:
tab_face.append([x, y, x+w, y+h])
gray2=cv2.flip(gray, 1)
face=profile_cascade.detectMultiScale(gray2, scaleFactor=1.2, minNeighbors=4)
for x, y, w, h in face:
tab_face.append([width-x, y, width-(x+w), y+h])
tab_face=sorted(tab_face, key=operator.itemgetter(0, 1))
index=0
for x, y, x2, y2 in tab_face:
if not index or (x-tab_face[index-1][0]>marge or y-tab_face[index-1][1]>marge):
cv2.rectangle(frame, (x, y), (x2, y2), (0, 0, 255), 2)
index+=1
if cv2.waitKey(1)&0xFF==ord('q'):
break
fps=cv2.getTickFrequency()/(cv2.getTickCount()-tickmark)
cv2.putText(frame, "FPS: {:05.2f}".format(fps), (10, 30), cv2.FONT_HERSHEY_PLAIN, 2, (255, 0, 0), 2)
cv2.imshow('video', frame)
cap.release()
cv2.destroyAllWindows()

View File

@@ -0,0 +1,43 @@
import cv2
import operator
import picamera
import picamera.array
face_cascade=cv2.CascadeClassifier("./haarcascade_frontalface_alt2.xml")
profile_cascade=cv2.CascadeClassifier("./haarcascade_profileface.xml")
marge=70
WIDTH=640
HEIGHT=480
with picamera.PiCamera() as camera:
with picamera.array.PiRGBArray(camera) as stream:
camera.resolution=(WIDTH, HEIGHT)
while True:
camera.capture(stream, 'bgr', use_video_port=True)
tab_face=[]
tickmark=cv2.getTickCount()
gray=cv2.cvtColor(stream.array, cv2.COLOR_BGR2GRAY)
face=face_cascade.detectMultiScale(gray, scaleFactor=1.2, minNeighbors=4, minSize=(5, 5))
for x, y, w, h in face:
tab_face.append([x, y, x+w, y+h])
face=profile_cascade.detectMultiScale(gray, scaleFactor=1.2, minNeighbors=4)
for x, y, w, h in face:
tab_face.append([x, y, x+w, y+h])
gray2=cv2.flip(gray, 1)
face=profile_cascade.detectMultiScale(gray2, scaleFactor=1.2, minNeighbors=4)
for x, y, w, h in face:
tab_face.append([WIDTH-x, y, WIDTH-(x+w), y+h])
tab_face=sorted(tab_face, key=operator.itemgetter(0, 1))
index=0
for x, y, x2, y2 in tab_face:
if not index or (x-tab_face[index-1][0]>marge or y-tab_face[index-1][1]>marge):
cv2.rectangle(stream.array, (x, y), (x2, y2), (0, 0, 255), 2)
index+=1
if cv2.waitKey(1)&0xFF==ord('q'):
break
fps=cv2.getTickFrequency()/(cv2.getTickCount()-tickmark)
cv2.putText(stream.array, "FPS: {:05.2f}".format(fps), (10, 30), cv2.FONT_HERSHEY_PLAIN, 2, (255, 0, 0), 2)
cv2.imshow('video', stream.array)
stream.seek(0)
stream.truncate()
cv2.destroyAllWindows()