I am working on an app that reads QR codes and I need the orientation of the code. The ZXING source states that the orientation can be obtained from a hashtable ResultMetaData through the key ORIENTATION
Now, my issue is that the getResultMetaData() is not returning any results when I run the following:
orientation = (Integer) Returned[v].getResultMetadata().get("ORIENTATION");
However, the line directly above this,
points = Returned[v].getResultPoints();
Works just fine, so I know that the code is being read, and it is returning data.
Does anyone know of a fix for this or a different method of obtaining the orientation?
One last note: I am using QRCodeMultiReader which is why Returned is an array.
Thanks, Zander
EDIT I just found that getResultMetaData only supports orientation for 1D barcodes, So I guess the questions is now: How do I get the orientation of a QR code?
EDIT #2 Here is the code to get the rotation (doesn't support perspective)
ResultPoint a= points[1];
ResultPoint b= points[2];
ResultPoint c= points[0];
float distance = Math.abs(a.getX()-b.getX());
RectF rect = new RectF(a.getX(), a.getY(), a.getX()+distance, a.getY()+distance);
//Find the degree of the rotation that is needed
double z = Math.abs(a.getX()-b.getX());
double x = Math.abs(a.getY()-b.getY());
double theta = Math.atan(x/z);
if((b.getX()<a.getX())&&(b.getY()>a.getY())){//-+
theta=180-theta;
}else if((b.getX()<a.getX())&&(b.getY()<a.getY())){//--
theta=180+theta;
}else if((b.getX()>a.getX())&&(b.getY()<a.getY())){ //+-
theta=360-theta;
}
//theta stores the degree of rotation
Result has a getResultPoints method. That will return the locations of the finder patterns (the large black squares) in a QR code. Since those appear top-left, top-right, and bottom-left of the code, you can figure out the orientation that they describe. There are some static helper methods in the ResultPoint class.
For an image with no perspective, the three points should describe an isosceles right triangle. If there is perspective, things get more complicated.