Hello all! thank you for reading and hopefully helping with my issue.
trying to run OpenCV through python spyder on anaconda. I am following an online course where they have created a virtual environment so that everything that is required should be there. I have also run it through my own anaconda OpenCV spyder install (I've tried asking the creator but no response from them
)
I've run the following code that they created which is below and then I got an error which I can't seem to find online either (error code also below)
I've been trying to alter different parts to see what I can sus out and I think it has to do with some variables not being created as variables which is strange. I've tried creating other variables which show up in spyders variable explore but these particular two just don't seem to be created. they are as follows:
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
eye_cascade = cv2.CascadeClassifier('haarcascade_eye.xml')
I've set up the working directory file containing all the files including the cascade files etc.
I'm very stuck on what is causing this so I'm hoping someone in the community has encountered.
I'm also well aware that this may be normal and its something completely different going wrong and I am just beginning my python journey.
anyway thank you to those that can offer advice.
the code:
trying to run OpenCV through python spyder on anaconda. I am following an online course where they have created a virtual environment so that everything that is required should be there. I have also run it through my own anaconda OpenCV spyder install (I've tried asking the creator but no response from them

I've run the following code that they created which is below and then I got an error which I can't seem to find online either (error code also below)
I've been trying to alter different parts to see what I can sus out and I think it has to do with some variables not being created as variables which is strange. I've tried creating other variables which show up in spyders variable explore but these particular two just don't seem to be created. they are as follows:
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
eye_cascade = cv2.CascadeClassifier('haarcascade_eye.xml')
I've set up the working directory file containing all the files including the cascade files etc.
I'm very stuck on what is causing this so I'm hoping someone in the community has encountered.
I'm also well aware that this may be normal and its something completely different going wrong and I am just beginning my python journey.
anyway thank you to those that can offer advice.
the code:
# Face Recognition # Importing the libraries import cv2 # Loading the cascades face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml') eye_cascade = cv2.CascadeClassifier('haarcascade_eye.xml') # Defining a function that will do the detections def detect(gray, frame): 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) roi_gray = gray[y:y+h, x:x+w] roi_color = frame[y:y+h, x:x+w] eyes = eye_cascade.detectMultiScale(roi_gray, 1.1, 3) for (ex, ey, ew, eh) in eyes: cv2.rectangle(roi_color, (ex, ey), (ex+ew, ey+eh), (0, 255, 0), 2) return frame # Doing some Face Recognition with the webcam video_capture = cv2.VideoCapture(0) while True: _, frame = video_capture.read() gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) canvas = detect(gray, frame) cv2.imshow('Video', canvas) if cv2.waitKey(1) & 0xFF == ord('q'): break video_capture.release() cv2.destroyAllWindows()the kernnel with error at bottom:
import cv2 # Loading the cascades face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml') eye_cascade = cv2.CascadeClassifier('haarcascade_eye.xml') # Defining a function that will do the detections def detect(gray, frame): 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) roi_gray = gray[y:y+h, x:x+w] roi_color = frame[y:y+h, x:x+w] eyes = eye_cascade.detectMultiScale(roi_gray, 1.1, 3) for (ex, ey, ew, eh) in eyes: cv2.rectangle(roi_color, (ex, ey), (ex+ew, ey+eh), (0, 255, 0), 2) return frame # Doing some Face Recognition with the webcam video_capture = cv2.VideoCapture(0) while True: _, frame = video_capture.read() gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) canvas = detect(gray, frame) cv2.imshow('Video', canvas) if cv2.waitKey(1) & 0xFF == ord('q'): break video_capture.release() cv2.destroyAllWindows()
Error:Traceback (most recent call last):
File "<ipython-input-1-806d0e67c07b>", line 25, in <module>
canvas = detect(gray, frame)
File "<ipython-input-1-806d0e67c07b>", line 9, in detect
faces = face_cascade.detectMultiScale(gray, 1.3, 5)
error: /Users/jenkins/miniconda/1/x64/conda-bld/conda_1486587097465/work/opencv-3.1.0/modules/objdetect/src/cascadedetect.cpp:1639: error: (-215) !empty() in function detectMultiScale