【问题标题】:GMVTextLineFeature returns null when initialised with the image in iOS在 iOS 中使用图像初始化时,GMVTextLineFeature 返回 null
【发布时间】:2019-01-22 09:07:37
【问题描述】:

我已将textlinedetector 初始化如下

self.textDetector = [GMVDetector detectorOfType:GMVDetectorTypeText options:nil]; 

由于我只想要一行而不是整个块,我直接访问GMVTextLineFeature,并且输入图像的类型是直接从相机预览中获得的UIImage

NSArray<GMVTextLineFeature *> *features = [self.textDetector featuresInImage:[_Result originalImage] options:nil]; 

但是上面的数组是零。

   [myOperation setCompletionBlock:^{


                for (GMVTextLineFeature *textLine in features) {

                    NSLog(@"value of each element: %@", textLine.value);

                    _Result.text = textLine.value;
                }



        [self finishDetection];
    }];

    [_operationQueue addOperation:myOperation];

我担心我的项目是在 gradle 中,而 GoogleVision 是在 cocoapods 中构建的。所以我手动将框架文件复制到我的项目中,并将其链接到frameworks and libraries。我还链接了框架的资源文件,其中包含copy resource bundles 下的所有转换配置文件。

然而feature 对象是nil。我还多次清理构建了该项目。由于我是 iOS 新手,我无法弄清楚它是 cocoapods 的问题还是它的实现方式。但这就是它在演示应用程序TextDetectorDemo 中的实现方式。我正在使用 xcode 9.4。

任何见解或任何解决方法将不胜感激。

提前致谢。

【问题讨论】:

    标签: ios gradle cocoapods google-vision google-ios-vision


    【解决方案1】:

    在传递到具有类似扩展名的移动视觉之前转换或重新创建 UIImage,可以根据需要更改过滤器

    extension UIImage {
        var noir: UIImage? {
            let context = CIContext(options: nil)
            guard let currentFilter = CIFilter(name: "CISharpenLuminance") else { return nil }
            currentFilter.setValue(CIImage(image: self), forKey: kCIInputImageKey)
            if let output = currentFilter.outputImage,
                let cgImage = context.createCGImage(output, from: output.extent) {
                return UIImage(cgImage: cgImage, scale: scale, orientation: imageOrientation)
            }
            return nil
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2017-05-19
      • 1970-01-01
      • 2023-04-02
      • 1970-01-01
      • 2020-03-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多