android opencv 人脸检测
转载自http://blog.csdn.net/jesse__zhong/article/details/24889709
.......省略包
public class Staticdetection2Activity extends Activity {
final private static String TAG = "StaticrecognitionActivity";
final private int PICTURE_CHOOSE = 1;
private ImageView imageView = null;
private Bitmap img = null;
private Button buttonDetect = null;
private TextView textView = null;
private EditText editText = null;
// OpenCV类库加载并初始化成功后的回调函数,在此我们不进行任何操作
private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
@Override
public void onManagerConnected(int status) {
switch (status) {
case LoaderCallbackInterface.SUCCESS: {
}
break;
default: {
super.onManagerConnected(status);
}
break;
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_staticdetection2);
Button button = (Button) this.findViewById(R.id.button1);
button.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
// get a picture form your phone
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
photoPickerIntent.setType("image/*");
startActivityForResult(photoPickerIntent, PICTURE_CHOOSE);
}
});
editText = (EditText) this.findViewById(R.id.editText1);
textView = (TextView) this.findViewById(R.id.textView1);
buttonDetect = (Button) this.findViewById(R.id.button2);
buttonDetect.setVisibility(View.INVISIBLE);
buttonDetect.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
textView.setText("Waiting ...");
// use the red paint
/*
* Paint paint = new Paint(); paint.setColor(Color.RED);
* paint.setStrokeWidth(Math.max(img.getWidth(),
* img.getHeight()) / 100f);
*
* // create a new canvas Bitmap bitmap =
* Bitmap.createBitmap(img.getWidth(), img.getHeight(),
* img.getConfig()); Canvas canvas = new Canvas(bitmap);
* canvas.drawBitmap(img, new Matrix(), null);
*
* float x, y, w, h;
*
* x = y = w = h = 100;
*
* // change percent value to the real size x = x / 100 *
* img.getWidth(); w = w / 100 * img.getWidth() * 0.7f; y = y /
* 100 * img.getHeight(); h = h / 100 * img.getHeight() * 0.7f;
*
* // draw the box to mark it out canvas.drawLine(x - w, y - h,
* x - w, y + h, paint); canvas.drawLine(x - w, y - h, x + w, y
* - h, paint); canvas.drawLine(x + w, y + h, x - w, y + h,
* paint); canvas.drawLine(x + w, y + h, x + w, y - h, paint);
*
* img = bitmap;
*/
String xmlfilePath = "/sdcard/FaceDetect/haarcascade_frontalface_alt2.xml";
CascadeClassifier faceDetector = new CascadeClassifier(
xmlfilePath);
// Bitmap bmptest = BitmapFactory.decodeResource(getResources(),
// R.drawable.lena);
Mat testMat = new Mat();
Utils.bitmapToMat(img, testMat);
// Detect faces in the image.
// MatOfRect is a special container class for Rect.
MatOfRect faceDetections = new MatOfRect();
faceDetector.detectMultiScale(testMat, faceDetections);
Log.i(String.format("Detected %s faces",
faceDetections.toArray().length), "");
int facenum = 0;
// Draw a bounding box around each face.
for (Rect rect : faceDetections.toArray()) {
Core.rectangle(
testMat,
new Point(rect.x, rect.y),
new Point(rect.x + rect.width, rect.y + rect.height),
new Scalar(255, 0, 0));
++facenum;
}
// Save the visualized detection.
// Bitmap bmpdone = Bitmap.createBitmap(bmptest.getWidth(),
// bmptest.getHeight(), Config.RGB_565);
Utils.matToBitmap(testMat, img);
imageView.setImageBitmap(img);
textView.setText("Facecount:" + facenum);
/*Staticdetection2Activity.this.runOnUiThread(new Runnable() {
public void run() {
// show the image
imageView.setImageBitmap(img);
// textView.setText("Finished, "+ count + " faces.");
textView.setText("Finished, " + " faces.");
// set edit text
// editText.setText(str);
}
});*/
}
});
imageView = (ImageView) this.findViewById(R.id.imageView1);
imageView.setImageBitmap(img);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.staticdetection2, menu);
return true;
}
@Override
protected void onActivityResult(int requestCode, int resultCode,
Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
// the image picker callback
if (requestCode == PICTURE_CHOOSE) {
if (intent != null) {
Cursor cursor = getContentResolver().query(intent.getData(),
null, null, null, null);
cursor.moveToFirst();
int idx = cursor.getColumnIndex(ImageColumns.DATA);
String fileSrc = cursor.getString(idx);
Options options = new Options();
options.inJustDecodeBounds = true;
img = BitmapFactory.decodeFile(fileSrc, options);
options.inSampleSize = Math.max(1, (int) Math.ceil(Math.max(
(double) options.outWidth / 1024f,
(double) options.outHeight / 1024f)));
options.inJustDecodeBounds = false;
img = BitmapFactory.decodeFile(fileSrc, options);
textView.setText("Clik Detect. ==>");
imageView.setImageBitmap(img);
buttonDetect.setVisibility(View.VISIBLE);
} else {
Log.d(TAG, "idButSelPic Photopicker canceled");
}
}
}
@Override
public void onResume() {
super.onResume();
// 通过OpenCV引擎服务加载并初始化OpenCV类库,所谓OpenCV引擎服务即是
// OpenCV_2.4.3.2_Manager_2.4_*.apk程序包,存在于OpenCV安装包的apk目录中
OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_3, this,
mLoaderCallback);
}
}
android opencv 人脸检测的更多相关文章
- Android+openCV人脸检测2(静态图片)
前几篇文章中有提到对openCV环境配置,这里再重新梳理导入和使用openCV进行简单的人脸检测(包括使用级联分类器) 一 首先导入openCVLibrary320 二 设置gradle的sdk版本号 ...
- keras系列︱人脸表情分类与识别:opencv人脸检测+Keras情绪分类(四)
引自:http://blog.csdn.net/sinat_26917383/article/details/72885715 人脸识别热门,表情识别更加.但是表情识别很难,因为人脸的微表情很多,本节 ...
- Android—基于OpenCV+Android实现人脸检测
导读 OpenCV 是一个开源的跨平台计算机视觉库, 采C++语言编写,实现了图像处理和计算机视觉方面的很多通用算法,同时也提供对Python,Java,Android等的支持,这里利用Android ...
- opencv人脸检测分类器训练小结
这两天在初学目标检测的算法及步骤,其中人脸检测作为最经典的算法,于是进行了重点研究.该算法最重要的是建立人脸检测分类器,因此我用了一天的时间来学习分类器的训练.这方面的资料很多,但是能按照一个资料运行 ...
- opencv人脸检测,旋转处理
年会签到,拍自己的大头照,有的人可能会拍成横向的,需要旋转,用人脸检测并修正它(图片). 1. 无脑检测步骤为: 1. opencv 读取图片,灰度转换 2. 使用CascadeClassifier( ...
- OpenCV人脸检测并把图片写成avi视频
读出某一个文件夹下“jpg”后缀的全部图片后,用的OpenCV自带的人脸检测检测图片中的人脸,调整图片的大小写成一个avi视频. 主要是要记录一下CvVideoWriter的用法和如何从文件夹中读取某 ...
- 人脸检测学习笔记(数据集-DLIB人脸检测原理-DLIB&OpenCV人脸检测方法及对比)
1.Easily Create High Quality Object Detectors with Deep Learning 2016/10/11 http://blog.dlib.net/201 ...
- OpenCV——人脸检测
OpenCV支持的目标检测的方法: 利用样本的Haar特征进行的分类器训练,得到的级联boosted分类器(Cascade Classification) 1.加载级联分类器 CascadeClass ...
- OpenCV: OpenCV人脸检测框可信度排序
参考文章:http://blog.csdn.net/hua_007/article/details/45368607 使用OpenCV进行人脸识别时,使用 casecade.detectMultiSc ...
随机推荐
- 浅析网站开发中的 meta 标签的作用
*:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: 0 !important; } /* ...
- ThinkPHP3.1.3的单字母函数汇总
A函数: 用于实例化Action 格式:[项目://][分组/]模块 /** * A函数用于实例化Action 格式:[项目://][分组/]模块 * @param string $name Acti ...
- HDU 4587 B - TWO NODES tarjan
B - TWO NODESTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view ...
- C# WinForm 上传图片,文件到服务器的方法Uploader.ashx
网上有很多方案,起初用时,因为对asp.net不太了解,觉得FTP实现不错,可是后来发现,如果机器在域控下,就会有问题. 一年过去了,asp.net也熟悉了,知道ajax没事应该用ashx,验证码也用 ...
- goldengate的HANDLECOLLISIONS参数
HANDLECOLLISIONS 是一个 replicat 进程参数,主要在 initial load 中使用. 在 replicat 进程中使用该参数时,即使目标数据库环境中存在数据完整性问题(如 ...
- [MODx] 3. Working with chunks, TV, Category
1. Add chunk: For example, replace the header by using chunk. Usage: [[$chunk_name]] Cut all the hea ...
- Centos 6.5使用Bumblebee关闭N卡,冷却你的电脑
夏天来了,笔记本装的Centos一直非常热.随着天气的变化,这个问题真的要攻克了.差了下原因可能是双显卡笔记本,N卡驱动不完好,导致风扇狂叫. 昨天安装了nvidia 的显卡驱动本以为时间安静了.但是 ...
- boost.asio源码剖析(一) ---- 前 言
* 前言 源码之前,了无秘密. ——侯捷 Boost库是一个可移植.提供源代码的C++库,作 ...
- Demo Swig
演示使用swig工具创建c语言的java接口,生成.so库和java接口文件. 在此之前先要安装swig,安装方法:sudo apt-get install swig 1.使用eclipse创建工程. ...
- Ruby on Rails Tutorial 第一章 之 搭建开发环境
云端开发环境,Cloud9(https://ide.c9.io/).这个开发环境预先安装好了Rails开发所需要的大多数软件,包括Ruby.RubyGems和Git,需要自己安装Rails. 1.安装 ...