1 | initial version |
all it needs is to reorganise the logic. right now, you're only showing an image, IF there was a detection. change that !
import cv2
cascade = cv2.CascadeClassifier('xcascade.xml')
cap = cv2.VideoCapture(1)
num = 0
while num<1000:
ret, img = cap.read()
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
cas = cascade.detectMultiScale(gray, 10, 10)
for(x,y,w,h) in cas:
font = cv2.FONT_HERSHEY_SIMPLEX
cv2.rectangle(img,(x,y), (x+w,y+h),(255,255,0),5)
cv2.putText(img, 'Something',(x,y-120), font, 1.5, (0,255,255),5, cv2.LINE_AA)
num = num+1
cv2.imshow('img',img)
if (cv2.waitKey(1000) == 27): # escape pressed
break
cap.release()
cv2.destroyAllWindows() # your code *never reached *that typo ;)