옵션 |
|
1 2 3 4 5 | private void startWinklick(){ //startService(new Intent(this, ScreenService.class)); //잘됨 startService(new Intent(this, FaceService.class)); //opencv //unable to add window token null is not for an application android } | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | public class FaceService extends Service implements CvCameraViewListener2{ private LayoutInflater li; private RelativeLayout mPopupView;//항상 보이게할 뷰(nativecam_view.xml의 레이아웃) private CameraBridgeViewBase mOpenCvCameraView;//카메라뷰 (NativeCameraView1) private WindowManager.LayoutParams mParams; //뷰의 위치 및 크기 private WindowManager mWindowManager; private static final String TAG = "OCVSample::Activity"; private static final Scalar FACE_RECT_COLOR = new Scalar(0, 255, 0, 255); public static final int JAVA_DETECTOR = 0; private File mCascadeFile; private CascadeClassifier mJavaDetector; private String[] mDetectorName; private float mRelativeFaceSize = 0.5f; private int mAbsoluteFaceSize = 0; private GlobalSettings global; @Override public IBinder onBind(Intent intent) { return null; } private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) { @Override public void onManagerConnected(int status) { switch (status) { case LoaderCallbackInterface.SUCCESS: { Log.i(TAG, "OpenCV loaded successfully"); try { //==얼굴전면==// InputStream is = getResources().openRawResource( R.raw.lbpcascade_frontalface); File cascadeDir = getDir("cascade", Context.MODE_PRIVATE); mCascadeFile = new File(cascadeDir, "lbpcascade_frontalface.xml"); FileOutputStream os = new FileOutputStream(mCascadeFile); byte[] buffer = new byte[4096]; int bytesRead; while ((bytesRead = is.read(buffer)) != -1) { os.write(buffer, 0, bytesRead); } is.close(); os.close(); //-- end --// mJavaDetector = new CascadeClassifier( mCascadeFile.getAbsolutePath()); if (mJavaDetector.empty()) { Log.e(TAG, "Failed to load cascade classifier"); mJavaDetector = null; } else Log.i(TAG, "Loaded cascade classifier from " + mCascadeFile.getAbsolutePath()); cascadeDir.delete(); } catch (IOException e) { e.printStackTrace(); Log.e(TAG, "Failed to load cascade. Exception thrown: " + e); } mOpenCvCameraView.setCameraIndex(1); mOpenCvCameraView.setMaxFrameSize(300, 200);// TODO : 최대 크기 지정 mOpenCvCameraView.enableView();//뷰 활성화 } break; default: { super.onManagerConnected(status); } break; } } }; public FaceService() { mDetectorName = new String[2]; mDetectorName[JAVA_DETECTOR] = "Java"; Log.i(TAG, "Instantiated new " + this.getClass()); } @Override public void onCreate() { super.onCreate(); Log.i("TAG", "Face Service Started"); li = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE); mParams = new WindowManager.LayoutParams( WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,// WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON, PixelFormat.TRANSLUCENT); //(int w, int h, int _type, int _flags, int _format) mParams.width = cameraWidth; mParams.height = cameraHeight; mParams.gravity = Gravity.LEFT | Gravity.TOP; //좌표계가 좌상점을 중심으로.. mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE); mPopupView = (RelativeLayout) li.inflate(R.layout.nativecam_view, null); mOpenCvCameraView = (NativeCameraView) mPopupView.findViewById(R.id.NativeCameraView1); mOpenCvCameraView.setCameraIndex(1); mOpenCvCameraView.setCvCameraViewListener(this); mWindowManager.addView(mPopupView, mParams); //SYSTEM_ALERT_WINDOW permission 필요 OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_9, this, mLoaderCallback); global = (GlobalSettings) getApplicationContext();//super.onCreate()뒤에 넣자 //TODO global.set등은 처음엔 초기화를 시켜주자 } ....................... | cs |