[Android] Display Orientation Issue When Working with OpenCV on Android

The original post is moved to my new personal blog

8 comments

  1. Michal Vozny · · Reply

    Very nice, thanks for sharing. However, I feel that it has some impact on performance and also on HTC Desire, switching from portrait back to landscape causes border to flicker. Unfortunately, I did not find out better solution so far except for ignoring orientation changes what is actually no problem in case of image processing but it may be not solution in case of complex GUI with standard android View components. Anyways, very helpful post.

    1. It is a little trick I figure out when playing around with OpenCV on Android. May not be the optimal solution for orientation change issues, but worth a try.

  2. 多谢。这样可以直接调用OpenCV的VideoCapture,不用调用Android的相机代码了。据说后者Performance相比OpenCV来说不是很好。

  3. Have you tried this on the most recent version of OpenCV? I can’t seem to get this to work.
    I cant believe that the Authors of OpenCV wouldn’t include an easy way to deal with rotation?!

    Either way, I’d love to hear if you’ve still got a way for this to work!

    1. Actually, I ended up getting it to work, it is just slightly different now because they use a cached bitmap
      Matrix matrix = new Matrix();
      matrix.preTranslate((canvas.getWidth() – mCacheBitmap.getWidth()) / 2,(canvas.getHeight() – mCacheBitmap.getHeight()) / 2);

      if(getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT)
      matrix.postRotate(90f,(canvas.getWidth()) / 2,(canvas.getHeight()) / 2);
      canvas.drawBitmap(mCacheBitmap, matrix, new Paint());

      1. Tried the code and it worked fine here. Don’t quite understand the size problem. Is the size of the “mCacheBitmap” the same as the screen size? If so, should fill the screen in both orientations. Or you may look into the “mCacheBitmap” to find out. By the way, the bitmap can always be resized using “resized_bmp = Bitmap.createScaledBitmap(bmp, new_width, new_height, false)”

    2. However, in my implementation, in portrait, the preview size is much smaller than in landscape (ie, it does not fill the screen). I assume that it is because it thinks that that is the largest size of screen that can fit in portrait. Is there any way to increase the preview size?

      1. I’m facing the same issue, but I have no solution so far.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: