gpt4 book ai didi

ios - CIDetector 要么没有检测到,要么在奇怪的地方检测到

转载 作者:行者123 更新时间:2023-11-28 08:50:49 24 4
gpt4 key购买 nike

我正在练习使用一些 swift 2,但在使用 CIDetector 时遇到了一些困难。

我有一个应用程序,里面有一系列图片;三个不同的矩形和三张不同的人物/团体照片。我只是在这些图像上尝试 CIDetector 以查看识别出的内容。我最成功的是人脸——但是它识别的人脸在图像上非常奇怪的地方。

这是我测试过的矩形图像及其输出: Rectangle Test

这是一张人脸图片: enter image description here

这是我的检测代码:

    ///does the detecting of features
func detectFeatures() -> [CIFeature]? {

print("detecting")

let detectorOptions: [String: AnyObject] = [CIDetectorAccuracy: CIDetectorAccuracyHigh, CIDetectorImageOrientation: 6]
var detectorType : String

switch currentPhoto.currentType {
case .RECTANGLES:
detectorType = CIDetectorTypeRectangle
case .FACES:
detectorType = CIDetectorTypeFace
default:
print("error in phototype")
return nil

}

let detector = CIDetector(ofType: detectorType, context: nil, options: detectorOptions)
let image = CIImage(image: imageViewer.image!)

guard image != nil else{
print("image not cast to CIImage")
return nil
}

return detector.featuresInImage(image!)
}

添加星星的地方:

for f in features!{
print(f.bounds.origin)
imageViewer.layer.addSublayer(createMarker(f.bounds.size, location: f.bounds.origin))
}

星星的诞生地:

///Creates a star on a layer and puts it over the point passed in
func createMarker(size: CGSize, location: CGPoint) -> CALayer{

print("The marker will be at [\(location.x),\(location.y)]")
//doesn't appear in correct place on the screen
let newLayer = CALayer()
newLayer.bounds = imageViewer.bounds
newLayer.frame = CGRect(origin: location, size: size)
newLayer.contents = UIImage(named: "star")?.CGImage
newLayer.backgroundColor = UIColor(colorLiteralRed: 0.0, green: 0.0, blue: 0.0, alpha: 0.0).CGColor
newLayer.masksToBounds = false

return newLayer
}

有没有人遇到过这样的事情?

最佳答案

很遗憾,我认为您使用的矩形与您使用的图像不兼容。如果您查看 CIDetector Class Reference上面写着:

CIDetectorTypeRectangle A detector that searches for rectangular areasin a still image or video, returning CIRectangleFeature objects thatprovide information about detected regions.

The rectangle detector finds areas that are likely to representrectangular objects that appear in perspective in the image, such aspapers or books seen on a desktop.

采纳了这个建议,我在这张图片上运行了你的代码:enter image description here

结果:

bounds = "(296.752716064453, 74.7079086303711, 181.281158447266,253.205474853516)\n"

我在其他平面矩形上运行了您的代码,但没有找到任何特征。需要有点像“真实世界”的图像。

关于ios - CIDetector 要么没有检测到,要么在奇怪的地方检测到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34244752/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com