【发布时间】:2015-12-12 08:29:29
【问题描述】:
我将 OpenCV4Android 用于涉及 Java 和 C++ 代码的项目。 我正在使用 OpenCV 的 Java API 使用 FAST 特征检测器在图像中查找关键点。我需要将其输出(一组关键点)(即 Java 中的 MatofKeypoint 对象)传递给本机 C++ 方法。在 C++ 方法中,我需要将其用作向量,以便从中提取关键点描述符。
我从 java 中传递 MatofObject 并在 C++ 中将其作为 Mat& 接收,然后手动尝试通过手动读取每个点将 Mat& 转换为向量,如 here 所述。但是每次我使用致命信号 11,代码 1 访问接收到的 Mat& 对象时,程序都会崩溃。
我怀疑问题是由于 C++ 和 Java API 使用的数据结构不同造成的。
任何帮助将不胜感激,谢谢!!!
在 Java 中
public native void processImage(long matAddrTemplateKeypoints); // Native Method definition
FeatureDetector detector = FeatureDetector.create(FeatureDetector.FAST);
MatOfKeyPoint templateKeypoints = new MatOfKeyPoint();
detector.detect(img1, templateKeypoints);
processImage(templateKeypoints.getNativeObjAddr()); // Native method Call
在 C++ 中
JNIEXPORT void JNICALL MainActivity_processImage(JNIEnv*, jobject, jlong matAddrTemplateKeypoints)
Mat& templateKeypointMat = *(Mat*) matAddrTemplateKeypoints; // Casting received MatofPoint object as a Mat&
for(int i=0;i<templateKeypointMat.rows; i++){ // Code crashes here
...
}
【问题讨论】:
标签: android opencv java-native-interface opencv4android