title: Selecting ROI for high resolution images with Qt and Opencv
body: <p>I am working on a project that involves selecting an ROI from high resolution image(more like 5187x3268 like that). Right now i am using <code>findContours</code> in OpenCV to detect a round object(since hough circles is kind of slow for high res images). The problem is that due to high amount of texture on the object, <code>findContours</code> will be erroneous sometimes. </p>
  
  <p>What i am doing now is, to show the user what <code>findContours</code> has detected in a Qt Window, and decide if it has detected correctly. If it has detected correctly, the user will press <code>Ok</code> button, if not <code>No, Let me select</code> button will be pressed.</p>
  
  <p>When ever the user pressed <code>No, Let me select</code>, the application will start capturing <code>mouseEvent</code> and displays a rectangle using <code>QRubberBand</code>. I am using <code>QLabel</code> to display the image, since my screen size is <code>1920x1080</code>, i have to resize the image to some resolution( lets say 1537x1280, so that it leaves some space for buttons). 
  I am using opencv <code>resize</code> to resize the image.</p>
  
  <pre><code>width = myImageDisplayer.width()
  height = myImageDisplayer.height()
  
  resizedImage = cv2.resize(myImage,(height,width),cv2.INTER_LINEAR)
  </code></pre>
  
  <p>I am using ratios to calculate the size reduction like this(</p>
  
  <pre><code>xReduction = originalImage.rows()/resizedImage.rows()
  yReduction = originalImage.cols()/resizedImage.cols()
  </code></pre>
  
  <p>, and multiplying the <code>event.pos()</code> coordinates with the ratios to get correct coordinates in the original image.</p>
  
  <pre><code>xrealCoordinates = event.pos().x()*xReduction
  yrealCoordinates = event.pos().y()*yReduction
  </code></pre>
  
  <p>Since the coordinates will be of float, im rounding them off. The problem is in rounding off the float values, as i am losing precision in conversion. </p>
  
  <p>Precision is important since i need to recalculate the <code>principal coordinates(calculated by calibrating the stereo setup)</code>after selecting ROI from the images.</p>
  
  <p><a href="https://i.stack.imgur.com/qdjJT.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qdjJT.jpg" alt="enter image description here"></a></p>
  
  <p>How does Opencv calculates original image coordinates correctly after resizing?
  I observed it when i opened the same image using <code>imshow</code>, and if i drag my mouse i can see original image coordinates, even though the image has been resized to fit the screen.</p>
  
  <p>If anybody can help me in this issue, i will be thankful.</p>