Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How does this method calculate the crop area? #1

Open
DiwakarThapa opened this issue Jun 12, 2019 · 2 comments
Open

How does this method calculate the crop area? #1

DiwakarThapa opened this issue Jun 12, 2019 · 2 comments

Comments

@DiwakarThapa
Copy link

  private func cropImage(object: VNDetectedObjectObservation, padding: UIEdgeInsets) -> (image: CGImage, frame: CGRect)? {
        let width = object.boundingBox.width * CGFloat(detectable.width)
        let height = object.boundingBox.height * CGFloat(detectable.height)
        let x = object.boundingBox.origin.x * CGFloat(detectable.width)
        let y = (1 - object.boundingBox.origin.y) * CGFloat(detectable.height) - height
        
        let croppingRect = CGRect(x: x - padding.left, y: y - padding.top, width: width + (padding.left + padding.right), height: height + (padding.top + padding.bottom))
        
        guard let image = self.detectable.cropping(to: croppingRect) else { return nil }
        
        return (image: image, frame: croppingRect)
    }
    
@94cp
Copy link
Owner

94cp commented Jul 10, 2019

  1. UIKit coordinate space:
    Origin in the top left corner
    Max height and width values of the screen size in points
  2. Vision coordinate space:
    Origin in the bottom left corner
    Max height and width of 1

There are 2 different coordinate systems we have to convert between.

I found that the Vision cannot fully recognize faces, so I added a padding property.

@DiwakarThapa
Copy link
Author

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants