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 ...
随机推荐
- Ioc容器Autofac系列(2)-- asp.net mvc中整合autofac
经过上篇蜻蜓点水的介绍后,本篇通过实例快速上手autofac,展示当asp.net mvc引入了autofac之后会带来什么. 创建Asp.net MVC并引入Autofac 首先,创建一个MVC站点 ...
- EcTouch二次开发
一.EcTouch简介 1.1. 什么是ECTOUCH ECTouch是上海商创网络科技有限公司推出的一款开源免费移动商城网店系统,可以在手机上面卖商品的电子商务软件系统.能够帮助企业和个人快速构建手 ...
- HTML5画布Canvas
一.Canvas概念介绍 1.概念 Canvas : 画布 2.作用 : HTML5 Canvas 元素用于图形的绘制, 通过脚本(通常是JavaScript)来完成.它本身只是个图形容器,必须使用脚 ...
- nginx缓存优先级(缓存问题者必看)
接触nginx的兄弟或多或少都有遇到缓存问题,要么是nginx为什么不缓存,要么就是nginx缓存很快就失效等等问题,在网上找了一遍nginx缓存优先级的文章,大家可以参考下. 架构图client端 ...
- 玩转Bash脚本:test測试语句
总第1篇test就是測试的意思,经常使用在流程控制语句中作为条件.以下做一下介绍. 关于真值 与其它语言不同,Bash(包含其它Shell)中,是用0表示真,非0表示假的.之所以用0表示成功,而不是1 ...
- ANE在ios上的使用流程和问题解决
编写ANE流程: 1. 在xcode里编写.a原生类库 2. 更改配置文件extension.xml, 定义了原生程序的扩展接口 3. 编写AS替身类,生成扩展类包.swc,解压再得到library. ...
- Seconds_Behind_Master
http://blog.chinaunix.net/uid-28212952-id-3494560.html 今天同事遇到一个故障,xtrabackup备份中flush tables with rea ...
- MHA手动切换 原创4 (非交互式切换)
非交互式切换:不输 YES 或者 NO [root@monitor app1]# masterha_master_switch --conf=/etc/masterha/app1.conf --mas ...
- 解决Server Error in '/' Application.方法!
<!-- Web.Config Configuration File --> <configuration> <system.web> ...
- 网络IPC:套接字之寻址
在学习用套接字做一些有意义的事情之前,需要知道如何确定一个目标通信进程. 进程的标识有两个部分:计算机的网络地址可以帮助标识网络上想与之通信的计算机,而服务可以帮助标识计算机上特定的进程. 1.字节序 ...