我正在构建一个 Android 应用程序,目的是使用 OpenCV for Android 扫描表单。我计划使用与 QR 码相同的概念,即对齐方 block ,以确保每次都能正确扫描。
我知道我只能使用 ZXing 库,但是我没有使用二维码。在对它进行图像处理之前,我只是借用了对齐方 block 的想法。
我找到了 this blog其中他使用 OpenCV C++ 库找到对齐方 block ,然后他重新对齐图像并输出重新对齐的 QR 码。 His C++ Code can be found in his github here.除了我在大学里上过的课之外,我对 C++ 没有太多的背景,而且我没有在 C++ 中使用 OpenCV 的经验。我知道大部分代码都在尝试这样做,但是,当我在主函数之外转换他的函数时,我遇到了这个问题:
void cv_getVertices(ArrayList<ArrayList<Point>> contours, int c_id, float slope, ArrayList<Point> quad){
Rect box = Imgproc.boundingRect(contours.get(c_id)); //<-- problematic code
//more code here
}
原代码为:
void cv_getVertices(vector<vector<Point> > contours, int c_id, float slope, vector<Point2f>& quad){
Rect box;
box = boundingRect( contours[c_id]);
//more code here
}
但是,我收到一个错误,因为 Imgproc.boundingRect(contours.get(c_id));
正在寻找 MatOfPoint
对象,还有我的contours
ArrayList 由点组成。
注意:我不得不更改他的很多代码,比如更改 vectors
至 ArrayLists
,以及在对 Points
进行操作时重写.
最佳答案
boundingRect()
的 C++ 变体期望一个 InputArray<T>
它有一个接受 const vector<T> &
的构造函数因此它隐式转换给定的 vector<T>
你进入boundingRect()
进入InputArray<T>
.这不适用于 JAVA。您必须明确地将 ArrayList 转换为 MatOfPoint
可能通过 MatOfPoint.fromList(java.util.List<Point> lp)
关于Android OpenCV - 将 OpenCV C++ 代码转换为 Android 以检测 QR 码对齐方 block ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30542018/