Targeting Android zxing: ResultMetaData is null, Get Rotation / Orientation

I am working on an application that reads QR codes and I need code orientation. ZXING source claims that orientation can be obtained from the ResultMetaData strong> hash table via the ORIENTATION key

Now my problem is that getResultMetaData () does not return any results when I run the following:

orientation = (Integer) Returned[v].getResultMetadata().get("ORIENTATION"); 

However, the line directly above it,

 points = Returned[v].getResultPoints(); 

It works fine, so I know that the code is read and it returns data.

Does anyone know of a fix for this or another method of getting orientation?

Last note: I use QRCodeMultiReader , so Returned is an array.

Thanks Zander

EDIT I just found that getResultMetaData strong> only supports orientation for 1D barcodes, so I think the questions now are: How do I get the orientation of a QR code?

EDIT # 2 Here is the code for getting the rotation (doesn't support perspectives)

 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 
+4
source share
2 answers

The result has a getResultPoints method. This will return the location of the finder patterns (large black squares) in the QR code. Since they appear at the top left, top right and bottom left of the code, you can determine the orientation that they describe. There are several static helper methods in the ResultPoint class.

For an image without perspective, three dots should describe an isosceles right triangle. If there is a prospect, things get complicated.

+1
source

A correct calculation takes into account only the segment between a and b points and the angle defined between the coordinate axis. It adjusts the degree depending on the quadrant. The calculation does not require a "distance" or a "straight" vary:

 ResultPoint a= points[1]; ResultPoint b= points[2]; ResultPoint c= points[0]; double z = Math.abs(a.getX()-b.getX()); double x = Math.abs(a.getY()-b.getY()); double theta = Math.toDegrees(Math.atan(x/z)); // Quadrants 0 and 1 if(a.getY() > b.getY()) { if(a.getX() > b.getX()) { theta = 90 + (90 - theta); } } // Quadrants 2 or 3 else { if (a.getX() > b.getX()) { theta = 180 + theta; } else { theta = 360 - theta; } } return theta; 
0
source

All Articles