有什么理由说明为什么 OpenCV QRcodeDetector 可以使用带有 swift 的 Objective C++ 绑定处理一个图像而不是另一个图像?

问题描述

我正在尝试使用 OpenCV 检测静止图像中的二维码,然后确定其在图像中的位置。我已经成功地链接了 OpenCV 库和图像样本,OpenCV 代码在大多数情况下不会检测到二维码,但是在 swift 中检测二维码代码每次都有效,所以我知道这不是问题与图像。我在 OpenCV 网站上搜索了文档无济于事。我想使用openCV检测二维码和位置的原因是为了对图像进行进一步的操作,在Mat图像上有位置会很有好处。

请注意,我是第一次尝试很多东西的学生。

Swift 代码

    func detectQRCode(_ image: UIImage?) -> [CIFeature]? {
    if let image = image,let ciImage = CIImage.init(image: image){
        var options: [String: Any]
        let context = CIContext()
        options = [CIDetectorAccuracy: CIDetectorAccuracyHigh]
        let qrDetector = CIDetector(ofType: CIDetectorTypeQRCode,context: context,options: options)
        if ciImage.properties.keys.contains((kCGImagePropertyOrientation as String)){
            options = [CIDetectorImageOrientation: ciImage.properties[(kCGImagePropertyOrientation as String)] ?? 1]
        } else {
            options = [CIDetectorImageOrientation: 1]
        }
        let features = qrDetector?.features(in: ciImage,options: options)
        return features

    }
    return nil
}

   //qr code
            if let features = detectQRCode(displayPhoto.image),!features.isEmpty{
                for case let row as CiqrCodeFeature in features{
                    print(row.messageString ?? "nope")
                    print(row.bounds)
                    print(row.topLeft)
                    print(row.bottomLeft)
                    print(row.topRight)
                    print(row.bottomright)
                   // print(row.)
                }
            }

调用 OpenCV 包装器:

print("\(OpenCVWrapper.decodeQRCode(displayPhoto.image!))")

调用纯 C++ 代码

+(Nsstring *) decodeQRCode: (UIImage *)inputimage {
Mat mat = [inputimage CVMat];

string qrcode = detectAndDecode(mat);
    
return [Nsstring stringWithFormat: @"Data stored in the QR code is %s",qrcode.c_str()];

}

最后是 C++ 代码

QRCodeDetector qrDecoder = QRCodeDetector();

String detectAndDecode (Mat mat){

vector<Point> points;

String data = qrDecoder.detectAndDecode(mat,points);

return data;

}

任何线索、提示或技巧将不胜感激。如果有人知道任何项目,它允许我检测 QR 码并找到与 QR 相关的图像其余部分中某些区域的像素值,这将非常有帮助。

编辑:我在使用 detectAndDecode 函数之前将图像大小调整为 (1200X800) 并且我得到了更加一致的结果,是否有我应该瞄准的最佳尺寸?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...