I am trying to detect eyes but I have another problem. I cannot display the camera frame. The problem can be obvious but I am newbie. A part of my code below:
Here is my EyeDetection.h
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/objdetect/objdetect.hpp>
using namespace cv;
class EyeDetection {
private:
CascadeClassifier eye_cascade, eyepair_cascade;
public:
EyeDetection();
void detect();
};
Here is my EyeDetection.cpp
#include "EyeDetection.h"
EyeDetection::EyeDetection() {
eye_cascade.load("haarcascade_eye.xml");
eyepair_cascade.load("haarcascade_mcs_eyepair_big.xml");
}
void EyeDetection::detect()
{
VideoCapture webcam(1); //Webcam number is 1
if (eyepair_cascade.empty() || eye_cascade.empty() || !(webcam).isOpened())
return;
webcam.set(CV_CAP_PROP_FRAME_WIDTH, 800);
webcam.set(CV_CAP_PROP_FRAME_HEIGHT, 600);
Mat frame;
while (1) {
webcam >> frame;
if (frame.empty()) continue;
imshow("asad", frame);
}
}
And here is my Source.cpp(main):
#include "EyeDetection.h"
using namespace cv;
int main(int argc, char** argv)
{
EyeDetection e = EyeDetection();
e.detect();
return 0;
}
It does not show the camera frame, it shows just a blank gray window. What is the problem?
cv2.VideoCapture(1)
to cv2.VideoCapture(0)
`
while (1) {
webcam >> frame;
if (frame.empty()) continue;
imshow("asad", frame);
cv2.waitkey(0)
}
` Maybe to check about waitKey() should be needed for you. Thanks.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.