问题描述
我现在用的是JavaCV库为Android pre-建OpenCV的库。我想我已经安装Eclipse的正确的方式,因为我已经包括罐子都javacv.jar和javacpp.jar。此外,Java的CV-Android的arm.jar,在我的项目。一切编译罚款,没有错误,警告,任何应该是可疑的东西,就会出问题在运行时。但是我得到的是下面这个方法体抛出NoClassDefFoundError的异常:
I am using the JavaCV library with pre-built OpenCV libraries for Android. I think I have setup Eclipse the right way, because I have included the jars both javacv.jar and javacpp.jar. In addition, the java-cv-android-arm.jar, in my project. Everything compiles fine, no errors, warning, anything that should be suspicious of something that will go wrong at runtime. But I get NoClassDefFOundError exception that is thrown in this method body below:
@Override
public void draw(Canvas canvas)
{
try
{
canvas.drawColor(Color.BLUE);
if (current != null)
{
int width = current.getWidth();
int height = current.getHeight();
IplImage i = IplImage.create(width, height, IPL_DEPTH_8U, 1); // I assume here is where the exception gets thrown
ByteBuffer buffer = i.getByteBuffer();
current.copyPixelsToBuffer(buffer);
// We need a grayscale image in order to do the recognition, so
// we
// create a new image of the same size as the original one.
IplImage grayImage = IplImage.create(i.width(), i.height(),
IPL_DEPTH_8U, 1);
// We convert the original image to grayscale.
cvCvtColor(i, grayImage, CV_BGR2GRAY);
CvMemStorage storage = CvMemStorage.create();
// We instantiate a classifier cascade to be used for detection,
// using the cascade definition.
CvHaarClassifierCascade cascade = new CvHaarClassifierCascade(
cvLoad("haarcascade_frontalface_alt.xml"));
// We detect the faces.
CvSeq faces = cvHaarDetectObjects(grayImage, cascade, storage,
1.1, 1, 0);
// We iterate over the discovered faces and draw yellow
// rectangles around them.
for (int index = 0; index < faces.total(); index++)
{
CvRect r = new CvRect(cvGetSeqElem(faces, index));
cvRectangle(i, cvPoint(r.x(), r.y()),
cvPoint(r.x() + r.width(), r.y() + r.height()),
opencv_core.CvScalar.YELLOW, 1, CV_AA, 0);
}
Bitmap b = BitmapFactory.decodeByteArray(i.getByteBuffer()
.array(), 0, i.getByteBuffer().array().length);
canvas.drawBitmap(b, x, y, paint);
canvas.drawText(new Date().toLocaleString(), canvas.getWidth() - 100,
canvas.getHeight() - 50, paint);
paint.setColor(Color.GREEN);
}
} catch (Exception e)
{
canvas.drawColor(Color.RED);
canvas.drawText(
"Handled exception occurred in panel:\n" + e.getMessage(),
250, 250, paint);
paint.setColor(Color.GREEN);
}
super.draw(canvas);
}
抛出异常
当然,之后,我的Android崩溃了,我强行关闭应用程序。难道我有罐子,以及需要的库是否正确?有什么,我应该知道的?任何帮助将大大AP preciated。
And of course, right after the exception is thrown, my Android crashes, and I force close the application. Did I include the jars, and required libraries correctly? Is there anything that I should be aware of? Any help would be greatly appreciated.
下面是为那些谁喜欢猫的LogCat中(插入表情符号,在这里的):
Here is the LogCat for those who love Cats (insert emoticon here):
05-03 19:07:53.217: E/AndroidRuntime(741): FATAL EXCEPTION: main
05-03 19:07:53.217: E/AndroidRuntime(741): java.lang.NoClassDefFoundError: com.googlecode.javacv.cpp.opencv_core$IplImage
05-03 19:07:53.217: E/AndroidRuntime(741): at home.security.DrawingPanel.draw(DrawingPanel.java:81)
05-03 19:07:53.217: E/AndroidRuntime(741): at home.security.Main$2.run(Main.java:105)
05-03 19:07:53.217: E/AndroidRuntime(741): at android.os.Handler.handleCallback(Handler.java:587)
05-03 19:07:53.217: E/AndroidRuntime(741): at android.os.Handler.dispatchMessage(Handler.java:92)
05-03 19:07:53.217: E/AndroidRuntime(741): at android.os.Looper.loop(Looper.java:123)
05-03 19:07:53.217: E/AndroidRuntime(741): at android.app.ActivityThread.main(ActivityThread.java:3683)
05-03 19:07:53.217: E/AndroidRuntime(741): at java.lang.reflect.Method.invokeNative(Native Method)
05-03 19:07:53.217: E/AndroidRuntime(741): at java.lang.reflect.Method.invoke(Method.java:507)
05-03 19:07:53.217: E/AndroidRuntime(741): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
05-03 19:07:53.217: E/AndroidRuntime(741): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
05-03 19:07:53.217: E/AndroidRuntime(741): at dalvik.system.NativeStart.main(Native Method)
文件夹结构林达文件夹
推荐答案
该罐必须在项目的根/库文件夹或将其标记为在项目的构建路径出口...
The jars need to be in the project-root/libs folder or to mark them as exported in the build path of the project...
现在它应该工作...
now it should work...
这篇关于Android的JavaCV困境,NoClassDefFoundError的方法内抛出'画'创建的IplImage时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!