OpenCv with Android Camera Surfaceview -


i trying develop image recognition android application... using customized camera using surface view.... as herein android capture images ... want process captured images using opencv , how can captured image , convert mat ? there way save captured image temporary ? in advance

i assume have added opencv library project successfully.

here sample code using opencv4android.

public class samplecameraframeaccessactivity extends activity implements        cvcameraviewlistener2, ontouchlistener{ private static final string  tag = "samplecameraframeaccessactivity";  protected camerabridgeviewbase camerapreview; protected mat mrgba;  protected baseloadercallback  mloadercallback = new baseloadercallback(this) {     @override     public void onmanagerconnected(int status) {         switch (status) {             case loadercallbackinterface.success:             {                 log.i(tag, "opencv loaded successfully"); //                    mopencvcameraview.enableview(); //                    mopencvcameraview.setontouchlistener(colorregiondetectionactivity.this);                 camerapreview.enableview();             } break;             default:             {                 super.onmanagerconnected(status);             } break;         }     } };  @override protected void oncreate(bundle savedinstancestate) {     // todo auto-generated method stub     super.oncreate(savedinstancestate);     setcontentview(r.layout.camera_sample_layout);      camerapreview = (camerabridgeviewbase) findviewbyid(r.id.sample_test_camera_view);      camerapreview.setcvcameraviewlistener(this);  }  @override protected void ondestroy() {     // todo auto-generated method stub     super.ondestroy(); }  @override protected void onpause() {     // todo auto-generated method stub     super.onpause();     if(camerapreview != null){         camerapreview.disableview();     } }  @override protected void onresume() {     // todo auto-generated method stub     super.onresume();     opencvloader.initasync(opencvloader.opencv_version_2_4_3, this, mloadercallback); }  @override public void oncameraviewstarted(int width, int height) {     // todo auto-generated method stub     mrgba =  new mat(height, width, cvtype.cv_8uc4); }  @override public void oncameraviewstopped() {     // todo auto-generated method stub     mrgba.release();  }  @override public mat oncameraframe(cvcameraviewframe inputframe) {     // todo auto-generated method stub     mrgba = inputframe.rgba();      return mrgba; }  @override public boolean ontouch(view v, motionevent event) {     // todo auto-generated method stub     return false; } 

}

and xml layout file :

<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:id="@+id/sample_test_layout" >      <org.opencv.android.javacameraview         android:layout_width="match_parent"         android:layout_height="match_parent"         android:id="@+id/sample_test_camera_view" />  </relativelayout> 

in oncameraframe method can access every frame frame buffer of camera. if want capture image can add button , take particular frame buffer , process it. frame given mat object default.so don't have convert it. after processing, if need converted bitmap, can call utils.mattobitmap(mat, bmp); method that.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -