繁体   English   中英

我无法从OpenCV的摄像头捕获帧

[英]I can't capture frames from camera in OpenCV

我试图检测眼睛,但是我还有另一个问题。 我无法显示相机框。 问题可能很明显,但我是新手。 我的部分代码如下:

这是我的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();
}; 

这是我的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);
    }
}

这是我的Source.cpp(main):

#include "EyeDetection.h"

using namespace cv;

int main(int argc, char** argv)
{
    EyeDetection e = EyeDetection();
    e.detect();
    return 0;
}

它不显示相机框架,而仅显示空白的灰色窗口。 问题是什么?

  1. 请检查您的摄像机ID1。如果只有一台已连接的摄像机,请更换摄像机ID 0代替1。

cv2.VideoCapture(1)cv2.VideoCapture(0)

  1. 添加waitKey()行在循环末尾添加此行

`

while (1) {
        webcam >> frame;
        if (frame.empty()) continue;
        imshow("asad", frame);
        cv2.waitkey(0)
    }

`也许您应该检查一下waitKey()。 谢谢。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM