当鼠标单击事件在图像上发生时,从320 * 240图像(emgu opencv的图像)中选择像素颜色. [英] picking pixel color from 320*240 image (of emgu opencv) as mouse click event occurs on the image.
问题描述
我正在emgu opencv上进行颜色检测.我有320 * 240尺寸的图像,并且我希望程序开始检测与通过鼠标单击事件选择的图像中的像素相同的颜色.我使用过MousePosition.X;(Y),但是它返回相对于屏幕的坐标,但是我需要的是相对于图像的光标位置,即当它进入imagebox时,它应返回的值应为320 * 240尺寸的屏幕.
或者换句话说,我需要不大于x:320,y:240的坐标.否则我得到空异常错误.请帮忙.
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.
推荐答案
您很可能必须处理类似的内容
You will most likely have to process something like this
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
));
}
这篇关于当鼠标单击事件在图像上发生时,从320 * 240图像(emgu opencv的图像)中选择像素颜色.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!