简体   繁体   English

如何在c ++ openCV中使用raspberry pi摄像头作为视频输入?

[英]how to use the raspberry pi camera as video input in c++ openCV?

This is how I usually process video's in openCV. 这就是我通常在openCV中处理视频的方式。

#include <iostream>
#include<opencv2/opencv.hpp>

int main(int argc, char** argv)
{

        Mat output;
        VideoCapture cap(CV_CAP_ANY);


        if( !cap.isOpened() )
        {
            cout << "Could not initialize capturing...\n";
            return 0;
        }


        while(1){
            cap >> output;

            imshow("webcam input", output);
            char c = (char)waitKey(10);
            if( c == 27 ) break;
          }
}

Now I have a raspberry pi camera and I have the following minimal: 现在我有一个覆盆子pi相机,我有以下最小:

#include <iostream>
#include<opencv2/opencv.hpp>
#include <raspicam/raspicam_cv.h>


int main(int argc, char** argv)
{

        Mat image, output;
        //VideoCapture cap(CV_CAP_ANY);
    raspicam::RaspiCam_Cv cap;

        if( !cap.isOpened() )
        {
            cout << "Could not initialize capturing...\n";
            return 0;
        }

        while(1){
            cap >> output;

            imshow("webcam input", output);
            char c = (char)waitKey(10);
            if( c == 27 ) break;
         }
}

However the latter doesn't work, this is what is output to the terminal when I compile it: http://paste.ubuntu.com/24324541/ 然而后者不起作用,这是我编译时输出到终端的内容: http//paste.ubuntu.com/24324541/

Could someone tell me what the correct way to do this is? 有人能告诉我这样做的正确方法是什么?

Thank you 谢谢

According to the documentation , you cannot use it as a stream, but instead must do this: 根据文档 ,您不能将它用作流,但必须这样做:

while(1){
    cap.grab();
    cap.retrieve(output);

    imshow("webcam input", output);
    char c = (char)waitKey(10);
    if( c == 27 ) break;
}

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

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