Blue square not showing oh screen
Hello folk. I just started using opencv--python.
Intially I typed in some code found here.
But when I typed in the code to my windows 7 64 bit computer and ran it. After a few syntax errors and typos on my part it ran just fine. I dectected the web camera that I have plugged in and it displayed the cameras video in a window. But I do not get that blue square that says it has detected my face. I am using a celron 2200 mhz with 2gb of ram so its not the fastest computer . Is it just that my computer is slow or is there something wrong with the code?
Ok here is the code. It was in the youtube video on the link that I posted,
import numpy as np
import cv2
#some comment i a foreign language which I cannot understand. I will put it
#thru Altavista later
face_cascade = cv2.CascadeClassifier('haarscascade_frontalface_default.xml')
video_capture = cv2.VideoCapture(0)
while True:
ret, frame = video_capture.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
#capture test with image.
#img = cv2.imread("wyld2.jpg")
# gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray,1.3,5)
for(x,y,w,h) in faces:
cv2.rectangle(frame,(x,y),(x+w,y+h),(255,0,0),2)
cv2.imshow('video', frame)
#some more foreign comments
if cv2.waitKey(1) & 0xFF == ord('q'):
break
video_capture.release()
cv2.destroyAllWindows()
Post your code.
without seeing anything of your stuff, i bet a beer, that it did not find the xml file for the cascade, because the path was wrong.
please try like:
cv2.CascadeClassifier('complete/path/to/haarscascade_frontalface_default.xml')
it's most probably in opencv/data/haarcascades
also:
Like @berak said, 98% of cascade errors result from not reading correctly the model and not capturing the return value!