【问题标题】:Detect partial circles in an image using python and opencv [closed]使用python和opencv检测图像中的部分圆圈[关闭]
【发布时间】:2014-10-24 07:36:03
【问题描述】:

我今天拍摄了大约 220 张日偏食的图像,并计划制作该事件的延时动画。正如预期的那样,部分黯然失色的太阳的图像有点跳跃,我需要在制作动画之前注册镜头。

以下是样张照片:

http://www.trivalleystargazers.org/gert/sofi_141023/sofi.htm

我想将图像放在太阳的中心,这在日食期间显然是圆的一部分。我猜月球会分散算法的注意力(我不想以月球为中心)。我对 Python 有一些了解,对 opencv 没有。

有没有一种简单的方法可以在图像中找到太阳并将其居中设置为大约。 1像素精度? opencv + python 是正确的方法吗?是否有特别的技巧可以达到最佳效果?

感谢和晴朗的天空, 格特

【问题讨论】:

  • 你能尝试用 HoughCircle 方法检测圆圈吗?也许您可以选择最大/最中心的圆作为启发式方法,而不是明确解决“半圆”部分。
  • 我想在这种情况下手动执行此操作会节省您的时间。

标签: python opencv


【解决方案1】:

你可以试试这个:

  • 图像阈值
  • 得到最大的轮廓
  • 找到包围此轮廓的最小面积圆

找到中心和半径后,注册会更容易。如果快照之间的半径不同,则必须将所有圆调整为预定义的大小,并在注册阶段相应地调整中心。

我在 OpenCV 和 C++ 中试过这个。

    Mat im = imread(INPUT_FOLDER_PATH + string("SoFi_400_20141023_163450.jpg"));

    Mat gray;
    cvtColor(im, gray, CV_BGR2GRAY);

    Mat bw;
    threshold(gray, bw, 0, 255, CV_THRESH_BINARY|CV_THRESH_OTSU);

    vector<vector<Point>> contours;
    vector<Vec4i> hierarchy;
    findContours(bw, contours, hierarchy, CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE, Point(0, 0));
    /* in actual implementation you'll have to find the largest contour. 
    here i'm just assuming i get one and it's the largest*/
    for(int idx = 0; idx >= 0; idx = hierarchy[idx][0])
    {
        Point2f center;
        float radius;
        minEnclosingCircle(contours[idx], center, radius);
        cout << idx << " (" << center.x << ", " << center.y << ") : " << radius << endl;

        circle(im, Point(center.x, center.y), radius, Scalar(0, 255, 255), 2);
    }

    imshow("", im);
    waitKey();

一些结果:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-08-02
    • 2011-12-25
    • 2023-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多