使用__android_log_print打印Opencv Mat,Android NDK的内容

书到用时方恨少,事非经过不知难。这篇文章主要讲述使用__android_log_print打印Opencv Mat,Android NDK的内容相关的知识,希望能为你提供帮助。
我有以下代码,我想用它来将trainingLables Mat的内容打印到android控制台:

#include < android/log.h> JNIEXPORT jintArray JNICALLjava_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 numberMat_< 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中查找标签,在我的例子中是“搜索此标签”
【使用__android_log_print打印Opencv Mat,Android NDK的内容】关于它如何存储在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 numberMat_< int> trainingLabels(1,10); trainingLabels < < 0, 0, 0, 1, 1, 1, 0, 1, 1, 1; int * data = https://www.songbingjia.com/android/(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);


    推荐阅读