我是图像处理和开发的新手.我有一个图像的像素坐标.通过连接每个坐标可以得到一个三角形.我想提取给定坐标(三角形内的像素)的像素内的像素
坐标如下.
1(x,y) -> (146 , 548)
2(x,y) -> (155, 548)
3(x,y) -> (149.6 , 558.1)
Run Code Online (Sandbox Code Playgroud)
如何拍摄上面坐标入站的像素.任何帮助表示赞赏.谢谢.
您应该在图像上应用蒙版.
示例代码:
首先你应该加载你的图像:
//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)
结果:
这就是你要找的东西吗?
| 归档时间: |
|
| 查看次数: |
90 次 |
| 最近记录: |