System information (version)
- OpenCV => 4.5.2
- Operating System / Platform => Ubuntu 20.04.2 / x86_64
- Compiler => g++ 9.3
Detailed description
I have found that by using OpenCV's mouse callback function in high GUI module with GTK backend I can access pixels who's coordinate is out of range of image.
For example I can access pixel 500 or 333 despite image size is 500x333 and accessible area should be 0-499 for width and 0-332 for height.
When reproducing it with QT backend, this issue did not happen(can not access 500 or 333 in above example).
Steps to reproduce
- reading an image and click border of an image with mouse
- get and output clicked pixel coordinates using mouse callback function
Please change input image path in below code
test.cpp
#include <opencv2/opencv.hpp>
#include <opencv2/highgui.hpp>
void onMouse(int action, int x, int y, int flags, void *userdata)
{
// Action to be taken when left mouse button is clicked
if( action == cv::EVENT_LBUTTONDOWN )
{
std::cout << "Clicked position: " << cv::Point(x,y) << std::endl;
}
}
int main(){
cv::Mat input = cv::imread("../test.png");
std::cout << "Image size: " << input.size() << std::endl;
cv::namedWindow("test");
cv::setMouseCallback("test", onMouse); // set callback function
cv::imshow("test", input);
while(cv::waitKey() != 27){}
cv::destroyAllWindows();
return 0;
}
And this is my tested output with this code.
I emphasized issues with bold and italic.
Image size: [500 x 333]
Clicked position: [500, 198]
Clicked position: [0, 99]
Clicked position: [321, 0]
Clicked position: [367, 333]
Issue submission checklist
System information (version)
Detailed description
I have found that by using OpenCV's mouse callback function in high GUI module with GTK backend I can access pixels who's coordinate is out of range of image.
For example I can access pixel 500 or 333 despite image size is 500x333 and accessible area should be 0-499 for width and 0-332 for height.
When reproducing it with QT backend, this issue did not happen(can not access 500 or 333 in above example).
Steps to reproduce
Please change input image path in below code
And this is my tested output with this code.
I emphasized issues with bold and italic.
Issue submission checklist
forum.opencv.org, Stack Overflow, etc and have not found solution