gpt4 book ai didi

c++ - 收集使用鼠标绘制的线条中的像素值

转载 作者:太空宇宙 更新时间:2023-11-04 08:39:24 25 4
gpt4 key购买 nike

我有一张图片(24 位 bmp),如下所示:

enter image description here

用户使用鼠标绘制一条线(此处显示为红色)。这条线可以是任何角度的任何地方。然后他点击鼠标右键或左键,跨行的图像像素值除了显示在控制台上外,还被存储在一个文件中。

我使用 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;

}

最佳答案

通过变形将线提取为 1 x (linelength) 或 (linelength) x 1,垂直或水平 Mat。然后,您可以轻松地向下或跨像素值读取。

关于c++ - 收集使用鼠标绘制的线条中的像素值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24485826/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com