Bounding Box from VNDetectRectangleRequest is not correct size when used as child VC
First let's look at boundingBox
, which is a "normalized" rectangle. Apple says
The coordinates are normalized to the dimensions of the processed image, with the origin at the image's lower-left corner.
This means that:
- The
origin
is at the bottom-left, not the top-left - The
origin.x
andwidth
are in terms of a fraction of the entire image's width - The
origin.y
andheight
are in terms of a fraction of the entire image's height
Hopefully this diagram makes it clearer:
What you are used to | What Vision returns |
---|---|
Vision framework barcode detection region of interest not working
Just making sure, if you look at regionOfInterest
, the documentation says:
The rectangle is normalized to the dimensions of the processed image. Its origin is specified relative to the image's lower-left corner.
So the origin (0,0) is at the bottom left. With your current CGRect,
CGRect(x: 0.1,
y: 0.4,
width: 0.9,
height: 0.6)
you are getting the expected result - "If the bar code is inside the blue area and at any point above that, including anywhere on the area at the top of the blue area, it will detect."
All you need to do is change the height from 0.6
to 0.2
. You will want:
barcodeRequest.regionOfInterest = CGRect(x: 0.1,
y: 0.4,
width: 0.9,
height: 0.2) /// your height is wrong
Related Topics
My Swift 4 Uiscrollview with Autolayout Constraints Is Not Scrolling
Swiftui Generic Pull to Refresh View
Programmatically Go Back to Previous Viewcontroller in Swift
iPhone Sdk Internet Connection Detection
iOS - 'Myproject-Swift.H' File Not Found When Running Unit Tests for Swift
How to Dismiss the iOS Keyboard
How to Get Animated Polyline Route in Gmsmapview, So That It Move Along with Map When Map Is Moved
How to Disable Afnetworking Cache
Mfmailcomposeviewcontroller in iOS 7 Statusbar Are Black
How to Keep Uiswitch State When Changing Viewcontrollers
Application Not Automatically Launching in Device and Getting Error on Xcode
Run iPhone as an Ibeacon in the Background
Certificate Has Either Expired or Has Been Revoked
iOS Is It a Static or a Dynamic Framework
Navigation Pop View When Swipe Right Like Instagram iPhone App.How I Achieve This
Using Uipageviewcontroller with Swift and Multiple View Controllers