What I want to do is when the user click the buttom , django will run the python code and detect people. I use VideoStream from imutils.video but it just popup the window and freeze. It works prefectly when I test for the face recognition but once I put the same code to django. I mean it can still detect people but it only detect the first frame then it will freeze.
The VideoStream is from imutils.video and the cv2.imshow is from opencv.
Here is the code for the Video Stream. Even I run the Video Stream alone(without the face recognition code), it still freeze.
def detect(request):
vs = VideoStream("http://192.168.1.109:8080/video").start()
while True:
frame = vs.read()
cv2.imshow("Frame", frame)
key = cv2.waitKey(1) & 0xFF
if key == ord("q") :
break
else:
time.sleep(30)
break
cv2.destroyAllWindows()
vs.stop()
return render(request,"attendance/detect.html")
If it cannot be fix ,any recommendation than can do the same thing? Thank you
Try this:
while True:
frame = vs.read()
cv2.imshow("Frame", frame)
if cv2.waitKey(1) & 0xFF == ord("q"):
break
cv2.destroyAllWindows()
vs.stop()
Honestly I dont really understand what you want to do. You want to wait every 30s before you taking another picture? Your code seem to break while loop in both if condition and else condition
EDIT: 30s stream
2 Option
1) for 30s stream, you need to count your fps and break after reaching fps*30 loops.
2) create flag variable and timeout function
flag = 0
def timeout(sleep):
time.sleep(sleep)
flag = 1
threading.Thread(target = timetout, args=(30,)).start()
# in your loop then break when
if flag == 1:
break