'opencv face detection problems

Please help me resolve this **openCv **problem in faces

import cv2, time
first_frame = None
video = cv2.VideoCapture(0)
while True:
    check, frame=video.read()
    status=0
    print(check)
    print(frame)

    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    gray=cv2.GaussianBlur(gray,(21,21),0)

    if first_frame is None:
        first_frame=gray
        continue

    delta_frame=cv2.absdiff(first_frame, gray)
    thresh_frame=cv2.threshold(delta_frame, 30, 255, cv2.THRESH_BINARY)[1]
    thresh_frame=cv2.dilate(thresh_frame, None, iterations=2)

    (cnts,_) =cv2.findContours(thresh_frame.copy(),cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)

    for contour in cnts:
        if cv2.contourArea(contour) < 10000:
            continue
        status=1

        (x,y, w, h)=cv2.boundingRect(contour)
        cv2.rectangle(frame, (x, y), (x+w, y+h), (0,255,0), 3)

    cv2.imshow("Gray Frame", gray)
    cv2.imshow("Delta Frame",delta_frame)
    cv2.imshow("Threshold Frame", thresh_frame)
    cv2.imshow("color Frame", frame)

    key=cv2.waitKey(1)

    if key==ord('q'):
        break

    print(status)

video.release()
cv2.destroyAllWindows()

Problems

There are many problems here.

There are 2 rectangles coming on my face... when i go away from the camera, there is still a rectangle present in the background...this should not happen... Press "q" on your keyboard to exit.

The numpy array comes nicely but After exiting the code this error comes: [ WARN:0] global D:\a\opencv-python\opencv-python\opencv\modules\videoio\src\cap_msmf.cpp (438) `anonymous-namespace'::SourceReaderCB::~SourceReaderCB terminating async callback

The delta frame and threshold frame are also not working properly.

Please run my code in your code editor to fully understand and recognize the problem.

Keep in mind that my computer camera quality is bad.

Please help me resolve this issue by giving the complete solved code to me.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source