使用android log print打印Opencv Mat的内容,android NDK
我有以下代码,我想用它将trainingLables Mat的内容打印到android控制台:使用android log print打印Opencv Mat的内容,android NDK,android,c++,opencv,android-ndk,Android,C++,Opencv,Android Ndk,我有以下代码,我想用它将trainingLables Mat的内容打印到android控制台: #include <android/log.h> JNIEXPORT jintArray JNICALL Java_com_example_user_activity_MainActivity_generateAssets(JNIEnv* env, jobject thiz, jobject assetManager) { ..... ..... Mat_&
#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.???????);
......
......
}
#包括
JNIEXPORT jintArray JNICALL Java_com_示例_用户_活动_主活动_生成集合(JNIEnv*env、jobject thiz、jobject资产管理器){
.....
.....
材料培训标签(1,10);
trainingLabels您只需事先准备一个包含数据的字符串即可
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);
char matRow[100]=“”;//您可以计算您需要多少内存,但对于调试打印,只需输入足够大的数字即可
材料培训标签(1,10);
trainingLabels我用trainingLabels.data[I]试过这个,它给出10个0,我试过trainingLabels.row(0.data[I]这也给出了10个0。是否有其他方法可以访问trainingLabels中的数据?如果您知道答案,您是否可以解释Mat中的数据实际存储在哪里?我已经检查了android调试器上的数据元素,其中包含一组uchar*值,如\x05、\0、\x02。我假设他是我的数据转换成其他格式的吗?有没有办法读取我放在Mat(0,0,0,1,1,1,1,0,1,1)中的原始int值通过检查数据元素,或者打印出来?-提前谢谢。嘿@Ber12345我已经更新了我的答案,以便它打印正确的数据。还添加了关于如何使用Mat对象的数据字段的说明。不客气。字符数组中可能有一些垃圾。我编辑了答案(字符数组初始化为“”)
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);