package com.example.devin.myapplication;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PointF;
import android.media.FaceDetector;
import android.media.FaceDetector.Face;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.ActionBarActivity;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
public class MainActivity extends ActionBarActivity {
private ImageView imageview;
private TextView countertext;
String result = null;
String TAG = "HttpPort";
private int SCEEEN_WIDTH, SCEEEN_HIGHT;
byte[] buffer = new byte[1024*16];
private int TIME = 100;
private int numberOfFace = 5; //最大检测的人脸数
private FaceDetector myFaceDetect; //人脸识别类的实例
private FaceDetector.Face[] myFace; //存储多张人脸的数组变量
private BitmapFactory.Options BitmapFactoryinfo;
float myEyesDistance; //两眼之间的距离
int numberOfFaceDetected; //实际检测到的人脸数
private Bitmap image;
private Handler handler;
HttpThreadGet myHttpThreadGet;
// HttpThreadPost myHttpThreadPost;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
widgetSetup();
paramsSetup();
detectSetup();
//faceDetect(image);
// timerHandler.postDelayed(runnable, TIME); //每隔1s执行
/************************** msg接收 *************************/
handler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case HttpThreadPost.POST:
result = (String) msg.obj;
break;
case HttpThreadGet.GET:
result = (String) msg.obj;
break;
case HttpThreadGet.GETIMG:
buffer = (byte[])msg.obj;
try {
image = BitmapFactory.decodeByteArray(buffer, 0, buffer.length, BitmapFactoryinfo);
faceDetect(image);
} catch (Exception e) {
Log.e(TAG, e.toString());
}
doGet(); //再请求
break;
default:
break;
}
}
};
doGet();
}
/************************** face detect *************************/
private void faceDetect(Bitmap fBitmap) {
// myBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.baby, BitmapFactoryOptionsbfo);
int imageWidth = fBitmap.getWidth();
int imageHeight = fBitmap.getHeight();
myFace = new FaceDetector.Face[numberOfFace]; //分配人脸数组空间
myFaceDetect = new FaceDetector(imageWidth, imageHeight, numberOfFace);
numberOfFaceDetected = myFaceDetect.findFaces(fBitmap, myFace); //FaceDetector 构造实例并解析人脸
countertext.setText("numberOfFaceDetected is " + numberOfFaceDetected);
Log.i(TAG,"numberOfFaceDetected is " + numberOfFaceDetected);
Bitmap bitmapTemp = Bitmap.createBitmap(fBitmap.getWidth(), fBitmap.getHeight(), Bitmap.Config.RGB_565);
Canvas canvas = new Canvas(bitmapTemp);
canvas.drawColor(Color.TRANSPARENT);
Paint myPaint = new Paint();
myPaint.setColor(Color.GREEN);
myPaint.setStyle(Paint.Style.STROKE);
myPaint.setStrokeWidth(3); //设置位图上paint操作的参数
canvas.drawBitmap(fBitmap, 0, 0, myPaint);
for(int i=0; i < numberOfFaceDetected; i++){
Face face = myFace[i];
PointF myMidPoint = new PointF();
face.getMidPoint(myMidPoint);
myEyesDistance = face.eyesDistance(); //得到人脸中心点和眼间距离参数,并对每个人脸进行画框
canvas.drawRect( //矩形框的位置参数
(int)(myMidPoint.x - myEyesDistance),
(int)(myMidPoint.y - myEyesDistance),
(int)(myMidPoint.x + myEyesDistance),
(int)(myMidPoint.y + myEyesDistance),
myPaint);
}
imageview.setImageBitmap(bitmapTemp);
}
/************************** register widget *************************/
private void widgetSetup() {
imageview = (ImageView) findViewById(R.id.imageView);
countertext = (TextView) findViewById(R.id.textView);
}
/************************** get HW & set widget size *************************/
private void paramsSetup() {
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
SCEEEN_WIDTH = dm.widthPixels;
SCEEEN_HIGHT = dm.heightPixels;
ViewGroup.LayoutParams para;
para = imageview.getLayoutParams();
para.width = (int)(SCEEEN_WIDTH * 0.96);
para.height = (int)(SCEEEN_WIDTH * 0.75 * 0.96);
imageview.setLayoutParams(para);
}
/************************** format bitmap *************************/
private void detectSetup() {
BitmapFactoryinfo = new BitmapFactory.Options();
BitmapFactoryinfo.inPreferredConfig = Bitmap.Config.RGB_565; //构造位图生成的参数,必须为565。类名+enum
}
private void doPost() {
//TODO
}
private void doGet() {
//get http img
String url = "http://192.168.0.105:8080/?action=snapshot";
// Log.d(TAG, url);
myHttpThreadGet = new HttpThreadGet(url, HttpThreadGet.GETIMG, handler);
myHttpThreadGet.start();
}
// /************************** 定时器发送 *************************/
//
// Handler timerHandler = new Handler();
// Runnable runnable = new Runnable() {
//
// @Override
// public void run() {
// // handler自带方法实现定时器
// try {
// handler.postDelayed(this, TIME);
// } catch (Exception e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// }
// };
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
protected void onDestroy() {
super.onDestroy();
if(myHttpThreadGet.isAlive()) {
myHttpThreadGet.interrupt();
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
mjpegstream android客户端
共49个文件
xml:21个
bin:5个
java:5个
2星 需积分: 35 47 下载量 13 浏览量
2017-10-30
13:40:37
上传
评论
收藏 282KB ZIP 举报
温馨提示
MJPG-streamer takes JPGs from Linux-UVC compatible webcams, filesystem or other input plugins and streams them as M-JPEG via HTTP to webbrowsers, VLC and other software. It is the successor of uvc-streamer, a Linux-UVC streaming application with Pan/Tilt
资源推荐
资源详情
资源评论
收起资源包目录
mjpegstream_android.zip (49个子文件)
WebViewTest
gradlew 5KB
src
androidTest
java
com
example
devin
myapplication
ApplicationTest.java 362B
main
AndroidManifest.xml 766B
res
drawable-hdpi
ic_launcher.png 9KB
menu
menu_main.xml 361B
drawable
drawable-mdpi
ic_launcher.png 5KB
layout
activity_main.xml 1KB
drawable-xxhdpi
ic_launcher.png 19KB
drawable-xhdpi
ic_launcher.png 14KB
values-w820dp
dimens.xml 358B
values
HttpRunner.xml 62B
strings.xml 224B
styles.xml 194B
dimens.xml 211B
java
com
example
devin
myapplication
MainActivity.java 7KB
HttpRunner.java 7KB
HttpThreadPost.java 1KB
HttpThreadGet.java 1KB
.idea
libraries
appcompat_v7_21_0_3.xml 406B
support_v4_21_0_3.xml 708B
support_annotations_21_0_3.xml 501B
runConfigurations.xml 564B
misc.xml 2KB
compiler.xml 711B
workspace.xml 105KB
gradle.xml 577B
.name 11B
encodings.xml 166B
WebViewTest.iml 338B
modules.xml 262B
scopes
scope_settings.xml 139B
copyright
profiles_settings.xml 74B
vcs.xml 166B
build
gradle
wrapper
gradle-wrapper.properties 236B
gradle-wrapper.jar 52KB
.gradle
3.3
tasks
_compileDebugJavaWithJavac
localJarClasspathSnapshot
localJarClasspathSnapshot.bin 19KB
localJarClasspathSnapshot.lock 17B
localClassSetAnalysis
localClassSetAnalysis.bin 25KB
localClassSetAnalysis.lock 17B
taskArtifacts
fileHashes.bin 208KB
taskArtifacts.bin 56KB
fileSnapshots.bin 396KB
taskArtifacts.lock 17B
local.properties 504B
libs
WebViewTest.iml 9KB
gradlew.bat 2KB
.gitignore 7B
build.gradle 809B
proguard-rules.pro 675B
共 49 条
- 1
资源评论
- wuxianxiaxiang2019-04-18没用上,也许能用吧
大囚长
- 粉丝: 1117
- 资源: 48
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于CSS与JavaScript的积分系统设计源码
- 生物化学作业_1_生物化学作业资料.pdf
- 基于libgdx引擎的Java开发连连看游戏设计源码
- 基于MobileNetV3的SSD目标检测算法PyTorch实现设计源码
- 基于Java JDK的全面框架设计源码学习项目
- 基于Python黑魔法原理的Python编程技巧设计源码
- 基于Python的EducationCRM管理系统前端设计源码
- 基于Django4.0+Python3.10的在线学习系统Scss设计源码
- 基于activiti6和jeesite4的dreamFlow工作流管理设计源码
- 基于Python实现的简单植物大战僵尸脚本设计源码
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功