Python Forum
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Use OpenCV within FLASK
#1
Hi everyone, I would like to know if it is possible to run this code in my Flask app and turn on users camera to detect their faces. I tried but the server just crashes. Is there a way to do it with Python as my backend language or I should switch to a different approach? Also is it possible instead of waiting for Q to be pressed to quit, to get it to quit with a value returned from user input?

    face_detect = cv2.CascadeClassifier("C:\\Users\\HP\\Desktop\\workoutflow\\FLask\\Face\\haarcascade_frontalface_default.xml")
    camera = cv2.VideoCapture(0)

    while True:
        ret, img = camera.read()
        make_image_gray = cv2.cvtColor(img, cvt.COLOR_BGR2GRAY)
        user_face = face_detect.detectMultiScale(gray, 1.2, 5)
        for(x, y, w,  h) in user_face:
            cv2.rectangle(img, (x,y), (x+w, y+h), (0, 255, 0),2)
        cv2.imshow("Face",img)
        
        cam.release()
        cv2.destroyAllWindows()
Reply
#2
Do you want to stream camera live on a page or only control/user input to start stop/quit the program from Flask?
Reply
#3
I want both, to see how the face is recognized on the page and being able to quit the stream with a button by the user.
Reply
#4
You can look at Miguel Video Streaming with Flask.
Krokizo Wrote:being able to quit the stream with a button by the user.
You should try to be familiar with Ajax,
so when push start and quit button you never leave page with Steaming.
I have a couple of tutorials about in on this site.

Eg this one,
So when i push the button it update the page without reloading the whole page.
You would be calling a Python Quit function the same way.
Reply


Forum Jump:

User Panel Messages

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