Detecting partial circles in an image using python and opencv

Today I took about 220 images of a partial solar eclipse and planned to assemble an animation of time for the event. As expected, the image of the partially eclipsed Sun jumps a bit, and I need to register the images before doing the animation.

Here are sample photos:

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

I would like to focus the image on the Sun, which is obviously a circle segment during the eclipse. I think the moon would be a distraction for the algorithm (I don't want to focus on the moon). I have some knowledge of Python and not on opencv.

Is there an easy way to find the sun in images and focus it on approx. 1 pixel accuracy? Is opencv + python the right approach? Are there any tricks to find the best result?

Thanks and clear the sky, Gert

+3
source share
1 answer

You can try the following:

  • image threshold
  • get the greatest contour
  • find the minimum circle circle that covers this contour

Once you find the center and radius, it will be easier to register. If the radius is different between snapshots, you will have to resize all the circles to a predetermined size and adjust the center accordingly at the registration stage.

I tried this in OpenCV and 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 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(); 

Some results:

enter image description hereenter image description here

0
source

Source: https://habr.com/ru/post/1270193/


All Articles