Android OpenCV -转换OpenCV c++代码到Android,以检测QR码对齐方块

Android OpenCV - Converting OpenCV C++ Code to Android in order to detect QR Code Alignment Squares

本文关键字:Android OpenCV QR 对齐 方块 检测 -转换 c++ 代码      更新时间:2023-10-16

我正在构建一个Android应用程序,我的目标是使用OpenCV扫描Android表单。我计划使用与QR码相同的概念,对齐方块,以确保我每次都能正确扫描。

我知道我可以使用ZXing库,但是,我没有使用QR码。在我对它进行图像处理之前,我只是借用了对齐方形的想法。

我发现了这个博客,其中他使用OpenCV c++库找到对齐方块,然后他重新对齐图像并输出重新对齐的QR码。他的c++代码可以在他的github找到。除了我在大学里学过的课程之外,我对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数组列表是由点组成的。

注意:我不得不改变很多他的代码,如改变vectorsArrayLists,以及重写当他做Points的操作。

boundingRect()的c++变体期望InputArray<T>具有接受const vector<T> &的构造函数,因此它隐式地将给定的vector<T>转换为boundingRect()InputArray<T>。这在JAVA中不起作用。你必须明确地将数组列表转换为MatOfPoint可以通过MatOfPoint.fromList(java.util.List<Point> lp)