Compiling C++ code using openCV in Beaglebone

假装没事ソ 提交于 2019-12-04 06:12:33

问题


I have written the following code in C++ which use openCV to be run in Beaglebone:

    #include <unistd.h>
    #include <stdlib.h>
    #include <stdio.h>
    #include <string.h>
    #include <errno.h>
    #include <fcntl.h>
    #include <termios.h>
    #include <sys/types.h>
    #include <sys/stat.h>
    #include <netinet/in.h>
    #include "opencv/cv.h"
    #include "opencv/highgui.h" 

    using namespace cv;
    using namespace std;

    int main(int argc, char *argv[])
    {
         CvCapture *capture = 0;
         Mat img3;
         Mat src;

         capture = cvCaptureFromCAM(0);

         vector<int> p;
         p.push_back(CV_IMWRITE_PNG_COMPRESSION);
         p.push_back(9);

         while (1) {
              img3 = cvQueryFrame(capture);
              cvtColor(img3, img3, CV_BGR2GRAY);
              pyrDown(img3, src, Size( img3.cols/2, img3.rows/2 ) );
              if (!imwrite("/home/root/Desktop/website/fig3bmp.bmp",src,p)) {
                  printf("mat not saved!!!\n"); 
              }
         }

         return 0; 
    }

I have tried compiling the code using: "g++ -o CamaraTest CamaraTest.cpp", but it does not work, and all the errors I get are something like: "undefined reference to: cv... "

I have already checked that the files "cv.h" and "highgui.h" are in the directory "/usr/include/opencv".

How can I compile this code? Any suggestion would help a lot.

Thanks in advance.

gus.


回答1:


These "undefined reference to: cv... " messages are linker errors due to missing libraries - you need to link with the OpenCV libraries in your g++ command line, e.g.:

$ g++ -Wall -g -o CamaraTest CamaraTest.cpp `pkg-config --cflags --libs opencv` 


来源:https://stackoverflow.com/questions/14565876/compiling-c-code-using-opencv-in-beaglebone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!