Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tkinter and OpenCV
#3
Hi, I only have the code for recognition.

import cv2
import operator

face_cascade = cv2.CascadeClassifier("./haarcascade_frontalface_alt2.xml")  
profile_cascade = cv2.CascadeClassifier("./haarcascade_profileface.xml")

webcam = cv2.VideoCapture(0)  

width = int(webcam.get(3)) 
marge = 80

while True:
    ret, frame = webcam.read() 
    tab_face = [] 

    speed = cv2.getTickCount() 

    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

    face = face_cascade.detectMultiScale(gray, scaleFactor=1.2, minNeighbors=4)   

    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) == ord('q'):
        break
    fps = cv2.getTickFrequency() / (cv2.getTickCount()-speed) 
    cv2.putText(frame, "FPS : {:05.2f}".format(fps), (10, 30), cv2.FONT_HERSHEY_PLAIN, 2, (255, 0, 0), 2)
    cv2.imshow('video', frame)

webcam.release()
cv2.destroyAllWindows()
Reply


Messages In This Thread
Tkinter and OpenCV - by VHS - Jan-28-2021, 10:37 PM
RE: Tkinter and OpenCV - by Larz60+ - Jan-29-2021, 02:28 AM
RE: Tkinter and OpenCV - by VHS - Jan-29-2021, 10:52 AM
RE: Tkinter and OpenCV - by nilamo - Jan-29-2021, 06:58 PM
RE: Tkinter and OpenCV - by VHS - Jan-29-2021, 11:54 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Python + OpenCV + Tkinter playing video help Hanban 1 18,050 May-08-2017, 01:25 AM
Last Post: Joseph_f2

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020