bonjour j'espère que vous allez bien dans un projet personnel j'ai essayé l'opencv en python mais le rectangle n'apparait pas et les chiffres non plus voici le code merci pour votre aide
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
 
import numpy as np
import cv2
 
face_cascade = cv2.CascadeClassifier('cascades/data/haarcascade_frontalface_alt2.xml')
#I tried to change this line by face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'cascades/data/haarcascade_frontalface_alt2.xml') the camera no longer works the error comes from line 12 (faces = face_cascade.detectMultiScale(gray, scaleFactor=1.5, minNeighbors=5))
 
cap = cv2.VideoCapture(0)
 
while(True):
    ret, frame = cap.read()
    gray  = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    faces = face_cascade.detectMultiScale(gray, scaleFactor=1.5, minNeighbors=5)
    for(x,y,w,h) in faces:
        print(x,y,w,h)
        roi_gray=gray[y:y+h,x:x+w]
        roi_color=frame[y:y+h,x:x+w]
        img_item="my-image.png"
        cv2.imwrite(img_item,roi_gray)
 
        color=(255,0,0)
        stroke=2
        x1=x+w
        y1=y+h
        cv2.rectangle(frame,(x,y),(x1,y1),color,stroke)
 
    cv2.imshow('frame',frame)
    if cv2.waitKey(20) & 0xFF == ord('q'):
        break
 
cap.release()
cv2.destroyAllWindows()