Android OpenCV - 将 OpenCV C++ 代码转换为 Android 以检测 QR 码对齐方 block

标签 android c++ opencv

我正在构建一个 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 由点组成。

注意:我不得不更改他的很多代码,比如更改 vectorsArrayLists ,以及在对 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/

相关文章:

android - alignparentbottom 用于 ScrollView 中的相对布局

c++ - 为什么 Boost::multiprecision::sqrt(1) 返回 0?

c# - EmguCV FindFundamentalMat - 输入参数

python - 如何还原由openface.AlignDlib.align完成的转换?

python - 计算图形的方向以将其拉直(在Python中)

android - ConstraintLayout Ratio 绑定(bind)有宽度但没有高度

android - 如何实时持续更新UI?

android - 流式传输到 VideoView 仅在使用三星手机时在 Wifi 上播放

c++ - 访问派生类中的成员模板函数中的元素时,unordered_map 的性能低下

c++排序跟踪索引