RaspberryPi C ++应用程序使用OpenCV和Raspicam编译问题

时间:2015-07-18 22:53:56

标签: c++ opencv raspberry-pi

使用下面的代码,我试图用OpenCV + Raspicam在C ++中创建一个应用程序。此应用程序应实时将视频从连接到我的Pi的RasPi相机模型流式传输到Xwindow。

我在编译时遇到以下错误:

videofeed.cpp: In function ‘int main(int, char**)’:
videofeed.cpp:36:37: error: ‘cv::imread’ is not a member of ‘raspicam::RaspiCam_Cv’

我该如何解决这个问题?

#include "opencv2/highgui/highgui.hpp"
#include "opencv2/videoio.hpp"
#include <iostream>
#include </home/pi/raspicam-0.1.3/src/raspicam_cv.h>

using namespace std; 


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

    raspicam::RaspiCam_Cv Camera;
    cv::Mat image;
    int nCount=100;
    //set camera params
    Camera.set( CV_CAP_PROP_FORMAT, CV_8UC1 );
    //Open camera
    cout<<"Opening Camera..."<<endl;
    if (!Camera.open())// if not success, exit program
    {
        cout << "Cannot open the video cam" << endl;
        return -1;
    }

   double dWidth = Camera.get(CV_CAP_PROP_FRAME_WIDTH); //get the width of frames o$
   double dHeight = Camera.get(CV_CAP_PROP_FRAME_HEIGHT); //get the height of frame$

    cout << "Frame size : " << dWidth << " x " << dHeight << endl;

   cv::namedWindow("MyVideo",CV_WINDOW_AUTOSIZE); //create a window called "MyVideo"

    while (1)
    {
        cv::Mat frame;

        bool bSuccess =  Camera.cv::imread(frame);  // get a new frame from camera

         if (!bSuccess) //if not success, break loop
        {
             cout << "Cannot read a frame from video stream" << endl;
              break;
        }

   cv::imshow("MyVideo", frame); //show the frame in "MyVideo" window

        if (cv::waitKey(30) == 27) //wait for 'esc' key press for 30ms. If 'esc' ke$
       {
            cout << "esc key is pressed by user" << endl;
            break; 
       }
    }
    return 0;

}
///////////////////////////////////////////////////////////////////////////////////

1 个答案:

答案 0 :(得分:0)

bool bSuccess = Camera.cv::imread(frame);是错误,imread中没有raspicam::RaspiCam_Cv个功能。如果你想要grub一个框架,你可以使用函数grub而不是{{1} }。 例如:

retrieve

您可以看到声明:

Mat img;
camera.grab();
camera.retrieve(img);

此外,您可以参考:https://github.com/cedricve/raspicam