您的位置:首页 > 编程语言 > Java开发

javacv开发环境配置–一切原来可以这么简单

2011-05-03 09:46 585 查看
2013.5.31日根据Google Code上的变化重新编辑,提供Demo下载:http://download.csdn.net/detail/viviwen123/5489117

本文介绍eclipse下配置javacv的开发环境,过程十分简单,最后会举一个实例(FacePreview)进行验证配置是否成功。阅读本文的前提是android+eclipse开发环境已经配置好(当然javacv并不是专为android而写的,普通java程序也是支持的)。

一、打开网页:http://code.google.com/p/javacv/。点击:Downloads,下载javacv-0.5-bin.zip及javacv-0.5-cppjars.zip,解压到任意目录。

二、点击Project Home,回到原来的页面,看到下面这段话:

Eclipse (Android 2.2 or newer):

Follow the instructions on this page: http://developer.android.com/training/basics/firstapp/
Go to File > New > Folder, select your project as parent folder, type "libs/armeabi" as Folder name, and click Finish.
Copy javacpp.jar and javacv.jar into
the newly created "libs" folder.
Extract all the *.so files from javacv-android-arm.jar, opencv-2.4.5-android-arm.jar,
and ffmpeg-1.2-android-arm.jar directly into the newly created "libs/armeabi" folder, without creating any of the subdirectories
found in the JAR files.
Navigate to Project > Properties > Java Build Path > Libraries and click "Add JARs...".
Select both javacpp.jar and javacv.jar from
the newly created "libs" folder.

三、按照二的步骤做,里面的第一步可以不理。第二、第三步很简单,第四步是把三个jar包里的.so文件提取出来,放到“libs/armeabi”目录下,提取方法:把jar重命名为rar,打开即可看到一堆.so文件。现在很多压缩软件可以打开jar包里面的文件,打开后直接拖过去即可。第五、第六步也很简单,照做即可。

下面举一个实例:FacePreview。要注意的是javacv的运行要求Android 2.2 on ARMv7 or newer versions,有些机子可能会运行不了。

一、eclipse新建一个工程,工程名:FacePreview,包名:com.googlecode.javacv.facepreview。把javacv-bin/samples下的FacePreview.java复制到当前工程下替换原来的FacePreview.java。注意到FacePreview.java里第25行的注释里提到:“IMPORTANT – Make sure your AndroidManifiest.xml file includes the following”,要把拍照的权限加到AndroidManifiest.xml里。

二、第110行处:File classifierFile = Loader.extractResource(getClass(),

“/com/googlecode/javacv/facepreview/haarcascade_frontalface_alt.xml”,

context.getCacheDir(), “classifier”, “.xml”);用到了haarcascade_frontalface_alt.xml,如果找不到这个文件就网上下一个,然后把haarcascade_frontalface_alt.xml放到指定位置。

三、把上文中提到的jar包及.so文件加入进去。

四、运行程序,大功告成。

After that, the wrapper classes for OpenCV and FFmpeg can automatically access all of their C/C++ APIs。很赞吧~
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: