Pass MatofKeypoint from Java to c++ as vector<Keypoint> - OpenCV4Android

asked 2015-12-12 02:43:00 -0500

I am using OpenCV4Android for a project which involves both Java as well as C++ code. I am finding keypoints in an image using FAST feature detector using OpenCV's Java API. I need to pass its output (set of keypoints) which is a MatofKeypoint object in Java to a native C++ method. In the C++ method I need to use it as vector so that I can extract Keypoint descriptors form it.

I passed MatofObject form java and received it as a Mat& in C++, then manually tried to convert Mat& to vector by manually reading each point as described here. But the program crashes every time I access the received Mat& object with fatal signal 11,code 1.

I suspect the problem is due to difference in data structures used by C++ and Java API.

Any help will be appreciated, Thankyou!!!

In 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

In 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

... }

edit retag flag offensive close merge delete