如何翻译轮廓形象在OpenCV中的中心?轮廓、形象、中心、OpenCV

由网友(不忘初衷丶)分享简介:我工作在android系统的图像处理项目。目前,我的任务是提取对象,并将其转换为图像的中心,这样我可以从它很容易提取特征。我已经提取的对象,现在我想将其转换为图像的中心和旋转,水平对齐它在图像上。I am working on an image processing project in android. Curre...

我工作在android系统的图像处理项目。目前,我的任务是提取对象,并将其转换为图像的中心,这样我可以从它很容易提取特征。我已经提取的对象,现在我想将其转换为图像的中心和旋转,水平对齐它在图像上。

I am working on an image processing project in android. Currently my task is to extract the object and translate it to the center of the image so that i can extract features from it easily. I have extracted the object, Now i want to translate it to the center of image and rotate it, to align it horizontally on the image.

我使用Android中的图像处理的OpenCV。任何帮助是非常AP preciated。谢谢

I am using OpenCV for image processing in Android. Any help is highly appreciated. Thanks

推荐答案

我建议以下技术。

矢量<&点GT;轮廓 - OpenCV的轮廓点的向量。这样你就可以通过你想要的距离翻译。因此,在C ++中我会做以下轮廓翻译

vector<point>contour -- opencv contours are vector of points. so you can translate them by the distance you want. So in c++ i would do the following to translate the contour

void shifcontour(vector<Point>& contour, int x, int y)
{
    for (size_t i=0; i<contour.size(); i++)
    {
        contour[i].x += x;
        contour[i].y += y;
    }
}

找到x和y,则可以使用该图像的中心与中心的轮廓之间的差别。可以使用fitEllipse来计算轮廓的中心。这将使你粗略的估计您的轮廓的中心。你也将获得其中的轮廓被定向的角度。

to find xand y, you can use the difference between the centre of the image and centre of the contour. you can use fitEllipse to calculate centre of the contour. that will give you rough approximation to the centre of your contour. also you will get the angle in which contour is directed..

(x_centre,y_centre),(majoraxis,minoraxis),angle = cv2.fitEllipse(contour)

现在你的轮廓正在翻译。接下来,您必须将其旋转,水平对齐它。您可以使用的OpenCV提供的仿射穿越 - 由指定的角度旋转图像。

Now your contour is being translated. next you have to rotate it, to align it horizontally. you can use affine tranformation provided by opencv to rotate the image by specified angle.

的http://docs.opencv.org/doc/tutorials/imgproc/imgtrans/warp_affine/warp_affine.html

希望这有助于。

阅读全文

相关推荐

最新文章