问题描述:

I am using camera to capture an image on my phone which use Android 4.03 and opencv for android 2.4.3

In my application I am reading the image from disk using Highgui.imread

But the problem is the function is rotating the image always in contrast to the actual saved image!

if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) {

if (resultCode == RESULT_OK) {

Mat img = Highgui.imread(file.getAbsolutePath());

if(img!=null)

n.detectDocument(img.getNativeObjAddr());

and in native side

jbyteArray JNICALL Java_com_example_superemr_NSuperEMR_detectDocument(JNIEnv *env, jobject object, jlong addr)

{

Mat* image = (Mat*) addr;

imwrite("/mnt/sdcard/work/hala.jpg",*image);

return NULL;

}

How can I read the image in the correct position?

网友答案:

imread decodes the JPG metadata differently than the image viewer you're using.

Mobile photos have the "Orientation" EXIF set. This is seen in Chrome with photo1 and photo2 on tinypic.

Not sure how to read and handle the EXIF flags correctly in C++, but in python a similar question.

Haven't tried this, but you may consider reading the image with another library, saving as a png and then reading into opencv.

PS: Saw this was an old post, but this came up in my search result when I ran into the same issue, so maybe it will be helpful to others.

网友答案:

You can use imagemagick to first auto-orient the image. This will change orientation metadata to 1( or Top-Left) and change the orientation of image(rotate and mirror, whichever is necessary).

Checking orientation metadata: identify -format '%[exif:orientation]'

Auto-Orient Image: convert -auto-orient

相关阅读:
Top