在Mac Terminal上运行简单的C ++ OpenCV

时间:2018-07-03 19:05:54

标签: c++ xcode opencv

我是使用cpp和opencv的完整入门者。我想编译并运行这个简单的程序,该程序可以显示图像。如果我在XCode中运行代码,这会起作用,但是如果我在控制台中使用clang尝试它,则会抛出一个

linker command failed with exit code 1 (use -v to see invocation)

我已经在Xcode中添加了这些“链接器标志”以使opencv运行,所以我认为我也需要以某种方式在全局安装它们。 H我将如何实现?

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>

using namespace cv;
using namespace std;

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

if (argc != 2) {
    cout << "Bitte zu ladendes Bild als Parameter angeben." << endl;
    return -1;
}

Mat image;
image = imread(argv[1], CV_LOAD_IMAGE_COLOR);

if (!image.data) {
    cout <<  "Bild " << argv[1] << " wurde nicht gefunden." << std::endl ;
    return -1;
}

namedWindow("OpenCV Window", WINDOW_AUTOSIZE);
imshow("OpenCV Window", image);

cout << "Image width: " << image.cols << ", image height: " << 
image.rows << endl;

waitKey(0);

return 0;
} 

这些是Xcode中的链接器标志:

-lopencv_calib3d -lopencv_core -lopencv_features2d -lopencv_flann -lopencv_highgui -lopencv_imgcodecs -lopencv_imgproc -lopencv_ml -lopencv_objdetect -lopencv_photo -lopencv_shape -lopencv_stitching -lopencv_superres -lopencv_video -lopencv_videoio -lopencv_videostab

0 个答案:

没有答案