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 findContours
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, findContours
will be erroneous sometimes.
What i am doing now is, to show the user what findContours
has detected in a Qt Window, and decide if it has detected correctly. If it has detected correctly, the user will press Ok
button, if not No, Let me select
button will be pressed.
When ever the user pressed No, Let me select
, the application will start capturing mouseEvent
and displays a rectangle using QRubberBand
. I am using QLabel
to display the image, since my screen size is 1920x1080
, i have to resize the image to some resolution( lets say 1537x1280, so that it leaves some space for buttons).
I am using opencv resize
to resize the image.
width = myImageDisplayer.width()
height = myImageDisplayer.height()
resizedImage = cv2.resize(myImage,(height,width),cv2.INTER_LINEAR)
I am using ratios to calculate the size reduction like this(
xReduction = originalImage.rows()/resizedImage.rows()
yReduction = originalImage.cols()/resizedImage.cols()
, and multiplying the event.pos()
coordinates with the ratios to get correct coordinates in the original image.
xrealCoordinates = event.pos().x()*xReduction
yrealCoordinates = event.pos().y()*yReduction
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.
Precision is important since i need to recalculate the principal coordinates(calculated by calibrating the stereo setup)
after selecting ROI from the images.
How does Opencv calculates original image coordinates correctly after resizing?
I observed it when i opened the same image using imshow
, and if i drag my mouse i can see original image coordinates, even though the image has been resized to fit the screen.
If anybody can help me in this issue, i will be thankful.