简体   繁体   English

Beaglebone上的OpenCV编译错误

[英]OpenCV compiling error on Beaglebone

I installed Ubuntu 14.04 and Opencv using the steps mentioned here https://solarianprogrammer.com/2014/04/21/opencv-beaglebone-black-ubuntu/ 我使用此处提到的步骤安装了Ubuntu 14.04和Opencv https://solarianprogrammer.com/2014/04/21/opencv-beaglebone-black-ubuntu/
I am trying to compile the following code (saved in text file named as test2.cpp. test2.cpp and lena.jpg were copied to beaglebone home folder) : 我正在尝试编译以下代码(保存在名为test2.cpp的文本文件中。将test2.cpp和lena.jpg复制到beaglebone主文件夹中):

// Test to convert a color image to gray
// Build on Linux with:
// g++ test2.cpp -o test2 -lopencv_core -lopencv_imgproc -lopencv_highgui

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

int main() {
    // Load the image file and check for success
    cv::Mat input = cv::imread("lena.jpg", 1);
    if(!input.data) {
        std::cout << "Unable to open the image file" << std::endl;
        return -1;
    }

    // Convert the input file to gray
    cv::Mat gray_image;
    cvtColor(input, gray_image, cv::COLOR_BGR2GRAY);

    // Save the result
    cv::imwrite("lena_gray.jpg", gray_image);

    return 0;
}

using g++ test2.cpp -o test2 -lopencv_core -lopencv_imgproc -lopencv_highgui I also tried telling the compiler where the libraries are using -L /usr/local/lib . 使用g ++ test2.cpp -o test2 -lopencv_core -lopencv_imgproc -lopencv_highgui我还尝试告诉编译器库在哪里使用-L / usr / local / lib。 (the libopencv files were found there). (在那里找到libopencv文件)。 But got the following error each time: 但是每次都会出现以下错误:

ubuntu@arm:~$ g++ test2.cpp -o test2 -lopencv_core -lopencv_imgproc -lopencv_highgui -L usr/local/lib
/tmp/cckXjOPd.o: In function `main':
test2.cpp:(.text+0x26): undefined reference to `cv::imread(cv::String const&, int)'
test2.cpp:(.text+0xf0): undefined reference to `cv::imwrite(cv::String const&, cv::_InputArray const&, std::vector<int, std::allocator<int=""> > const&)'
collect2: error: ld returned 1 exit status

Can someone help me out here? 有人可以帮我吗? Any help would be appreciated. 任何帮助,将不胜感激。

I find it always convenient and safe to compile using: 我发现使用以下命令进行编译始终非常方便和安全:

g++ test2.cpp -o test2 `pkg-config --libs --cflags opencv`

Install pkg-config if not already present. 如果不存在,请安装pkg-config

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

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