c++ - 为什么 OpenCV QRcodeDetector 可以在一个图像上工作而不是另一个使用 Objective C++ 绑定与 swift 的原因?
问题描述
我正在尝试使用 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();
字符串检测和解码(垫子){
vector<Point> points;
String data = qrDecoder.detectAndDecode(mat, points);
return data;
}
任何线索、提示或提示将不胜感激。如果有人知道任何项目,它允许我检测 QR 码并在图像的其余部分中找到与 QR 相关的某些区域的像素值,这将非常有帮助。
编辑:在使用 detectAndDecode 函数之前,我将图像的大小调整为 (1200X800) 并且我得到了更加一致的结果,是否有我应该瞄准的最佳尺寸?
解决方案
推荐阅读
- python - 如何为 pandas 数据框列中的每个唯一值添加重复的月份行?
- javascript - 重新渲染键值对对象组件
- java - 如何使用 Hibernate 创建可以引用不同类型实体的实体字段
- reactjs - 从反应中检查 Django 自定义权限
- r - 使用 dotplot (binaxis = "y") 绘图时出现 x 轴错误 - ggplot
- angular - 如何使用 Angular Schematics 删除空文件夹或删除树中的目录?
- google-cloud-platform - 谷歌云平台免费套餐对 f1-micro 实例的突发收费
- sql - 获取上周有价格更新的产品
- html - 有没有办法让我的页面在与我的屏幕尺寸不同的屏幕上打开时不放大?
- azure-active-directory - 从客户端应用到另一个 API 的 Azure 身份验证