Initial commit
This commit is contained in:
17
OpenCV/tutoriel3/README.md
Normal file
17
OpenCV/tutoriel3/README.md
Normal 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
|
||||
|
||||
|
||||
19
OpenCV/tutoriel3/body_camera.py
Normal file
19
OpenCV/tutoriel3/body_camera.py
Normal 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()
|
||||
3
OpenCV/tutoriel3/cars.mp4
Normal file
3
OpenCV/tutoriel3/cars.mp4
Normal 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
20
OpenCV/tutoriel3/cars.py
Normal 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
3654
OpenCV/tutoriel3/cars.xml
Normal file
File diff suppressed because it is too large
Load Diff
12213
OpenCV/tutoriel3/haarcascade_eye.xml
Normal file
12213
OpenCV/tutoriel3/haarcascade_eye.xml
Normal file
File diff suppressed because it is too large
Load Diff
20719
OpenCV/tutoriel3/haarcascade_frontalface_alt2.xml
Normal file
20719
OpenCV/tutoriel3/haarcascade_frontalface_alt2.xml
Normal file
File diff suppressed because it is too large
Load Diff
17030
OpenCV/tutoriel3/haarcascade_fullbody.xml
Normal file
17030
OpenCV/tutoriel3/haarcascade_fullbody.xml
Normal file
File diff suppressed because it is too large
Load Diff
29690
OpenCV/tutoriel3/haarcascade_profileface.xml
Normal file
29690
OpenCV/tutoriel3/haarcascade_profileface.xml
Normal file
File diff suppressed because it is too large
Load Diff
19
OpenCV/tutoriel3/visage_camera.py
Normal file
19
OpenCV/tutoriel3/visage_camera.py
Normal 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()
|
||||
27
OpenCV/tutoriel3/visage_camera_raspberry.py
Normal file
27
OpenCV/tutoriel3/visage_camera_raspberry.py
Normal 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()
|
||||
37
OpenCV/tutoriel3/visage_camera_v2.py
Normal file
37
OpenCV/tutoriel3/visage_camera_v2.py
Normal 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()
|
||||
43
OpenCV/tutoriel3/visage_camera_v2_raspberry.py
Normal file
43
OpenCV/tutoriel3/visage_camera_v2_raspberry.py
Normal 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()
|
||||
Reference in New Issue
Block a user