I always got flipped points (bounding boxes) vertically. I fixed this totally with helper method:
private static func translateVisionToNormalBoundingBox(bb: CGRect, imageFullRect: CGRect) -> CGRect
{
let renormalized = VNImageRectForNormalizedRect(bb, Int(imageFullRect.width), Int(imageFullRect.height))
// Vertically translate origin !!!
// Vertically translate origin !!!
// Vertically translate origin !!!
return CGRect(
origin: CGPoint(
x: renormalized.origin.x,
y: imageFullRect.maxY - renormalized.origin.y - renormalized.size.height
),
size: renormalized.size
)
}
For cgImage orientation I use this StackOverflow's extension:
extension UIImage {
var cgImagePropertyOrientation: CGImagePropertyOrientation {
switch imageOrientation
{
case .down: return .down
case .left: return .left
case .right: return .right
case .up: return .up
case .downMirrored: return .downMirrored
case .leftMirrored: return .leftMirrored
case .rightMirrored: return .rightMirrored
case .upMirrored: return .upMirrored
// TWEAK FOR NEW CASES !!!
// TWEAK FOR NEW CASES !!!
// TWEAK FOR NEW CASES !!!
@unknown default:
return .down
}
}
}
Use of unresolved identifier 'uiImage'
as soon as I attempt to declare the variableorientation
in the first line. Is there a specific library that needs to be imported for this to work? – Haddix