简体   繁体   中英

Error compiling opencv2 with aruco in c++

I have written a simple code for creating makers in aruco library which is

#include <opencv2/highgui/highgui.hpp>
#include <opencv2/aruco.hpp>

using namespace cv;

int main(int argc, char *argv[]) {


int dictionaryId = 100;
int markerId = 45;
int borderBits = 2;
int markerSize = 2450;
bool showImage = true;

cv::Ptr<aruco::Dictionary> dictionary = aruco::getPredefinedDictionary(aruco::PREDEFINED_DICTIONARY_NAME(dictionaryId));

Mat markerImg;
aruco::drawMarker(dictionary, markerId, markerSize, markerImg, borderBits);

if(showImage) {
    imshow("marker", markerImg);
    waitKey(0);
}

imwrite("out.png", markerImg);

return 0;
}

when i try to compile and run it using the command

g++ -I/usr/local/include/opencv -I/usr/include/opencv2 -L/usr/local/lib/ -g -o binary create_marker.cpp -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_stitching -lopencv_aruco

as given in one of the solutions of this site it gives this error

g++ -I/usr/local/include/opencv -I/usr/include/opencv2 -L/usr/local/lib/ -g -o binary create_marker.cpp -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_stitching -lopencv_aruco /usr/bin/ld: cannot find -lopencv_aruco collect2: error: ld returned 1 exit status

can someone please point out what am i doing wrong, as i'am new to opencv Thanks!!

Use this command:

g++ -std=c++11  file_to_run.cpp  -o output_binary_name  -I/usr/local/include -L/usr/local/lib -lopencv_highgui -lopencv_aruco -lopencv_imgcodecs -lopencv_core -lopencv_videoio -lopencv_calib3d -lopencv_imgproc

If it still does not work, post the error again.

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