【发布时间】:2014-08-20 13:42:00
【问题描述】:
我有一个图像(24 位 bmp),如下所示:
用户使用鼠标绘制一条线(此处以红色显示)。这条线可以是任何角度的任何地方。然后他单击鼠标右键或鼠标左键,图像的像素值将被存储在一个文件中,并显示在控制台上。
我使用setMouseCallback() 来显示鼠标的位置(如下所示)。但是我需要更多帮助来理解一种优雅的方式来查找和存储跨行的像素值。请帮忙!
void CallBackFunc(int event, int x, int y, int flags, void* userdata)
{
if ( event == EVENT_LBUTTONDOWN )
{
cout << "Left button of the mouse is clicked - position (" << x << ", " << y << ")" << endl;
}
else if ( event == EVENT_RBUTTONDOWN )
{
cout << "Right button of the mouse is clicked - position (" << x << ", " << y << ")" << endl;
}
else if ( event == EVENT_MOUSEMOVE )
{
cout << "Mouse move over the window - position (" << x << ", " << y << ")" << endl;
}
}
int main(int argc, char** argv)
{
Mat img = imread("C:\\Users\\Acme\\Desktop\\image-processing\\2.bmp");
namedWindow(" Window", 1);
setMouseCallback(" Window", CallBackFunc, NULL);
imshow(" Window", img);
waitKey(0);
return 0;
}
【问题讨论】:
-
那么有什么问题,比如用直线方程计算直线经过的像素?
-
你不能用线条作为输入图像的掩码吗?
-
我会按照 berak 的建议使用行迭代器。使用掩码还没有给出任何命令,我猜构造线迭代将与绘制线一样复杂(如果两种算法都使用 bresenham 线算法)。
-
@Micka 正在尝试使用迭代器,但我遇到了错误Trying to understand the usage of Lineiterator
标签: c++ c opencv image-processing