Click here to Skip to main content
15,899,679 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,
i am working on color detection on emgu opencv. i have 320*240 sized image and i want program to start detecting color same as a pixel in image selected by mouse click event. i have used MousePosition.X;(Y) but it returns coordinates with respect to screen but what i need is cursor location with respect to image i-e when it enters imagebox it sh return should return value as it were in 320*240 sized screen.

or in other word i need coordinates not greater than x:320 ,y:240. otherwise i am getting null exception error. please help.
Posted
Comments
Sergey Alexandrovich Kryukov 4-Jan-12 2:55am    
Not clear. Where is a problem? What's your code which is problematic? Could you make a short sample?
--SA

1 solution

You will most likely have to process something like this
C#
public System.Drawing.Point GetPositionInImage()
{
    int locationInImageX = locationOnScreen.X - imageUpperLeftCorner.X;
    if(locationInImageX < 0)
        locationInImageX = 0;
    if(locationInImageX >= imageLowerRightCorner.X)
        locationInImageX = imageLowerRightCorner.X - 1;

    return(new System.Drawing.Point(
        locationInImageX,
        locationInImageY    // Same processing as for x-value
    ));
}
 
Share this answer
 
Comments
ssattarr 4-Jan-12 11:23am    
thanks lukeer , you got my problem. i did something similar to this and solved issue . what i am wondering if there is no direct way to do this? instead of calculations.
lukeer 5-Jan-12 8:19am    
Actually, there is a method System.Windows.Forms.Control.PointToClient(), that does the translation part (use control co-ordinates instead of desktop co-ordinates).
The range check stays for you to do.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900