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 ...
随机推荐
- 位运算&字节运算
- 2015南阳CCPC F - The Battle of Guandu 多源多汇最短路
The Battle of Guandu Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 无 Description In the year of 200, t ...
- Windbg命令
(1)!runaway命令显示每个线程消费的时间 参考:http://blog.csdn.net/hgy413/article/details/7564252 (2)!wow64exts.sw 关闭6 ...
- 转自邓凡平 《深入理解Android:Wi-Fi,NFC和GPS》章节连载[节选]--第七章 深入理解Wi-Fi P2P部分节选
本章主要内容: 介绍Wi-Fi P2P相关知识: 介绍Android中WifiP2pService.wpa_supplicant的相关代码. 7.1 概述 承接第6章介绍的WSC,本章将继续介绍Wi ...
- Spring MVC Junit4 单元測试 JunitTest
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvSmVyb21lX3M=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA ...
- Java中Queue类实现
原先在java编程中,Queue的实现都是用LinkedList Queue queue = new LinkedList(); 但正如jdk中所说的那样: 注意,此实现不是同步的.如果多个线程同时访 ...
- python selenium自动化(二)自动化注册流程
需求:使用python selenium来自动测试一个网站注册的流程. 假设这个网站的注册流程分为三步,需要提供比较多的信息: 在这个流程里面,需要用户填入信息.在下拉菜单中选择.选择单选的radio ...
- Linux下的简单好用的计算器bc
1. 关于bc bc是随意精度计算器语言,通常在linux下当计算器用,简单好用.相当于windows下的计算器. 2. 支持的运算符 主要的数学运算: + 加法 - 减法 * 乘法 / 除法 ^ 指 ...
- WEB服务器、应用程序服务器、HTTP服务器区别(转)
WEB服务器.应用程序服务器.HTTP服务器有何区别?IIS.Apache.Tomcat.Weblogic.WebSphere都各属于哪种服务器,这些问题困惑了很久,今天终于梳理清楚了: Web服务器 ...
- iframe自适应高度的多种方法方法小结
对于自适应高度的代码有很多,可效率什么的考虑进来好代码就不多见了,不过思路倒是差不多的 不带边框的iframe因为能和网页无缝的结合从而不刷新页面的情况下更新页面的部分数据成为可能,可是 ifram ...