2016-09-13 68 views
1

我设置了一个hello world项目here,它基本上是来自gradle项目here的样本的复制/粘贴。如何通过gradle将OpenCV集成到C++项目中构建

我的下一步是hello world,但是对于OpenCV框架。它将读取内存中的图片并显示它。准确地说,在main.cpp将我们更像是

#include <stdio.h> 
#include <opencv2/opencv.hpp> 
using namespace cv; 
int main(int argc, char** argv) 
{ 
    if (argc != 2) 
    { 
     printf("usage: DisplayImage.out <Image_Path>\n"); 
     return -1; 
    } 
    Mat image; 
    image = imread(argv[1], 1); 
    if (!image.data) 
    { 
     printf("No image data \n"); 
     return -1; 
    } 
    namedWindow("Display Image", WINDOW_AUTOSIZE); 
    imshow("Display Image", image); 
    waitKey(0); 
    return 0; 
} 

正如你可以看到我包括OpenCV的头,但我挣扎的gradle通过添加的lib本身。我可能不得不使用prebuilt的方式,但我失败了。

回答

0

我认为你需要配置头和预建库联反应:

我通常在Android中,但我不能保证它的作品,因为我不知道什么是你的gradle这个插件。 但是,您可以将其用作线索,具体取决于您的gradle版本,语法可能会更改。

首先定义你的OpenCV目录:

opencv.dir="the site where opencv headers are" 

后定义你的OpenCV库,定义headers.srcDir

repositories { 
    libs(PrebuiltLibraries) { 
    opencv_core { 
    headers.srcDir "your opencv.dir" 
     binaries.withType(StaticLibraryBinary) { binary -> 
     // This closure will be executed once for every buildType/platform combination 
     def variantDir = binary.targetPlatform.architecture.name == 'i386' ? 'Win32' : 'x64' 
     staticLibraryFile = "path/to/library/${variantDir}/opencv_core.so" 
     } 
    } 
    opencv_another_lib { 
    headers.srcDir "your opencv.dir" 
     binaries.withType(StaticLibraryBinary) { binary -> 
     // This closure will be executed once for every buildType/platform combination 
     def variantDir = binary.targetPlatform.architecture.name == 'i386' ? 'Win32' : 'x64' 
     staticLibraryFile = "path/to/library/${variantDir}/opencv_another_lib.so" 
     } 
    } 
    } 

可能,例如opencv_core将有更多的3rparty依赖,尝试添加在同样的方式。

我希望这会有所帮助。

干杯。

Unai。

相关问题