简体   繁体   中英

Building OpenCV app with JNI in Eclipse

I've got a problem when building android applications with OpenCV and JNI part in Eclipse.

The problem is than ndk-build runs normally for the project, but Eclipse shows errors (usually irrelevant to the code).

For example, I'm building one of the OpenCV4Android samples:

boris@boris-ubuntu:~/src/OpenCV-2.4.3-android-sdk/samples/tutorial-3-native$ ndk-build 
Install        : libnative_camera_r2.2.0.so => libs/armeabi-v7a/libnative_camera_r2.2.0.so
Install        : libnative_camera_r2.3.3.so => libs/armeabi-v7a/libnative_camera_r2.3.3.so
Install        : libnative_camera_r3.0.1.so => libs/armeabi-v7a/libnative_camera_r3.0.1.so
Install        : libnative_camera_r4.0.0.so => libs/armeabi-v7a/libnative_camera_r4.0.0.so
Install        : libnative_camera_r4.0.3.so => libs/armeabi-v7a/libnative_camera_r4.0.3.so
Install        : libnative_camera_r4.1.1.so => libs/armeabi-v7a/libnative_camera_r4.1.1.so
Install        : libnative_sample.so => libs/armeabi-v7a/libnative_sample.so
Install        : libopencv_java.so => libs/armeabi-v7a/libopencv_java.so

It runs normally, but Eclipse shows errors:

'size_t' is ambiguous '
Candidates are:
Field 'pt' could not be resolved
Field 'pt' could not be resolved
Field 'x' could not be resolved
Field 'y' could not be resolved
Invalid arguments '
Candidates are:
void detect(const cv::Mat &, ? &, const cv::Mat &)
void detect(const ? &, ? &, const ? &)
The type 'cv::FastFeatureDetector' must implement the inherited pure virtual method 'cv::FeatureDetector::detectImpl'

And other error like this one in other projects. And also, the Eclipse intellisense (or how is it called properly :) is not working on .cpp files.

I've tried to clean the projects, delete the obj and lib folders, but no effect.

My system is ubuntu 12.04, OpenCV version is 2.4.3.

Thanks for any help!

Had same problem with you on ubuntu 12.04, OpenCV version is 2.4.3. exactly on the same example and I am using the eclipse-android bundle.

Here's what I did:

Update the NDK plugin using google repo, It is already installed but it can be updated.

Then I changed size_t to int and added a temp variable instead of going straight as the example goes. Here's the code:

Mat* pMatGr=(Mat*)addrGray;
Mat* pMatRgb=(Mat*)addrRgba;
vector<KeyPoint> v;
FastFeatureDetector detector(50);
detector.detect(*pMatGr, v);
for( int i = 0; i < v.size(); i++ )
{
     KeyPoint tK = v[i];
    circle(*pMatRgb, Point(tK.pt.x, tK.pt.y ), 10, Scalar(255,0,0,255));
}

It really is a weird bug, my guess is that it has something to do with eclipse debug mechanism not working properly.

Yea very strange bug. Am on Ubuntu 12.04 and OpenCV 2.4.5.

I got the same bug on 'OpenCV Tutorial 2 - Mixed Processing'

Managed to fix it without reinstalling Eclipse or NDK. Just deleted the sample project, then imported it again. Works fine now.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM