提取给定坐标内的像素

Ala*_*lan 2 c++ opencv

我是图像处理和开发的新手.我有一个图像的像素坐标.通过连接每个坐标可以得到一个三角形.我想提取给定坐标(三角形内的像素)的像素内的像素

坐标如下.

1(x,y) -> (146 , 548)
2(x,y) -> (155, 548)
3(x,y) -> (149.6 , 558.1)
Run Code Online (Sandbox Code Playgroud)

如何拍摄上面坐标入站的像素.任何帮助表示赞赏.谢谢.

zed*_*edv 5

您应该在图像上应用蒙版.

示例代码:

首先你应该加载你的图像:

//load default image
Mat image = cv::imread("/home/fabio/code/lena.jpg", cv::IMREAD_GRAYSCALE);
Run Code Online (Sandbox Code Playgroud)

默认图像已加载

然后为图像创建蒙版并将三角形点应用于蒙版.

//mask image definition
cv::Mat mask = cv::Mat::zeros(image.size(), image.type());

//triangle definition (example points)
vector<Point> points;
points.push_back( Point(100,70));
points.push_back( Point(60,150));
points.push_back( Point(190,120));

//apply triangle to mask
fillConvexPoly( mask, points, Scalar( 255 ));
Run Code Online (Sandbox Code Playgroud)

之后,你的面具将如下所示:

三角形蒙版图像

最后创建将蒙版应用于原始图像的最终图像:

//final image definition
cv::Mat finalImage = cv::Mat::zeros(image.size(), image.type());

image.copyTo(finalImage, mask);
Run Code Online (Sandbox Code Playgroud)

结果:

结果

这就是你要找的东西吗?