hotdogee / solar-eclipse-timelapse-aligner

This specialized program is used to align and stabilize solar eclipse time-lapse photos.
MIT License
16 stars 4 forks source link

OpenCV error: assertion failed radius >= 0 && thickness <= MAX_THICKNESS && 0 <= shift && shift <= XY_SHIFT in function 'circle' #4

Open patitsas opened 5 months ago

patitsas commented 5 months ago

Hi there! I've got a bunch of photos from today's eclipse I'd like to centre and crop and turn into a time lapse. I was moving my camera's tripod manually during the eclipse so just plunking everything into ffmpeg is pretty jerky.

Unfortunately, when I run the code from this project I get the following error:

python eclipse-aligner.py --input=timelapse/ --sun=timelapse/DSC05852.JPG
INFO: 84 images found in /home/patitsas/Downloads/solar-eclipse-timelapse-aligner-master/timelapse
INFO: Detected image size (height, width): (3648, 5472)
INFO: Detected SUN RADIUS: 0
Traceback (most recent call last):
  File "/home/patitsas/Downloads/solar-eclipse-timelapse-aligner-master/eclipse-aligner.py", line 403, in <module>
    _ = cv2.circle(sun_mask, (sun_mask_r, sun_mask_r), sun_mask_r - 50, 0.0, -1)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
cv2.error: OpenCV(4.9.0) /io/opencv/modules/imgproc/src/drawing.cpp:1921: error: (-215:Assertion failed) radius >= 0 && thickness <= MAX_THICKNESS && 0 <= shift && shift <= XY_SHIFT in function 'circle'

I've tried running it on a few different subsets of my eclipse photos with the same error. I've also tried picking different sun photos for the sun parameter, same error.

If helpful, a subset of the photos I'm working with, including DSC05852 are here: https://www.flickr.com/photos/patitsas/albums/72177720316092556/

I'm running Python 3.12.2 on Fedora 39 (6.7.5-200.fc39.x86_64)

Thanks!

patitsas commented 5 months ago

I wound up doing some debugging on this. In the case above, the issue was the sun radius was not being calculated correctly, and I resolved it by manually calculating the sun radius (which was 142 pixels).

Playing around with the code more, I discovered this error message can also arise if the sun radius is less than 50 pixels. So if anybody is getting this error message and you have photos where the sun is not very wide, you'll need to resize your pictures.

starfriend10 commented 5 months ago

Same issue:

INFO: 42 images found in D:\Astronomy\20240408 Solar Eclipse\tests INFO: Detected image size (height, width): (3456, 5184) INFO: Detected SUN RADIUS: 2 Traceback (most recent call last): File "eclipse-aligner.py", line 403, in cv2.error: OpenCV(4.3.0) C:\projects\opencv-python\opencv\modules\imgproc\src\drawing.cpp:1866: error: (-215:Assertion failed) radius >= 0 && thickness <= MAX_THICKNESS && 0 <= shift && shift <= XY_SHIFT in function 'cv::circle'

[8676] Failed to execute script eclipse-aligner

It looks like the SUN RADIUS is not correctly detected? The example is "1210".

starfriend10 commented 5 months ago

I wound up doing some debugging on this. In the case above, the issue was the sun radius was not being calculated correctly, and I resolved it by manually calculating the sun radius (which was 142 pixels).

Playing around with the code more, I discovered this error message can also arise if the sun radius is less than 50 pixels. So if anybody is getting this error message and you have photos where the sun is not very wide, you'll need to resize your pictures.

Yes, I found it out, we have to first resize the image before the detection. It seems that our image size or resolution is too big for the program detecting. After reducing the size, it is able to proceed the processes. The fine-tuning is necessary, especially I have some images that the sun partially covered by cloud, so multiple times are needed to perfect detect the sun.

starfriend10 commented 5 months ago

I wound up doing some debugging on this. In the case above, the issue was the sun radius was not being calculated correctly, and I resolved it by manually calculating the sun radius (which was 142 pixels).

Playing around with the code more, I discovered this error message can also arise if the sun radius is less than 50 pixels. So if anybody is getting this error message and you have photos where the sun is not very wide, you'll need to resize your pictures.

After several trails, it turns out that resizing is not always necessary, but we have to set the sun radius manually.