开发者

Calling Generic OpenCV methods from Android with opencv-android

开发者 https://www.devze.com 2023-02-13 08:31 出处:网络
I installed the opencv-android plugin successfully and I can build and run the cvcamera sample application as well. I have the opencv project included in eclipse as a library project as well. However,

I installed the opencv-android plugin successfully and I can build and run the cvcamera sample application as well. I have the opencv project included in eclipse as a library project as well. However, I'm confused about how to execute arbitrary opencv methods from within my android application.

For instance, I have my application take a picture and save it. Then, I want to have opencv load that image so I can run some processing on it. As a first step, I'm trying to load that image into an opencv Mat. So, I created the following class based on the code I see in the cvcamera sample:

import com.opencv.jni.Mat;
public class ExtraOpencvJNI {
    static {
        try {
            System.loadLibrary("android-opencv");
        } catch (UnsatisfiedLinkError e) {
            throw e;
      开发者_JAVA技巧  }
    }
    public final static native Mat imread(String jarg1);

}

Then, within my android java code I try to execute:

Mat img = ExtraOpencvJNI.imread("<path_to_img>");

However, I get an UnsatisfiedLinkError: imread when I execute the above java code. I know I must be misunderstanding something fundamental about how the opencv-android library works, but I can't find anything else out there explaining how to call basic opencv functions using the android library. What steps am I overlooking?


You could try JavaCV instead, it does just that:

http://code.google.com/p/javacv/


You need to have a corresponding imread bit of code in the JNI files (.i). For example, in the cvcamera example, there is processor.i and some others. As far as i can remember, I haven't seen imread on there. You're supposed to use the given methods, which move the YUV images from androids camera into a pool for processing by code written in c++.


That should not be a problem. I can do imread in my app. My guess is that you forgot to

#include <opencv2/highgui/highgui.hpp>

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号