ɯɐɹʞ
ɯɐɹʞ

Reputation: 1068

VNImageBasedRequest regionOfInterest not within normalized bounds

I am attempting to access specific sections of an image to perform a VNCoreMLRequest on user defined areas of the image. I am getting errors for certain regions of interest while others are just fine. Each region is normalized.

The following two areas work:

regionOfInterest    CGRect  (origin = (x = 0.49538024164889838, y = 0.31979695431472077), size = (width = 0.26865671641791045, height = 0.24492385786802032))

regionOfInterest    CGRect  (origin = (x = 0.13290689410092396, y = 0.28807106598984761), size = (width = 0.24733475479744135, height = 0.19416243654822332))

But the two following areas don't work:

regionOfInterest    CGRect  (origin = (x = 0.15422885572139303, y = 0.87563451776649747), size = (width = 0.29992892679459843, height = 0.32106598984771573))

Error message: "The region of interest [0.148543, 0.874365, 0.319829, 0.31599] is not within the normalized bounds of [0 0 1 1]"

regionOfInterest    CGRect  (origin = (x = 0.57640369580668083, y = 0.90862944162436543), size = (width = 0.24307036247334754, height = 0.36928934010152287))

Could someone point out what I am not seeing? Maybe there is something I am not understanding about the regionOfInterest

Upvotes: 3

Views: 1361

Answers (1)

Michal Rogowski
Michal Rogowski

Reputation: 431

it's because your y + height > 1, so region of interest is bigger than image. I'm using something like

        let x = max((regionOfIntres.origin.x - 0.1), 0)
        let y = max((regionOfIntres.origin.y - 0.1), 0)

        let width = min((regionOfIntres.size.width + 0.2), (1 - x))
        let height = min((regionOfIntres.size.height + 0.2), (1 - y))

Upvotes: 2

Related Questions