简体   繁体   English

在树莓派 2 上使用 opencv C++

[英]Use opencv C++ on raspberry pi 2

I am successfully running opencv python code on raspberry pi 2 (raspbian).我在 raspberry pi 2 (raspbian) 上成功运行了 opencv python 代码。 Now I want to try to compile opencv C++ code on raspberry pi 2 by using this command:现在我想尝试使用以下命令在 raspberry pi 2 上编译 opencv C++ 代码:

g++ -std=c++0x test_colour_tracking_1.cpp -otest_colour

The C++ coding as below. C++ 编码如下。

#include <iostream>
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
using namespace cv;
using namespace std;
int main(int argc, char** argv)
{
    VideoCapture cap(0); //capture the video from web cam
    if ( !cap.isOpened() )  // if not success, exit program
    {
         cout << "Cannot open the web cam" << endl;
         return -1;
    }
    while (true)
    {
        Mat imgOriginal;    
        bool bSuccess = cap.read(imgOriginal); // read a new frame from video

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

But it show error as below.但它显示如下错误。

/tmp/ccHcCqSm.o: In function `main':
test_colour_tracking_1.cpp:(.text+0x70): undefined reference to `cv::VideoCapture::VideoCapture(int)'
test_colour_tracking_1.cpp:(.text+0x7c): undefined reference to `cv::VideoCapture::isOpened() const'
test_colour_tracking_1.cpp:(.text+0xd8): undefined reference to `cv::VideoCapture::read(cv::Mat&)'
test_colour_tracking_1.cpp:(.text+0x150): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
test_colour_tracking_1.cpp:(.text+0x164): undefined reference to `cv::imshow(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&)'
test_colour_tracking_1.cpp:(.text+0x1a4): undefined reference to `cv::VideoCapture::~VideoCapture()'
test_colour_tracking_1.cpp:(.text+0x1f0): undefined reference to `cv::VideoCapture::~VideoCapture()'
/tmp/ccHcCqSm.o: In function `cv::Mat::~Mat()':
test_colour_tracking_1.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x3c): undefined reference to `cv::fastFree(void*)'
/tmp/ccHcCqSm.o: In function `cv::Mat::release()':
test_colour_tracking_1.cpp:(.text._ZN2cv3Mat7releaseEv[cv::Mat::release()]+0x58): undefined reference to `cv::Mat::deallocate()'
collect2: ld returned 1 exit status

And I want to ask how to check frame rate per second?我想问一下如何查看每秒帧数?

尝试使用以下命令:

g++ -std=c++0x test_colour_tracking_1.cpp -o test_colour `pkg-config --cflags --libs opencv`

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

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