Ask Your Question

coordinates for cvRectangle

asked 2013-03-17 19:49:54 -0600

I have an image the is larger than my screen and a mouse handler that selects the corners for a call to cvRectangle. If I select a corner near 0, 0 (top left) the start of cvRectange is at or near the correct position but the further I go to the bottom right, the more the second corner is off. It looks like a scaling issue between the image that is 1980x1080 and the screen that is 1366x768. How can I get the correct coordinates rom the image so that the call to cvRectange produces the correct rectange Ian

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2013-03-18 09:58:09 -0600

The mousehandlers assigned to a namedWindow only work correct as long as the window is not larger than your main monitor. To solve your problem there are two possible solutions.

  1. Rescale images if they are over your screens resolution. Then use the scale factor to calculate the actual dimensions.
  2. Cut down your image into patches and just assing a storage of current point into a temp variable when clicking the image. Then use the two points to define the rectangle.

In order to split a givin image easily use:

Mat window = image( Rect(xWindow,yWindow,widthWindow,heigthWindow) );
edit flag offensive delete link more

Question Tools


Asked: 2013-03-17 19:49:54 -0600

Seen: 334 times

Last updated: Mar 18 '13