| | |
| | | package cn.com.basic.face.fragment; |
| | | |
| | | import android.graphics.ImageFormat; |
| | | import android.media.ImageReader; |
| | | import android.content.Context; |
| | | import android.graphics.Bitmap; |
| | | import android.graphics.BitmapFactory; |
| | | import android.graphics.Canvas; |
| | | import android.net.Uri; |
| | | import android.net.wifi.WifiManager; |
| | | import android.os.Build; |
| | | import android.os.Bundle; |
| | | import android.text.format.Formatter; |
| | | import android.view.SurfaceHolder; |
| | | import android.view.SurfaceView; |
| | | import android.view.View; |
| | | import android.widget.LinearLayout; |
| | | import android.widget.RadioButton; |
| | | import android.widget.RadioGroup; |
| | | import android.widget.RelativeLayout; |
| | | import android.widget.TextView; |
| | | |
| | | import com.bsk.zhangbo.demoforbsk.R; |
| | | |
| | | import cn.com.basic.face.base.BaseApplication; |
| | | import cn.com.basic.face.base.BaseFragment; |
| | | |
| | | import cn.com.basic.face.base.MainActivity; |
| | | import cn.com.basic.face.service.DeviceMng; |
| | | import cn.com.basic.face.discern.common.CommonVariables; |
| | | import cn.com.basic.face.discern.query.item.SurveillanceQueryItem; |
| | | import cn.com.basic.face.thread.StartCameraThread; |
| | | import cn.com.basic.face.util.FileUtil; |
| | | import cn.com.basic.face.util.MjpegInputStream; |
| | | import cn.com.basic.face.util.MjpegView; |
| | | import cn.com.basic.face.util.NativeImg; |
| | | import cn.com.basic.face.util.RtspFaceNative; |
| | | |
| | | import cn.com.basic.face.service.SurveillanceMng; |
| | | import cn.com.basic.face.thread.SurveillancePhotoEmulateThread; |
| | | import cn.com.basic.face.widget.surveilance.SurveillanceBottomAttendanceListView; |
| | | import cn.com.basic.face.widget.surveilance.SurveillanceBottomVisitorListView; |
| | | |
| | | import com.lidroid.xutils.view.annotation.ViewInject; |
| | | import com.lidroid.xutils.view.annotation.event.OnClick; |
| | | import com.luxand.FSDK; |
| | | |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Date; |
| | | import java.io.File; |
| | | import java.net.InetAddress; |
| | | import java.net.NetworkInterface; |
| | | import java.net.SocketException; |
| | | import java.util.*; |
| | | |
| | | public class SurveillanceFragment extends BaseFragment { |
| | | |
| | |
| | | @ViewInject(R.id.fragment_supervisory_bottom_attendance_list_view) |
| | | private SurveillanceBottomAttendanceListView fragment_supervisory_bottom_attendance_list_view; |
| | | @ViewInject(R.id.fragment_supervisory_enter_camera) |
| | | SurfaceView fragment_supervisory_enter_camera; |
| | | private SurfaceView fragment_supervisory_enter_camera; |
| | | @ViewInject(R.id.fragment_supervisory_exit_camera) |
| | | SurfaceView fragment_supervisory_exit_camera; |
| | | private SurfaceView fragment_supervisory_exit_camera; |
| | | @ViewInject(R.id.fragment_surveillance_enter_timer) |
| | | private TextView fragment_surveillance_enter_timer; |
| | | @ViewInject(R.id.fragment_surveillance_exit_timer) |
| | | private TextView fragment_surveillance_exit_timer; |
| | | @ViewInject(R.id.fragment_supervisory_exit_camera_relative_layout) |
| | | private RelativeLayout fragment_supervisory_exit_camera_relative_layout; |
| | | @ViewInject(R.id.fragment_supervisory_enter_camera_relative_layout) |
| | | private RelativeLayout fragment_supervisory_enter_camera_relative_layout; |
| | | @ViewInject(R.id.fragment_surveillance_bottom_linear_layout) |
| | | private LinearLayout fragment_surveillance_bottom_linear_layout; |
| | | @ViewInject(R.id.myVideoView) |
| | | private MjpegView myVideoView; |
| | | |
| | | StartCameraThread startEnterCameraThread = null; |
| | | StartCameraThread startExitCameraThread = null; |
| | | |
| | | static boolean useNative = false; |
| | | |
| | |
| | | } else { |
| | | useNative = true; |
| | | } |
| | | if (CommonVariables.FACE_SERVER) { |
| | | useNative = false; |
| | | } |
| | | //useNative = false; |
| | | if (CommonVariables.EMULATOR) { |
| | | useNative = false; |
| | | } |
| | | if (useNative) { |
| | | try{ |
| | | |
| | | // Process su = Runtime.getRuntime().exec("su"); |
| | | // Calendar c = Calendar.getInstance(); |
| | | // c.set(2017, 4, 1, 12, 34, 56); |
| | | // AlarmManager am = (AlarmManager) MainActivity.getInstance().getSystemService(Context.ALARM_SERVICE); |
| | | // |
| | | //// am.setTime(c.getTimeInMillis()); |
| | | // |
| | | // DataOutputStream outputStream = new DataOutputStream(su.getOutputStream()); |
| | | // |
| | | //// outputStream.writeBytes("su 0 toolbox date -s 20170501.235959"); |
| | | // |
| | | // outputStream.writeBytes("/system/mac.sh"); |
| | | // outputStream.flush(); |
| | | // //Thread.sleep(5000); |
| | | //// outputStream.writeBytes("busybox ifconfig wlan0 hw ether f4:8b:32:62:4f:89\n"); |
| | | //// outputStream.flush(); |
| | | // |
| | | // outputStream.writeBytes("exit\n"); |
| | | // outputStream.flush(); |
| | | // su.waitFor(); |
| | | /* |
| | | busybox ifconfig wlan0 hw ether AC:83:F3:42:19:CE |
| | | */ |
| | | }catch(Exception e){ |
| | | e.printStackTrace(); |
| | | } |
| | | System.loadLibrary("cvface_api"); |
| | | System.loadLibrary("opencv_java3"); |
| | | System.loadLibrary("protobuf-lite"); |
| | |
| | | System.loadLibrary("protoc"); |
| | | System.loadLibrary("rtspface"); |
| | | RtspFaceNative.init(); |
| | | // RtspFaceNative.setLocalIP("192.168.1.10"); |
| | | RtspFaceNative.setLocalIP("192.168.1.106");//自己手机ip |
| | | // RtspFaceNative.setLocalIP("192.168.1.203"); |
| | | WifiManager wm = (WifiManager) MainActivity.getInstance().getSystemService(Context.WIFI_SERVICE); |
| | | String ip = Formatter.formatIpAddress(wm.getConnectionInfo().getIpAddress()); |
| | | String ipAddress = null; |
| | | try { |
| | | for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) { |
| | | NetworkInterface intf = en.nextElement(); |
| | | for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) { |
| | | InetAddress inetAddress = enumIpAddr.nextElement(); |
| | | if (!inetAddress.isLoopbackAddress()) { |
| | | String ip1 = inetAddress.getHostAddress().toString(); |
| | | if (ip1.contains("192.")) { |
| | | ipAddress = ip1; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } catch (SocketException ex) {} |
| | | |
| | | |
| | | // outputStream.writeBytes("busybox ifconfig wlan0 hw ether 00:e0:2c:31:1a:ba\n"); |
| | | /* |
| | | sysctl kernel.sched_is_big_little=1 |
| | | sysctl net.core.rmem_max=40000000 |
| | | */ |
| | | RtspFaceNative.setLocalIP(ipAddress); |
| | | System.out.println("ipaddr="+ipAddress); |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | @Override |
| | | protected void initViews(View view, Bundle savedInstanceState) { |
| | | new Thread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | try { |
| | | if (useNative) { |
| | | MainActivity.getInstance().runOnUiThread(new Runnable() { |
| | | public void run() { |
| | | RtspFaceNative.setSurface(1, fragment_supervisory_enter_camera.getHolder().getSurface()); |
| | | RtspFaceNative.setSurface(2, fragment_supervisory_exit_camera.getHolder().getSurface()); |
| | | RtspFaceNative.createPlayer(1, DeviceMng.getInstance().getCamera1Address()); |
| | | RtspFaceNative.createPlayer(2, DeviceMng.getInstance().getCamera2Address()); |
| | | RtspFaceNative.setFaceCallback(1, "cn/com/basic/face/util/RtspFaceNative", "faceCallBack"); |
| | | RtspFaceNative.setFaceCallback(2, "cn/com/basic/face/util/RtspFaceNative", "faceCallBack"); |
| | | } |
| | | }); |
| | | if (CommonVariables.FACE_SERVER) { |
| | | fragment_supervisory_enter_camera_relative_layout.addView(MainActivity.getInstance().mPreview); |
| | | fragment_supervisory_enter_camera_relative_layout.addView(MainActivity.getInstance().mDraw); |
| | | } |
| | | Uri vidUri = Uri.parse("http://192.168.1.13:8080/video"); |
| | | //myVideoView.setVideoURI(vidUri); |
| | | //myVideoView.setVideoPath("http://192.168.1.13:8080/video"); |
| | | //myVideoView.start(); |
| | | if (1!=1) { |
| | | new Thread() { |
| | | @Override |
| | | public void run() { |
| | | FSDK.HCamera cameraHandle = new FSDK.HCamera(); |
| | | boolean opened = false; |
| | | int res = FSDK.ActivateLibrary(""); |
| | | if (res == FSDK.FSDKE_OK) { |
| | | FSDK.Initialize(); |
| | | |
| | | } else { |
| | | FSDK.FSDK_VIDEOCOMPRESSIONTYPE type = new FSDK.FSDK_VIDEOCOMPRESSIONTYPE(); |
| | | type.type=FSDK.FSDK_VIDEOCOMPRESSIONTYPE.FSDK_MJPEG; |
| | | FSDK.OpenIPVideoCamera(type,"http://192.168.1.13:8080/video", |
| | | "username","password",500, cameraHandle); |
| | | opened = true; |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | try { |
| | | final SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss分"); |
| | | while (true) { |
| | | Thread.sleep(1000); |
| | | MainActivity.getInstance().runOnUiThread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | fragment_surveillance_enter_timer.setText(sdf.format(new Date())); |
| | | fragment_surveillance_exit_timer.setText(sdf.format(new Date())); |
| | | int tracId = 0; |
| | | while(true) { |
| | | try { |
| | | if (opened) { |
| | | FSDK.HImage imageHandle = new FSDK.HImage(); |
| | | int res1 = FSDK.GrabFrame(cameraHandle, imageHandle); |
| | | if (res1 == FSDK.FSDKE_OK) {// grab the current frame from the camera |
| | | FSDK.TFaces FacePositions = new FSDK.TFaces(); |
| | | int res3 = FSDK.DetectMultipleFaces(imageHandle, FacePositions); |
| | | if(res3 == FSDK.FSDKE_OK) { |
| | | if (FacePositions.faces != null) { |
| | | for (FSDK.TFacePosition fp : FacePositions.faces ) { |
| | | System.out.println("2:"+fp.xc); |
| | | int x1 = (int)(fp.xc - 1.2*fp.w / 2); |
| | | int y1 = (int)(fp.yc - 1.4*fp.w / 2); |
| | | int x2 = (int)(fp.xc + 1.2*fp.w / 2); |
| | | int y2 = (int)(fp.yc + 1.4*fp.w / 2); |
| | | FSDK.HImage img2 = new FSDK.HImage(); |
| | | FSDK.CreateEmptyImage(img2); |
| | | FSDK.CopyRect(imageHandle, x1, y1, x2, y2, img2); |
| | | FSDK.SetJpegCompressionQuality(100); |
| | | String fileName = MainActivity.getInstance().getFilesDir()+"/"+System.currentTimeMillis()+".jpg"; |
| | | int res4 = FSDK.SaveImageToFile(img2, fileName); |
| | | if (res4 == FSDK.FSDKE_OK) { |
| | | System.out.println(fileName); |
| | | } |
| | | List bitmapList = new ArrayList(); |
| | | for (int i = 0; i < 1; i++) { |
| | | NativeImg nativeImg = new NativeImg(); |
| | | nativeImg.image = FileUtil.readFile(new File(fileName)); |
| | | nativeImg.size = nativeImg.image.length; |
| | | SurveillanceQueryItem surveillanceQueryItem = new SurveillanceQueryItem(); |
| | | surveillanceQueryItem.setNativeImg(nativeImg); |
| | | nativeImg.st_track_id = ++tracId; |
| | | surveillanceQueryItem.setStTrackId(nativeImg.st_track_id); |
| | | BitmapFactory.Options options = new BitmapFactory.Options(); |
| | | options.inMutable = true; |
| | | Bitmap bmp = BitmapFactory.decodeByteArray(nativeImg.image, 0, nativeImg.image.length, options); |
| | | Canvas canvas1 = new Canvas(bmp); |
| | | |
| | | surveillanceQueryItem.setBitmap(bmp); |
| | | surveillanceQueryItem.setWidth("100"); |
| | | surveillanceQueryItem.setHeight("100"); |
| | | surveillanceQueryItem.setRegisterOrCheckIn(CommonVariables.Surveillance.OFFLINE_SURVEILLANCE_ITEM_TYPE); |
| | | surveillanceQueryItem.setCreateTime(new Date()); |
| | | bitmapList.add(surveillanceQueryItem); |
| | | |
| | | if (BaseApplication.getInstance().networkAvailable()) { |
| | | SurveillanceMng.getInstance().addBitmap(bitmapList, nativeImg.image, 0, CommonVariables.Camera.IN+"", nativeImg.image); |
| | | } else { |
| | | SurveillanceMng.getInstance().addOfflineBitmap(bitmapList, nativeImg.image, CommonVariables.Camera.IN+""); |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | }); |
| | | Thread.sleep(5); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } catch (InterruptedException e) { |
| | | /*myVideoView.setSource(MjpegInputStream.read("http://192.168.1.13:8080/video")); |
| | | myVideoView.setDisplayMode(MjpegView.SIZE_BEST_FIT); |
| | | myVideoView.showFps(false); |
| | | */ |
| | | } |
| | | }.start(); |
| | | } |
| | | //fragment_supervisory_enter_camera.setVisibility(View.GONE); |
| | | fragment_supervisory_enter_camera.getHolder().addCallback(new SurfaceHolder.Callback() { |
| | | public void surfaceCreated(SurfaceHolder holder) { |
| | | if (CommonVariables.EMULATOR) { |
| | | new SurveillancePhotoEmulateThread().start(); |
| | | } |
| | | if (useNative) { |
| | | synchronized (MainActivity.getInstance()) { |
| | | startEnterCameraThread = new StartCameraThread(Integer.parseInt(CommonVariables.Camera.IN), fragment_supervisory_enter_camera.getHolder().getSurface()); |
| | | startEnterCameraThread.start(); |
| | | } |
| | | } |
| | | } |
| | | }).start(); |
| | | reloadBottomList(); |
| | | |
| | | public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {} |
| | | public void surfaceDestroyed(SurfaceHolder holder) { } |
| | | }); |
| | | fragment_supervisory_exit_camera.getHolder().addCallback(new SurfaceHolder.Callback() { |
| | | public void surfaceCreated(SurfaceHolder holder) { |
| | | if (useNative) { |
| | | synchronized (MainActivity.getInstance()) { |
| | | startEnterCameraThread = new StartCameraThread(Integer.parseInt(CommonVariables.Camera.OUT), fragment_supervisory_exit_camera.getHolder().getSurface()); |
| | | startEnterCameraThread.start(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { } |
| | | public void surfaceDestroyed(SurfaceHolder holder) { } |
| | | }); |
| | | new SurveillanceMng.SurveillanceListThread().start(); |
| | | } |
| | | |
| | |
| | | fragment_supervisory_bottom_visit_list_view.setVisibility(fragment_supervisory_bottom_visitor_radio_button.isChecked()?View.VISIBLE:View.GONE); |
| | | fragment_supervisory_bottom_attendance_background.setVisibility(!fragment_supervisory_bottom_visitor_radio_button.isChecked()?View.VISIBLE:View.GONE); |
| | | fragment_supervisory_bottom_attendance_list_view.setVisibility(!fragment_supervisory_bottom_visitor_radio_button.isChecked()?View.VISIBLE:View.GONE); |
| | | reloadBottomList(); |
| | | } |
| | | |
| | | @OnClick(R.id.fragment_supervisory_bottom_attendance_radio_button) |
| | |
| | | fragment_supervisory_bottom_visit_list_view.setVisibility(fragment_supervisory_bottom_visitor_radio_button.isChecked()?View.VISIBLE:View.GONE); |
| | | fragment_supervisory_bottom_attendance_background.setVisibility(!fragment_supervisory_bottom_visitor_radio_button.isChecked()?View.VISIBLE:View.GONE); |
| | | fragment_supervisory_bottom_attendance_list_view.setVisibility(!fragment_supervisory_bottom_visitor_radio_button.isChecked()?View.VISIBLE:View.GONE); |
| | | reloadBottomList(); |
| | | } |
| | | |
| | | @Override |
| | |
| | | // reloadBottomList(); |
| | | } |
| | | }); |
| | | setupUI(getView()); |
| | | } |
| | | |
| | | @Override |
| | | public void setMenuVisibility(boolean menuVisible) { |
| | | super.setMenuVisibility(menuVisible); |
| | | if (menuVisible && fragment_supervisory_bottom_visit_list_view != null) { |
| | | //reloadBottomList(); |
| | | } |
| | | } |
| | | |
| | | private void reloadBottomList() { |
| | | SurveillanceMng.getInstance().findSurveillanceBottomList(fragment_supervisory_bottom_visitor_radio_button.isChecked()); |
| | | } |
| | | |
| | | } |