Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
patitsas opened this issue Apr 9, 2024 · 4 comments

Comments

@patitsas
Copy link

patitsas commented Apr 9, 2024

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
Copy link
Author

patitsas commented Apr 9, 2024

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
Copy link

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
Copy link

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
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants