android - OpenCV camera orientation issue -


i have simple project show camera org.opencv.android.javacameraview.

my problem in default camera on landscape mode , can't change cause need define camerabridgeviewbase instead of regular camera intent.

this part of code:

xml code:

        <linearlayout             android:layout_width="match_parent"             android:layout_height="match_parent" >              <org.opencv.android.javacameraview                 android:layout_width="fill_parent"                 android:layout_height="300dp"                 android:visibility="gone"                 android:id="@+id/helloopencvview"                 opencv:show_fps="true"                 opencv:camera_id="1" />           </linearlayout>            <linearlayout             android:layout_width="match_parent"             android:layout_height="wrap_content" >               <button                 android:id="@+id/btnvideo"                 android:layout_marginleft="2dp"                 android:layout_marginright="2dp"                                     android:layout_width="0dp"                 style="@style/button"                 android:layout_height="wrap_content"                 android:layout_weight="1.00"                 android:text="@string/videobtn"                 android:textsize="18dip" />           </linearlayout>    

java code :

 camerabridgeviewbase mopencvcameraview;     button videobutton;  protected void oncreate(bundle savedinstancestate) {          super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);         overridependingtransition(0, 0);          videobutton = (button) this.findviewbyid(r.id.btnvideo);          videobutton.setonclicklistener(onclicklistener);          mopencvcameraview= (camerabridgeviewbase) findviewbyid(r.id.helloopencvview);         mopencvcameraview.setvisibility(surfaceview.invisible);      }           private onclicklistener onclicklistener = new onclicklistener() {              @override             public void onclick(view v) {                     switch (v.getid()){                          case r.id.btnvideo:                             if(mopencvcameraview.getvisibility() == surfaceview.visible)                             {                                 mopencvcameraview.setvisibility(surfaceview.invisible);                             }                             else                             {                                 mopencvcameraview.setvisibility(surfaceview.visible);                             }                              break;                         default :                             break;                     }              }         };           public void onresume() {             super.onresume();             overridependingtransition(0, 0);             opencvloader.initasync(opencvloader.opencv_version_2_4_3, this, mloadercallback);         }          public void onpause()          {              super.onpause();              if (mopencvcameraview != null)                  mopencvcameraview.disableview();          }          public void ondestroy() {              super.ondestroy();              if (mopencvcameraview != null)                  mopencvcameraview.disableview();          }          public void oncameraviewstarted(int width, int height) {          }           public void oncameraviewstopped() {          }          public mat oncameraframe(cvcameraviewframe inputframe) {              return inputframe.rgba();          }          private baseloadercallback mloadercallback = new baseloadercallback(this) {             @override             public void onmanagerconnected(int status) {                 switch (status) {                     case loadercallbackinterface.success:                     {                         //log.i(tag, "opencv loaded successfully");                         mopencvcameraview.enableview();                     } break;                     default:                     {                         super.onmanagerconnected(status);                     } break;                 }             }         }; 

so how can change default orientation?

thanks!

ok, found solution:

first javacameraview.java class in opencv library - 2.4.5

and in initializecamera function before mcamera.startpreview(); added 2 function:

            setdisplayorientation(mcamera, 90);             mcamera.setpreviewdisplay(getholder()); 

and first function implemented this:

protected void setdisplayorientation(camera camera, int angle){     method downpolymorphic;     try     {         downpolymorphic = camera.getclass().getmethod("setdisplayorientation", new class[] { int.class });         if (downpolymorphic != null)             downpolymorphic.invoke(camera, new object[] { angle });     }     catch (exception e1)     {     } } 

i reminding work opencv.

hope someone.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -