本文介绍了如何裁剪圆形(找到与霍夫变换)在OpenCV?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用使用遮罩来检索圆圈内的图像部分,然后您可以
You should use copyTo with a mask to retrieve the part of image inside the circle, and then you can crop according to the bounding box of the circle.
您可以使用。
这个小例子可以让你开始。
This small example should get you started.
#include "opencv2/opencv.hpp"
using namespace cv;
int main()
{
// Your initial image
Mat3b img = imread("path_to_image");
// Your Hough circle
Vec3f circ(100,50,30); // Some dummy values for now
// Draw the mask: white circle on black background
Mat1b mask(img.size(), uchar(0));
circle(mask, Point(circ[0], circ[1]), circ[2], Scalar(255), CV_FILLED);
// Compute the bounding box
Rect bbox(circ[0] - circ[2], circ[1] - circ[2], 2 * circ[2], 2 * circ[2]);
// Create a black image
Mat3b res(img.size(), Vec3b(0,0,0));
// Copy only the image under the white circle to black image
img.copyTo(res, mask);
// Crop according to the roi
res = res(bbox);
// Save the image
imwrite("filename.png", res);
// Show your result
imshow("Result", res);
waitKey();
return 0;
}
这篇关于如何裁剪圆形(找到与霍夫变换)在OpenCV?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!