Bounding Box from Vndetectrectanglerequest Is Not Correct Size When Used as Child Vc

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 and width are in terms of a fraction of the entire image's width
  • The origin.y and height are in terms of a fraction of the entire image's height

Hopefully this diagram makes it clearer:















What you are used toWhat Vision returns
Sample ImageSample Image

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



Leave a reply



Submit