您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 管理学资料 > 基于Android的远程视频监控系统
基于android的远程视频监控系统(已开放源码)基本过程是android作为socket客户端将采集到的每一帧图像数据发送出去,PC作为服务器接收并显示每一帧图像实现远程监控。图片如下(后来PC端加了个拍照功能)。。。(PS。刚学android和java不久很多东西还不懂,高手若是知道哪些地方可以继续优化的话还请多多指点下啊)系统代码如下:一、android手机客户端(1)AndroidManifest.xml文件。添加camera和socket权限,并设置了程序开始执行的activity、?xmlversion=1.0encoding=utf-8?manifestxmlns:android==org.wanghai.CameraTestandroid:versionCode=1android:versionName=1.0uses-sdkandroid:minSdkVersion=15/!--授予程序使用摄像头的权限--uses-permissionandroid:name=android.permission.CAMERA/uses-featureandroid:name=android.hardware.camera/uses-featureandroid:name=android.hardware.camera.autofocus/uses-permissionandroid:name=android.permission.INTERNET/uses-permissionandroid:name=android.permission.KILL_BACKGROUND_PROCESSES/uses-permissionandroid:name=android.permission.RESTART_PACKAGES/applicationandroid:icon=@drawable/ic_launcherandroid:label=@string/app_nameactivityandroid:name=.GetIPandroid:screenOrientation=landscapeandroid:label=@string/app_nameintent-filteractionandroid:name=android.intent.action.MAIN/categoryandroid:name=android.intent.category.LAUNCHER//intent-filter/activityactivityandroid:name=.CameraTestandroid:screenOrientation=landscapeandroid:label=@string/app_name/activity/application/manifest(2)main.xml设置surfaceview用于摄像头采集图像的预览?xmlversion=1.0encoding=utf-8?LinearLayoutxmlns:android=:layout_width=fill_parentandroid:layout_height=fill_parentandroid:orientation=verticalSurfaceViewandroid:id=@+id/sViewandroid:layout_width=fill_parentandroid:layout_height=fill_parentandroid:scaleType=fitCenter//LinearLayout(3)login.xml登录界面,用于输入服务器IP?xmlversion=1.0encoding=utf-8?TableLayoutxmlns:android=:id=@+id/loginFormandroid:orientation=verticalandroid:layout_width=fill_parentandroid:layout_height=fill_parentTableRowTextViewandroid:layout_width=fill_parentandroid:layout_height=wrap_contentandroid:text=IP:android:textSize=10pt/!--输入用户名的文本框--EditTextandroid:id=@+id/ipedittextandroid:layout_width=fill_parentandroid:layout_height=wrap_contentandroid:digits=0123456789.android:hint=请填写服务器IPandroid:selectAllOnFocus=true//TableRow/TableLayout(4)GetIP.java获得服务器IP后,通过Intent启动CameraTest的activity,ip信息通过Bundle传递publicclassGetIPextendsActivity{Stringipname=null;@OverridepublicvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);//设置全屏requestWindowFeature(Window.FEATURE_NO_TITLE);getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);setContentView(R.layout.main);finalBuilderbuilder=newAlertDialog.Builder(this);//定义一个AlertDialog.Builder对象builder.setTitle(登录服务器对话框);//设置对话框的标题//装载/res/layout/login.xml界面布局TableLayoutloginForm=(TableLayout)getLayoutInflater().inflate(R.layout.login,null);finalEditTextiptext=(EditText)loginForm.findViewById(R.id.ipedittext);builder.setView(loginForm);//设置对话框显示的View对象//为对话框设置一个“登录”按钮builder.setPositiveButton(登录//为按钮设置监听器,newOnClickListener(){@OverridepublicvoidonClick(DialogInterfacedialog,intwhich){//此处可执行登录处理ipname=iptext.getText().toString().trim();Bundledata=newBundle();data.putString(ipname,ipname);Intentintent=newIntent(GetIP.this,CameraTest.class);intent.putExtras(data);startActivity(intent);}});//为对话框设置一个“取消”按钮builder.setNegativeButton(取消,newOnClickListener(){@OverridepublicvoidonClick(DialogInterfacedialog,intwhich){//取消登录,不做任何事情。System.exit(1);}});//创建、并显示对话框builder.create().show();}}(5)CameraTest.java程序主体。设置PreviewCallback后,每当一帧图像数据采集完成后将调用PreviewCallback的onPreviewFrame函数。在这里我们将YUV格式数据转为jpg,再启用线程将数据通过socket发送出去。publicclassCameraTestextendsActivity{SurfaceViewsView;SurfaceHoldersurfaceHolder;intscreenWidth,screenHeight;Cameracamera;//定义系统所用的照相机booleanisPreview=false;//是否在浏览中privateStringipname;@SuppressWarnings(deprecation)@OverridepublicvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);//设置全屏requestWindowFeature(Window.FEATURE_NO_TITLE);getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);setContentView(R.layout.main);//获取IP地址Intentintent=getIntent();Bundledata=intent.getExtras();ipname=data.getString(ipname);screenWidth=640;screenHeight=480;sView=(SurfaceView)findViewById(R.id.sView);//获取界面中SurfaceView组件surfaceHolder=sView.getHolder();//获得SurfaceView的SurfaceHolder//为surfaceHolder添加一个回调监听器surfaceHolder.addCallback(newCallback(){@OverridepublicvoidsurfaceChanged(SurfaceHolderholder,intformat,intwidth,intheight){}@OverridepublicvoidsurfaceCreated(SurfaceHolderholder){initCamera();//打开摄像头}@OverridepublicvoidsurfaceDestroyed(SurfaceHolderholder){//如果camera不为null,释放摄像头if(camera!=null){if(isPreview)camera.stopPreview();camera.release();camera=null;}System.exit(0);}});//设置该SurfaceView自己不维护缓冲surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);}privatevoidinitCamera(){if(!isPreview){camera=Camera.open();}if(camera!=null&&!isPreview){try{Camera.Param
本文标题:基于Android的远程视频监控系统
链接地址:https://www.777doc.com/doc-2568119 .html