opencv 展开曲面

xriantvc  于 12个月前  发布在  其他
关注(0)|答案(2)|浏览(153)

我有一个圆柱形物体,上面粘贴了一个圆形标签。我提取图像的轮廓。x1c 0d1x
我知道圆柱体的半径和标号,但并不是每次得到的椭圆都是对称的,如何将椭圆展开成圆呢?
这是一个不对称的图像

已编辑我试图扩展@Haris的解决方案,类似于

我想使用一个点数组来得到一个更精确的圆,而不是仅仅4个点。但是getPerspectiveTransform不允许我有超过4个点。有更好的方法吗?

wsxa1bj1

wsxa1bj11#

所以你想把你的物体变换成最小的封闭圆,
如下图所示,将矩形转换为绿色圆形,也就是将外接矩形转换为外接圆形。

所以做下面的事情,

*图像阈值
*Find contour and calculate bounding rect and minmum enclosing circle for contour.

Mat src=imread("src.png");
 Mat thr;
 cvtColor(src,thr,CV_BGR2GRAY);
 threshold( thr, thr, 20, 255,CV_THRESH_BINARY_INV );
 bitwise_not(thr,thr);
 vector< vector <Point> > contours; // Vector for storing contour
 vector< Vec4i > hierarchy;

 Mat dst(src.rows,src.cols,CV_8UC1,Scalar::all(0)); //create destination image
 findContours( thr.clone(), contours, hierarchy,CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE ); // Find the contours in the image
 drawContours( dst,contours, 0, Scalar(255,255,255),CV_FILLED, 8, hierarchy );
 Rect R=boundingRect(contours[0]);
 Point2f center;
 float radius;
 minEnclosingCircle( (Mat)contours[0], center, radius);`

*应用warpPerspective

在这里,您需要从边界框和圆形计算变换矩阵,如

std::vector<Point2f> src_pts;
std::vector<Point2f> dst_pts;

src_pts.push_back(Point(R.x,R.y));
src_pts.push_back(Point(R.x+R.width,R.y));
src_pts.push_back(Point(R.x,R.y+R.height));
src_pts.push_back(Point(R.x+R.width,R.y+R.height));

dst_pts.push_back(Point2f(center.x-radius,center.y-radius));
dst_pts.push_back(Point2f(center.x+radius,center.y-radius));
dst_pts.push_back(Point2f(center.x-radius,center.y+radius));
dst_pts.push_back(Point2f(center.x+radius,center.y+radius));

Mat transmtx = getPerspectiveTransform(src_pts,dst_pts);

然后应用透视变换,

Mat transformed = Mat::zeros(src.rows, src.cols, CV_8UC3);
warpPerspective(src, transformed, transmtx, src.size());
imshow("transformed", transformed);

oxf4rvwz

oxf4rvwz2#

image
我一直在寻找一个解决方案,并尝试了我自己的方法,结果并不出色。我将图像投影Map到Maya中的一个圆柱体上,方向我觉得是正确的。然后我将纹理烘焙到对象上。该纹理仍然太高,但它看起来相当松散。我垂直缩小图像并将结果发布在这里。我希望有一个可以做到这一点的应用程序。

相关问题