OpenCV的和JavaCv在Android上 - 检测到图像形状 [英] OpenCV and JavaCv on Android - detect shape on image

查看:1140
本文介绍了OpenCV的和JavaCv在Android上 - 检测到图像形状的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的OpenCV和JavaCV开始,我​​尝试来检测我的形象的形状。我要检测圈。我有一个形象作为位图(只有这样)。我已阅读,首先我需要把我的图片作为IplImage结构,然后将其转换为灰度和平滑的边缘。好了,我开始做这样的事情:首先,因为我的形象是位图我创建的IplImage的对象(我应该提到这一切都是$ P $后pssing按钮happing):

I'm starting using openCV and JavaCV and I try to detect shapes on my Image. I want to detect circles. I have an Image as a bitmap (and only like this). I have read that first I need to take my Image as IplImage, then convert it to grayscale and smooth the edges. Ok, so I started doing something like this: because first my image is as the bitmap i creating an object of IplImage (I should mention that everything is happing after pressing the button):

IplImage image = new IplImage();

然后我我的位图转换为IplImage的:

Then I'm converting my bitmap to IplImage:

bitmap.copyPixelsToBuffer(image.getByteBuffer());

,我应该知道另作想,但我不能,因为$ P $后pssing按钮的应用程序在第一行崩溃:的IplImage图像=新的IplImage();
我试图用其他的构造,如:的IplImage图像=新的IplImage(大小); ,但它也没有工作。如果有些能帮助我,我应该怎么做,(我的意思是创建的IplImage和位图转换为IplImage结构),我将非常感激。

And i should know make other thinks, but I can't, because after pressing the button application is crashing on the first line : IplImage image = new IplImage(); I tried to use other constructors like: IplImage image = new IplImage(size);but it also didn't work. If some can help me how should I do that (I mean create the IplImage and convert a bitmap to IplImage), I will be very grateful.

---编辑----
我再次尝试。现在我不添加使用项目 - >属性 - > Java的内置路径罐子 - > ...但我设置里面的罐子的lib文件夹中。但还是一切都崩溃时,我特林创建的IplImage类的对象。有谁知道为什么吗?

---EDIT---- I tried again. And now I'm not adding jar using Project->properties->Java Built Path->... But I'm setting jars inside 'lib' folder. But still everything is crashing when I'm tring to create object of IplImage class. Does anybody know why?

- EDIT--
在我的lib文件夹中我有:Android的支持 - v4.jar,javacpp.jar,javacv.jar,OpenCV库 - 2.4.3.jar。
我的活动类:

--EDIT-- In my lib folder i have: android-support-v4.jar, javacpp.jar, javacv.jar, opencv library - 2.4.3.jar. My Activity class:

import com.googlecode.javacv.cpp.opencv_core.IplImage;

import android.app.Activity;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.Menu;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        IplImage image = new IplImage();

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

}
而当我开始我的活动它的崩溃和日志:

} And when I'm starting my activity it' crashing and the log:

02-09 12:18:59.207: E/AndroidRuntime(7652): Caused by: java.lang.UnsatisfiedLinkError: Library jniopencv_core not found
02-09 12:18:59.207: E/AndroidRuntime(7652):     at java.lang.Runtime.loadLibrary(Runtime.java:461)
02-09 12:18:59.207: E/AndroidRuntime(7652):     at java.lang.System.loadLibrary(System.java:557)
02-09 12:18:59.207: E/AndroidRuntime(7652):     at com.googlecode.javacpp.Loader.loadLibrary(Loader.java:448)
02-09 12:18:59.207: E/AndroidRuntime(7652):     at com.googlecode.javacpp.Loader.load(Loader.java:372)
02-09 12:18:59.207: E/AndroidRuntime(7652):     at com.googlecode.javacpp.Loader.load(Loader.java:319)
02-09 12:18:59.207: E/AndroidRuntime(7652):     at com.googlecode.javacv.cpp.opencv_core.<clinit>(opencv_core.java:136)
02-09 12:18:59.207: E/AndroidRuntime(7652):     ... 19 more

我可以提到,如果我试图定义 Imgproc IMG =新Imgproc(); 一切正常。也许我可以用Imgproc检测形状(圆形),有人可以推荐一个好教程?

I can mention that if I tried to define Imgproc img = new Imgproc();everything was ok. Maybe I can detect shape (circles) using Imgproc, can someone recommend a good tutorial?

推荐答案

您可以直接创建映像如下:

You can create the image directly as following:

IplImage image = IplImage.createFrom(bitmapBuffer);

或者

IplImage image = IplImage.create(width, height, IPL_DEPTH_8U, 4); // Change the parameter as you need
bitmap.copyPixelsToBuffer(image.getByteBuffer());

或者直接加载图像到 LplImage 对象

IplImage image = cvLoadImage("image.png");

修改

<一个href=\"http://stackoverflow.com/questions/10438017/android-javacv-dilemma-noclassdeffounderror-thrown-inside-of-method-draw-when\">See这个问题,它应该解决您的错误。

See this question, it should solve your error.

根据你的错误,你似乎没有包括本地库(例如libjniopencv_core.so)OpenCV的在你的libs文件夹中。

Based on your error, it seems that you did not include the native libraries (e.g. libjniopencv_core.so) of OpenCV in your libs folder.

请按照指示指导安装和使用该库妥善还有的README.txt 文件

Follow the instruction guide to install and use the library properly as well as the README.txt file

<一个href=\"http://stackoverflow.com/questions/14588391/how-to-install-javacv-on-android-and-use-framegrabber\">See这个问题

这篇关于OpenCV的和JavaCv在Android上 - 检测到图像形状的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆