[英]I can't capture frames from camera in OpenCV
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 这是我的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 这是我的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): 这是我的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)
cv2.VideoCapture(1)
至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. `也许您应该检查一下waitKey()。 Thanks. 谢谢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.