如何解决有什么理由说明为什么 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!))")
+(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 举报,一经查实,本站将立刻删除。