gpt4 book ai didi

android - 使用 __android_log_print 打印 Opencv Mat、Android NDK 的内容

转载 作者:太空宇宙 更新时间:2023-11-03 22:22:12 25 4
gpt4 key购买 nike

我有以下代码,我想用它来将 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com