Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Android Native OpenCV sample: camera preview changes with orientation.

Hello everyone,
I have read several questions about this topic, but not one was really focused on what I experienced.
I am running the native opencv sample on my cell and tablet: Samsung Galaxy S2 and Google Nexus 10.
on both devices, the sample did not work very well.

  1. it only started when the orientation was landscape
  2. it crashed when trying to put the device portrait
  3. the optimal resolution calculated was always limited to 640x480, no matter what device was selected

I took a glance at the code, to see if there were some enhancements possible: in fact, yes, it seems there are.
I figured out how to make it select a better resolution, and how to make it work also in portrait mode. In fact, these were little changes, which did not affect algorithms inside the sample.
Now the application works, but what I see is the following:

  1. in landscape mode, 90 deg CCW with respect to portrait, everything is well, the text above is aligned with the image from the camera. image description
  2. in portrait mode, the image is stretched and rotated 90 deg CCW. image description
  3. in landscape mode, 90 deg CW with respect to portrait, image is rotated 180 deg, text is correct and image upside down. image description

Some forum members (Itay) suggest to take the image and rotate (with a combined transpose and flip) in order to have it ready to display. I did not try, but I am positive it will work.
But I am looking for a different solution, if anyone can advice:
the image rotation happens when handling a command of the APP_CMD_INIT_WINDOW type.
Is it possible to check the orientation of the display and prevent OpenCV from rotating the image? Does it make sense? I would prefer not to affect java code or XML.
Did anyone encounter such a behaviour?
Sorry for the length. Thank you

Android Native OpenCV sample: camera preview changes with orientation.

Hello everyone,
I have read several questions about this topic, but not one was really focused on what I experienced.
I am running the native opencv sample on my cell and tablet: Samsung Galaxy S2 and Google Nexus 10.
on both devices, the sample did not work very well.

  1. it only started when the orientation was landscape
  2. it crashed when trying to put the device portrait
  3. the optimal resolution calculated was always limited to 640x480, no matter what device was selected

I took a glance at the code, to see if there were some enhancements possible: in fact, yes, it seems there are.
I figured out how to make it select a better resolution, and how to make it work also in portrait mode. In fact, these were little changes, which did not affect algorithms inside the sample.
Now the application works, but what I see is the following:

  1. in landscape mode, 90 deg CCW with respect to portrait, everything is well, the text above is aligned with the image from the camera. camera.
    image description
  2. in portrait mode, the image is stretched and rotated 90 deg CCW. CCW.
    image description
  3. in landscape mode, 90 deg CW with respect to portrait, image is rotated 180 deg, text is correct and image upside down. down.
    image description

Some forum members (Itay) suggest to take the image and rotate (with a combined transpose and flip) in order to have it ready to display. I did not try, but I am positive it will work.
But I am looking for a different solution, if anyone can advice:
the image rotation happens when handling a command of the APP_CMD_INIT_WINDOW type.
Is it possible to check the orientation of the display and prevent OpenCV from rotating the image? Does it make sense? I would prefer not to affect java code or XML.
Did anyone encounter such a behaviour?
Sorry for the length. Thank you

Android Native OpenCV sample: camera preview changes with orientation.

Hello everyone,
I have read several questions about this topic, but not one was really focused on what I experienced.
I am running the native opencv sample on my cell and tablet: Samsung Galaxy S2 and Google Nexus 10.
on both devices, the sample did not work very well.

  1. it only started when the orientation was landscape
  2. it crashed when trying to put the device portrait
  3. the optimal resolution calculated was always limited to 640x480, no matter what device was selected

I took a glance at the code, to see if there were some enhancements possible: in fact, yes, it seems there are.
I figured out how to make it select a better resolution, and how to make it work also in portrait mode. In fact, these were little changes, which did not affect algorithms inside the sample.
Now the application works, but what I see is the following:

  1. in landscape mode, 90 deg CCW with respect to portrait, everything is well, the text above is aligned with the image from the camera.
    image description
  2. in portrait mode, the image is stretched and rotated 90 deg CCW.
    image description
  3. in landscape mode, 90 deg CW with respect to portrait, image is rotated 180 deg, text is correct and image upside down.
    image description

Some forum members (Itay) suggest to take the image and rotate (with a combined transpose and flip) in order to have it ready to display. I did not try, but I am positive it will work.
But I am looking for a different solution, if anyone can advice:
the image rotation happens when handling a command of the APP_CMD_INIT_WINDOW type.
Is it possible to check the orientation of the display and prevent OpenCV from rotating the image? Does it make sense? I would prefer not to affect java code or XML.
Did anyone encounter such a behaviour?
Sorry for the length. Thank you

AFK