- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在开发一个 Android 应用程序,可以从任何捕获的图像中提取词袋为此,我将使用 opencv 库来实现此 tutorial
现在我有了一个 C++ 方法:void extractTrainingVocabulary(const path& basepath) {...}
我在我的 android Activity 中需要它
void extractTrainingVocabulary(const path& basepath) {
for (directory_iterator iter = directory_iterator(basepath); iter
!= directory_iterator(); iter++) {
directory_entry entry = *iter;
if (is_directory(entry.path())) {
cout << "Processing directory " << entry.path().string() << endl;
extractTrainingVocabulary(entry.path());
} else {
path entryPath = entry.path();
if (entryPath.extension() == ".jpg") {
cout << "Processing file " << entryPath.string() << endl;
Mat img = imread(entryPath.string());
if (!img.empty()) {
vector<KeyPoint> keypoints;
detector->detect(img, keypoints);
if (keypoints.empty()) {
cerr << "Warning: Could not find key points in image: "
<< entryPath.string() << endl;
} else {
Mat features;
extractor->compute(img, keypoints, features);
bowTrainer.add(features);
}
} else {
cerr << "Warning: Could not read image: "
<< entryPath.string() << endl;
}
}
}
}
}
所以按照 android NDK
教程我应该这样声明这个方法:public native void extractTrainingVocabulary () ;
我的问题是如何处理 C++ 参数 const path& basepath
?如何在java方法中传递这个参数
我希望我的问题对你来说是清楚的谢谢
最佳答案
第一个问题是,C/C++代码中path
的基类型是什么,比如这个是String,那么Java方法需要声明一个String值作为输入。
class Dude{
public native void extractTrainingVocabulary(final String arg);
}
首先用javac Dude.java
编译dude类然后你需要头文件,将生成的类文件传递给javah Dude
,然后javah
会给你一个头文件,像这样。
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class Dude */
#ifndef _Included_Dude
#define _Included_Dude
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: Dude
* Method: extractTrainingVocabulary
* Signature: (Ljava/lang/String;)V
*/
JNIEXPORT void JNICALL Java_Dude_extractTrainingVocabulary
(JNIEnv *, jobject, jstring);
#ifdef __cplusplus
}
#endif
#endif
在上面的代码中,jstring
指向该方法的 Java 输入参数,您可能需要使用那个人。下一步是实现 Java_Dude_extractTrainingVocabulary
函数并调用实际方法。
关于java - android NDK——将C++方法转换为java方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19492187/
我想使用 ndk 构建一个 3rd 方库 avahi。 avahi 已经有 android 端口(带有有效的 Android.mk)。 我做了什么: 我已经成功创建了一个项目并将所有源代码复制到 jn
由于不再需要Android NDK,因此我尝试将其卸载。在Eclipse中找到的路径似乎已损坏。我应该如何清理这个烂摊子?我尝试了brew,但它说未安装NDK。 (它甚至告诉我未安装SDK!也许不是通
我是 Android Studio 和 Android NDK 的新手。我正在尝试使用 android NDK 为类分配编译一个简单的 hello.c 程序。我已按照以下项目说明进行操作,但出现错误:
当我尝试执行 NDK 构建时,我收到以下错误列表...有人知道吗? encies\FreeImage/D:/Projects.CPP/Engine5/svn/trunk/Dependencies/Fr
我正在使用 android-ndk-profiler-3.1 为我的项目进行 NDK 分析。我在 Android.mk 中进行了如下更改... LOCAL_PATH := $(call my-dir)
我需要使用 cutils 库和头文件在我的 NDK 项目中实现 ashmem,但我在我的系统中找不到与 cutils 相关的任何内容。它位于何处或从何处获得? 最佳答案 Android“cutils”
我有两个独立的项目,一个项目用于构建 Boost 库,另一个项目从构建的 boost 库中调用。 Boost 项目编译良好并生成 libboost.a 文件。我想要实现的是将此库添加到我的其他 NDK
我在ndk-build clean上遇到以下错误 mo@mo-Toshiba ~/Workspace/AndroidApp/jni/android_programming_driver $ ndk-b
已结束。此问题正在寻求书籍、工具、软件库等的推荐。它不满足Stack Overflow guidelines 。目前不接受答案。 我们不允许提出寻求书籍、工具、软件库等推荐的问题。您可以编辑问题,以便
我正在尝试使用 NDK(又使用开放 SLES)在 Android 上创建一个基于流的音频应用程序。我已经完成了基本的流媒体设置。我需要知道 Android 中如何处理欠载(或重载)?错误回调是如何实现
我的 Application.mk 设置为构建 arm 以及 x86 共享库: APP_ABI :- armeabi-v7a x86 我有预建的 openssl 静态库: libcrypto_v7a.
我的 $NDK_HOME 文件夹包含标准库的不同实现。 qdii@nomada /opt/android-ndk/platforms $ ls -l total 24 drwxr-xr-x 5 roo
如何安装android-ndk。我已经为 ndk 设置了路径,但在执行“ndk-build”命令时仍然出现错误。 fya 我正在使用 Windows 操作系统。 最佳答案 它对我有用: 打开命令提示符
构建 Android-ndk 时出现以下错误 请帮助我。 Cygwin.bat @echo off set IS_UNIX= set DEV_ROOT=C:/iliu-Android-NDK-Fibo
我开始使用 android ndk (r8c),为此我安装了新版本的 Ubuntu 12.10 (32bit) 问题,无论我尝试构建什么,我都会遇到让我发疯的怪异错误...... ~/workspac
我正在尝试向我的 Android 项目添加 Crashlytics 支持,该项目使用 NDK 和 gradle CMake。这意味着我的共享项目需要符号。所以如果我想为发布版本创建符号,我会调用 gr
我想知道是否有人设法使用 Android NDK(r8d) 的工具链构建了新的 SDL2。 SDL2 似乎非常接近发布(从昨天开始,它不再是“正在 build 中:http://hg.libsdl.o
我试图在“ndk-build”过程中禁用所有警告,以编译与 Android 上的 JNI 一起使用的 CPP 代码。 我正在使用 LOCAL_CFLAGS := -Wno-error没有成功。 有任何
谁能告诉我如何在android(ndk-build)中建立C-ares库 最佳答案 这是使用NDK standalone toolchain将其构建为ARMv7的静态库的方法: export NDK=
我正在尝试从我的 native 代码中读取一个简单的文本文件。 我把file.txt放在assets文件夹下 在我的事件中,我正在创建 Assets 管理器:assetManager = getAss
我是一名优秀的程序员,十分优秀!