【发布时间】:2015-10-05 14:22:21
【问题描述】:
我使用 OpenCV4Android,我需要使用 Android NDK 在 C++ 中计算一些值。在 OpenCV 文档中,我阅读了如何在 Java 和 C++ 之间传递 Mat 对象,这对于 CV_8U int 值很好。但是,如果我使用填充双打的 Mat 类型 CV_64FC1,我会得到一些奇怪的值。
有什么我需要的方法吗?
Java
MyNativeLib.myNativeFunction(mat.getNativeObjAddr());
C++
JNIEXPORT void JNICALL Java_de_my_package_MyNativeLib_myNativeFunction(JNIEnv *env, jlong mat_adress) {
cv::Mat& mat = *((cv::Mat*) mat_adress);
int i, j;
for(int i = 0; i < mat.rows; i++) {
for(int j = 0; j < mat.cols; j++) {
if(i < 5 && j == 0)
LOGI("Test output @ (%i,%i) = %f", i, j, (double) mat.data[i*mat.cols+j] );
}
}
}
我使用 CV_8U int 值的输入:
108.0
100.0
111.0
112.0
119.0
我的 jni 输出
Test output @ (0,0) = 108.000000
Test output @ (0,0) = 100.000000
Test output @ (0,0) = 111.000000
Test output @ (0,0) = 112.000000
Test output @ (0,0) = 119.000000
我的输入垫类型为 CV_64FC1
109.32362448251978
105.32362448251978
110.82362448251978
111.32362448251978
114.82362448251978
我的 jni 输出
Test output @ (0,0) = 223.000000
Test output @ (0,0) = 223.000000
Test output @ (0,0) = 223.000000
Test output @ (0,0) = 223.000000
Test output @ (0,0) = 223.000000
有人知道为什么会这样吗?
【问题讨论】:
-
除了
Test output @ (%d,%d)(可能)我在C++部分看不到任何问题。您能否也记录mat.type()并访问像mat.at<double>(i,j);这样的像素? -
非常感谢!! mat.at
(i,j) 为我修好了!顺便说一句 mat.type() 是 6. -
很高兴它成功了。然后发布了更详细的答案。
标签: android c++ opencv android-ndk java-native-interface