AllskyTeam / allsky

A Raspberry Pi operated Wireless Allsky Camera
MIT License
1.19k stars 180 forks source link

keogram and startrails fail with images of different channels #734

Closed EricClaeys closed 2 years ago

EricClaeys commented 3 years ago

The keogram program failed with the following error when the day's images directory had both color and mono images. It's interesting that it didn't display any messages about different number of channels.

Also, keogram sets the verbose level to ALLSKY_DEBUG_LEVEL; I suggest not doing this since config.sh has KEOGRAM_EXTRA_PARAMETERS which people can use to set the keogram verbosity level.

Oct 26 07:12:07 allsky allsky.sh[24520]: [309/1223] /home/pi/allsky/images/20211025//image-20211025152621.jpg
Oct 26 07:12:07 allsky allsky.sh[24520]: OpenCV Error: Assertion failed (channels() == CV_MAT_CN(dtype)) in copyTo, file /build/opencv-L65chJ/opencv-3.2.0+dfsg/modules/core/src/copy.cpp, line 259
Oct 26 07:12:07 allsky allsky.sh[24520]: terminate called after throwing an instance of 'cv::Exception'
Oct 26 07:12:07 allsky allsky.sh[24520]:   what():  /build/opencv-L65chJ/opencv-3.2.0+dfsg/modules/core/src/copy.cpp:259: error: (-215) channels() == CV_MAT_CN(dtype) in function copyTo
ckuethe commented 3 years ago

Can you stick that set of images somewhere that I can get to it (or a representative sample?

EricClaeys commented 3 years ago

@ckuethe. Attached is a file that contains 4 pictures that cause the CV error. Removing any one of the files doesn't produce the error, but does produce the negative file numbers below:

===== Generating Keogram
thread 1/4 processing files 0--1 (0/3)
thread 2/4 processing files 0--1 (0/3)
thread 3/4 processing files 0--1 (0/3)
thread 4/4 processing files 0-2 (3/3)
[1/3] /home/pi/allsky/images/test/image-20211025182643.jpg
thread 3 initialized accumulator
[2/3] /home/pi/allsky/images/test/image-20211025182941.jpg
repairing channel mismatch: 3 != 1
[3/3] /home/pi/allsky/images/test/image-20211025183212.jpg
repairing channel mismatch: 3 != 1
Completed

With 4 images the file numbers are correct but it produces the error:

===== Generating Keogram
thread 1/4 processing files 0-0 (1/4)
[1/4] /home/pi/allsky/images/test/image-20211025182643.jpg
thread 2/4 processing files 1-1 (1/4)
[2/4] /home/pi/allsky/images/test/image-20211025182710.jpg
thread 3/4 processing files 2-2 (1/4)
[3/4] /home/pi/allsky/images/test/image-20211025182941.jpg
thread 4/4 processing files 3-3 (1/4)
[4/4] /home/pi/allsky/images/test/image-20211025183212.jpg
thread 0 initialized accumulator
OpenCV Error: Assertion failed (channels() == CV_MAT_CN(dtype)) in copyTo, file /build/opencv-L65chJ/opencv-3.2.0+dfsg/modules/core/src/copy.cpp, line 259

Note that with 3 files, 2 of them gave the "repairing channel" error, but with 4 files NONE of them gave the error. That's probably a hint as to where the error is in the code. Also note that the first file has the histogram box and the others don't. Perhaps capture.cpp is creating mono images with the histogram box as 3 channel.

Keogram crash - 4 images.zip

EricClaeys commented 3 years ago

@ckuethe, BTW, the same thing happens with the startrails command and these 4 images. Interestingly, the bit depth of the image with the histogram box is 8 whereas the other 3 images have a bit depth of 24, even though the image type is ASI_IMG_RAW8.

ckuethe commented 3 years ago

Each worker will get int(n_images / n_threads) images to process. The last worker will get n_images % n_threads extra images. I'll think about tidying up the thread assignment message.

Both the channel conversion logic and worker assignment is the same between keogram and startrail so it's not surprising that you're seeing the same thing.

I'm starting to think that anything other than 3 channels is a bad idea.... Thanks for the repro images.

EricClaeys commented 2 years ago

The latest allsky/src/keogram.cpp fixes the original issue posted. The same issue exists in allsky/src/startrails.cpp, and will be fixed soon.