- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有以下代码,我想用它来将 trainingLables Mat 的内容打印到 android 控制台:
#include <android/log.h>
JNIEXPORT jintArray JNICALL Java_com_example_user_activity_MainActivity_generateAssets(JNIEnv* env, jobject thiz, jobject assetManager) {
.....
.....
Mat_<int> trainingLabels(1,10);
trainingLabels << 0, 0, 0, 1, 1, 1, 0, 1, 1, 1;
__android_log_print(ANDROID_LOG_ERROR, "TESTING", "%d %d", trainingLabels.???????);
......
......
}
我有两个问题:
1) 我用什么方法从 trainingLabels 打印一行数据? (我在代码中用什么代替问号?)
2) 如何在 Android LogCat 中搜索来自 __android_log_print 的内容?
最佳答案
你可以简单地预先用你的数据准备一个字符串
char matRow[100] = ""; // You can calculate how much memory u need, but for debug prints just put a big enough number
Mat_<int> trainingLabels(1,10);
trainingLabels << 0, 0, 0, 1, 1, 1, 0, 1, 1, 1;
for (int i = 0; i < 10; i++) {
sprintf(matRow + strlen(matRow), "%d ", trainingLabels.at<int>(i)); // You can use data from row you need by accessing trainingLabels.row(...).data
}
android_log_print(ANDROID_LOG_ERROR, "SEARCH FOR THIS TAG", "%s", matRow);
然后在您的 logcat 中查找在我的示例中为“SEARCH FOR THIS TAG”的标签
至于您关于它如何存储在 Mat 对象中的其他问题 - 因为您使用 int 类型创建了 Mat - Mat.data 是 int 数组,您可以通过类似的东西轻松地看到它:
char matRow[100] = ""; // You can calculate how much memory u need, but for debug prints just put a big enough number
Mat_<int> trainingLabels(1,10);
trainingLabels << 0, 0, 0, 1, 1, 1, 0, 1, 1, 1;
int * data = (int*)trainingLabels.data;
for (int i = 0; i < 10; i++) {
sprintf(matRow + strlen(matRow), "%d ", data[i]); // You can use data from row you need by accessing trainingLabels.row(...).data
}
android_log_print(ANDROID_LOG_ERROR, "SEARCH FOR THIS TAG", "%s", matRow);
关于android - 使用 __android_log_print 打印 Opencv Mat、Android NDK 的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47952638/
打印到 stderr 的原始代码: extern "C" { /* error: output error message */ void Error(const int error, char *m
我使用这个库:https://github.com/mysolution/hyphenator在 JNI 中,我创建了这个函数: int main2() { //load russian hyphe
我正在尝试将此日志记录语句移植到工作中,因此它将在 linux 和 android 上运行我的#define'ing: __android_log_print(ANDROID_LOG_ERROR, L
我的 make 文件有什么问题? Android.mk LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := fo
我有一个类似的功能 __android_log_print(ANDROID_LOG_INFO, "HelloNDK!"); 在我的 C 代码上 我不会在我的 LogCat 上找到那个输出。我需要设置什
有一些像这样的问题,但提供的解决方案都没有解决问题。构建包含两个模块的应用程序时,Build 会输出标题中的错误。其中一个模块具有 native 代码文件。 我检查了很多线程,所有线程都建议包含 -l
此问题存在,但无法解决我的问题。我得到了对 __android_log_print 的 undefined reference ,但我有包含 header #include 我的 Android.m
这是.cpp文件,代码是 JNIEXPORT jint JNICALL Java_com_example_compute_MainActivity_AddNumbers(JNIEnv *env, jo
当在 native 代码中使用 __android_log_print() 时,它会打印并在文本末尾添加一个 /n。 我正在尝试获得与 printf 相同的行为,当未使用 /n 时,它会在同一行上打印
我有兴趣通过 NDK 应用演示 printf 漏洞。明确地说,我知道要登录控制台,我们可以使用 __android_log_print(ANDROID_LOG_DEBUG, "LOG_TAG", "P
我有以下代码,我想用它来将 trainingLables Mat 的内容打印到 android 控制台: #include JNIEXPORT jintArray JNICALL Java_com
我有一个 Android NDK 项目,其 NDK 部分从命令行编译正常;我以前在 Eclipse 下将编译好的东西作为纯 Java 项目运行没有问题。但是我将它转换为 C/C++ 项目,现在甚至无法
我是一名优秀的程序员,十分优秀!