move a rect given a new center position to it..

asked 2015-04-26 11:58:19 -0600

215 gravatar image

I seem to have a simple problem that i am not capable of solving.

I am trying to move a already existing Rect to a new position. I would have thought that this would be possible by just changing is tl() and br() parameter, but it does seem like it, since doing so doesn't change it at all.. ??

How do i move the rect such that it's center position is the coordinate i give it. about the width and the height doesn't need to be changed.

edit retag flag offensive close merge delete



Rect::tl() and Rect::br() both return a copy of the corner points, use the x and y members to move it.

berak gravatar imageberak ( 2015-04-26 12:04:24 -0600 )edit

If you are working on the one image or one frame, you can not do that at all. Because when you draw one shape such as line or rect on an image, you change the image data and you do not have a pointer to that shape or object to erase it later (such as QItem in Qt). For solve this problem, I think it's better to clone the frame in each time for drawing your rect in desire location and showing by cv::imshow.

Amin_Abouee gravatar imageAmin_Abouee ( 2015-04-26 13:27:11 -0600 )edit

The rect is used for a binary Mask which is then applied on to a image i am working on to retrieve a ROI.

215 gravatar image215 ( 2015-04-26 13:34:40 -0600 )edit