Extend cvRect manually

asked 2014-05-11 12:59:32 -0600

Luek gravatar image

I am finding the text on business cards and sometimes the bounding box cuts off a part of a letter. How can I go through each Rect and make it just slightly bigger?

Given a vector of Rects how could I extend the x and y?

image description

edit retag flag offensive close merge delete

Comments

1

please, use the c++ api (cv::Rect), not the outdated c-api (cvRect)

but basically, if you want to extend your rect by Z pixels, you subtract Z from x,y, and add 2*Z to w and h

cv::Rect r; // original
cv::Rect extended( r.x-Z, r.y-Z, r.width+2*Z, r.height+2*Z);

also, don't forget to check, if your extended Rect is still within the image's boundaries !!

(btw, that card looks like taken straight from 'american psycho'...)

berak gravatar imageberak ( 2014-05-11 13:06:21 -0600 )edit

How do I check if the rect is within the image boundaries?

Luek gravatar imageLuek ( 2014-05-11 17:01:58 -0600 )edit

@Luek, just check if extended.x and extended.y are positive and smaller than your card dimensions...

StevenPuttemans gravatar imageStevenPuttemans ( 2014-05-12 02:23:08 -0600 )edit
1

... and x+r.width+2Z and y+r.height+2Z are smaller than your card dimensions...

berak gravatar imageberak ( 2014-05-12 02:26:36 -0600 )edit