繁体   English   中英

Beaglebone上的OpenCV编译错误

[英]OpenCV compiling error on Beaglebone

我使用此处提到的步骤安装了Ubuntu 14.04和Opencv https://solarianprogrammer.com/2014/04/21/opencv-beaglebone-black-ubuntu/
我正在尝试编译以下代码(保存在名为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;
}

使用g ++ test2.cpp -o test2 -lopencv_core -lopencv_imgproc -lopencv_highgui我还尝试告诉编译器库在哪里使用-L / usr / local / lib。 (在那里找到libopencv文件)。 但是每次都会出现以下错误:

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

有人可以帮我吗? 任何帮助,将不胜感激。

我发现使用以下命令进行编译始终非常方便和安全:

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

如果不存在,请安装pkg-config

暂无
暂无

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

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