问题
I'm new to both Android development and OpenCV. I downloaded the OpenCV library for Android from http://sourceforge.net/projects/opencvlibrary/files/opencv-android/ and set up a phone using the Virtual Device Manager. When I try to run "OpenCV Tutorial 0 - Android Camera" in Eclipse, the phone's screen says "Fatal error: can't open camera!" and I get these errors in the log:
08-07 15:02:57.322: E/Trace(708): error opening trace file: No such file or directory (2)
08-07 15:02:57.772: E/Sample::SurfaceView(708): Can't open camera!
I also tried running a simple project:
package com.example;
import org.opencv.core.Mat;
import org.opencv.highgui.Highgui;
public class Test{
public static void main(String[] args) {
Mat example = Highgui.imread("/image.jpg");
return;
}
}
which gives me the error
Exception in thread "main" java.lang.UnsatisfiedLinkError: org.opencv.highgui.Highgui.imread_1(Ljava/lang/String;)J
How can I fix these errors? On a side note, /image.jpg looks in the parent directory of the project, not the SD card on the Android virtual device, right?
Thanks so much.
回答1:
If you are developing on a device via usb, try going to the App Manager from the options menu (stack of lines), scrolling down to the OpenCV Manager (assuming you are on OpenCV 2.4.2 or higher) and Force Close it. Do the same with your Tutorial 0 app.
I have Tutorial 0 working on my ubuntu machine. However, when I tried to add some OpenCV classes into a pure android project, I got the UnsatisfiedLink error. After that, my Tutorial 0 stopped working for a while with the "camera not found" error you are getting. It seems that OpenCV Manager can get messed up, probably having a lock or something on some resources, and needs to restart. My suggestion fixed the Totorial 0 camera problem, but not the unsatisfiedLink for my pure android + openCV project.
回答2:
After a bunch of searching, I found this solution for the UnsatisfiedLinkError (which came up again after I thought it was fixed - see here):
"3. If your application project doesn’t have a JNI part, just copy the corresponding OpenCV native libs from /sdk/native/libs/ to your project directory to folder libs/."
So that means copy the \armeabi, \armeabi-v7a, and \x86 folders.
"4. The last step of enabling OpenCV in your application is Java initialization code before call to OpenCV API. It can be done, for example, in the static section of the Activity class:
static {
if (!OpenCVLoader.initDebug()) {
// Handle initialization error
}
}
This code snippet should go right after:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_load_image);
Now it works!
来源:https://stackoverflow.com/questions/11852642/android-for-opencv-error-opening-trace-file-unsatisfiedlinkerror