Quantcast
Channel: OpenCV Q&A Forum - Latest question feed
Viewing all articles
Browse latest Browse all 53

Android + OpenCV + Face detection + Custom Layout

$
0
0
Hi, I am using: - Android 4.0.3 - OpenCV 2.4.2 - Samsung Galaxy S2 The face-detection example (from the opencv 2.4.2) is working perfectly. But now, I would like to create a custom layout and actually work with just the data extracted from face detection and build a game on it. Not necessarily having the FdView surface taking the entire screen. I have done these modifications below, but just a black screen is displayed. Added a fd.xml layout: Modified the baseLoaderCallback of FdActivity.java: private BaseLoaderCallback mOpenCVCallBack = new BaseLoaderCallback(this) { @Override public void onManagerConnected(int status) { switch (status) { case LoaderCallbackInterface.SUCCESS: { Log.i(TAG, "OpenCV loaded successfully"); // Load native libs after OpenCV initialization System.loadLibrary("detection_based_tracker"); //EXPERIMENT setContentView(R.layout.fd); FdView surface = (FdView) (findViewById(R.id.FdView)); surface = mView; // Create and set View mView = new FdView(mAppContext); mView.setDetectorType(mDetectorType); mView.setMinFaceSize(0.2f); //setContentView(mView); // Check native OpenCV camera if( !mView.openCamera() ) { AlertDialog ad = new AlertDialog.Builder(mAppContext).create(); ad.setCancelable(false); // This blocks the 'BACK' button ad.setMessage("Fatal error: can't open camera!"); ad.setButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); finish(); } }); ad.show(); } } break; default: { super.onManagerConnected(status); } break; } } }; Added constructors in FdView.java: public FdView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); // TODO Auto-generated constructor stub } public FdView(Context context, AttributeSet attrs) { super(context, attrs); // TODO Auto-generated constructor stub } Added constructors in SampleCvViewBase.java: public SampleCvViewBase(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); // TODO Auto-generated constructor stub } public SampleCvViewBase(Context context, AttributeSet attrs) { super(context, attrs); // TODO Auto-generated constructor stub }

Viewing all articles
Browse latest Browse all 53

Trending Articles