使曲面变形

问题描述 投票:0回答:2

我有一个圆柱形物体,上面贴有圆形标签。我提取图像的轮廓。enter image description here

我知道圆柱形物体的半径以及标签。但并不是每次得到的椭圆都是完全对称的。如何将椭圆展开为圆形?

这是一个不对称的图像enter image description here

已编辑 我尝试扩展 @Haris 的解决方案,如下所示 enter image description here

我想使用点数组来获得更准确的圆,而不是仅仅使用 4 个点。但

getPerspectiveTransform
不允许我获得超过4分。有更好的方法吗?

opencv distortion unwarp
2个回答
1
投票

所以你想将你的对象变换为最小外接圆,

如下图所示,将簧片矩形变换为绿色圆圈。即将边界矩形变换为边界圆。

enter image description here

所以请执行以下操作,

 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);`

enter image description here

这里你需要从边界框和圆计算变换矩阵

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);

enter image description here


0
投票

image

我一直在寻找解决方案,并尝试了自己的方法,但结果并不理想。我以我认为正确的方向将图像投影到 Maya 中的圆柱体上。然后我将纹理烘焙到物体上。那个纹理仍然太高,但看起来相当未包裹。我垂直缩小了图像并将结果发布在这里。我想要一个可以做到这一点的应用程序。

© www.soinside.com 2019 - 2024. All rights reserved.