简体   繁体   中英

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/
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) :

// 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 . (the libopencv files were found there). 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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