我设置了一个hello world
项目here这基本上是 gradle 项目中样本的复制/粘贴 here .
我的下一步是 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 header ,但我正在努力通过 gradle 添加库本身。我可能必须使用 prebuilt方式,但我失败了。
最佳答案
我认为您需要配置 header 和预建库链接:
我通常在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依赖,尝试以同样的方式添加。
希望对您有所帮助。
干杯。
乌奈。
关于c++ - 如何将 OpenCV 集成到 gradle 构建的 C++ 项目中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39477382/