1

I have been trying to place a marker at the mouse location on an image when the user clicks on the image box, the problem is that the marker has a certain offset which is exponential, and I think it's because the image size is not equal to the image box size. I also want to place the marker after zooming in on the image.

This is a windows forms project and it uses emgucv, OpenCV, and c++/cli.

Note I place the marker using an OpenCV function by passing the mouse click coordinates.

Can anyone please help?.

GHOST
  • 21
  • 2
  • 1
    [This post](https://stackoverflow.com/a/38977660/3110834) may help. It handles click event on picture box, then convert the location to a point on the image. – Reza Aghaei Mar 01 '21 at 19:48

2 Answers2

1

I found the solution in this article https://www.codeproject.com/Articles/20923/Mouse-Position-over-Image-in-a-PictureBox you need to translate the PictureBox coordinates to image coordinates however, it depends on the size mode of the PictureBox.

GHOST
  • 21
  • 2
0

I found a simple way to get mouse click coordinates with respect to a image coordinate when using ImageBox (add Emgu.CV.UI via Nuget). Add MouseClick event to your ImageBox and put that subroutine as below

private void imageBox1_MouseClick(object sender, MouseEventArgs e)
    {
        var ib = (ImageBox)sender;
        var x_offset = ib.HorizontalScrollBar.Value;
        var y_offset = ib.VerticalScrollBar.Value;
        var x = e.Location.X;
        var y = e.Location.Y;
        var zoom = ib.ZoomScale;
        int X = (int)((x / zoom) + x_offset);
        int Y = (int)((y / zoom) + y_offset);

        //MessageBox.Show(String.Format("{0}, {1}", X, Y));
        
    }