Beaglebone上的OpenCV编译错误

OpenCV compiling error on Beaglebone

本文关键字:错误 编译 OpenCV 上的 Beaglebone      更新时间:2023-10-16

我使用这里提到的步骤安装了Ubuntu 14.04和Opencvhttps://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,请安装。