安卓zxing方向:ResultMetaData为空,获取旋转/方向 [英] Android zxing orientation: ResultMetaData is null, Get Rotation/Orientation

查看:416
本文介绍了安卓zxing方向:ResultMetaData为空,获取旋转/方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个应用程序,读取QR codeS,我需要的code的方向。 该ZXING源指出的方向可以从哈希表中获得的 ResultMetaData 通过按键的取向

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

现在,我的问题是,在 getResultMetaData()未返回任何结果当我运行以下命令:

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();

工作得很好,所以我知道,code被读取,并且它返回的数据。

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?

最后一个说明:我使用的 QR codeMultiReader 这是为什么的返回的是一个数组

One last note: I am using QRCodeMultiReader which is why Returned is an array.

谢谢, 詹德

修改我刚刚发现的 getResultMetaData 仅支持方向的一维条码codeS,所以我猜这个问题现在是:如何我得到一个QR code的方向?

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?

修改#2 这里是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存储转动程度

//theta stores the degree of rotation

推荐答案

结果有getResultPoints方法。这将返回取景器模式的一个QR code中的位置(大黑方块)。由于这些出现左上,右上和左下角的code,可以计算出它们所描述的方向。有在ResultPoint类中的一些静态辅助方法。

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.

这篇关于安卓zxing方向:ResultMetaData为空,获取旋转/方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆