@@ -89,6 +89,7 @@ def __init__(
8989 self .name = 'Image-{0:d}' .format (idx )
9090
9191 self .config = config
92+
9293 self .error_q = error_q
9394 self .image_q = image_q
9495 self .upload_q = upload_q
@@ -140,12 +141,15 @@ def __init__(
140141
141142 self .filename_t = 'ccd{0:d}_{1:s}.{2:s}'
142143
144+ self .generate_mask_base = True
145+
143146 self .target_adu_found = False
144147 self .current_adu_target = 0
145148 self .hist_adu = []
146149
147150 self .sqm_value = 0
148151
152+ self .image_count = 0
149153 self .metadata_count = 0
150154
151155 self .image_processor = ImageProcessor (
@@ -340,6 +344,9 @@ def processImage(self, i_dict):
340344 filename_p .unlink () # original file is no longer needed
341345
342346
347+ self .image_count += 1
348+
349+
343350 # use original value if not defined
344351 libcamera_black_level = image_data .get ('libcamera_black_level' , libcamera_black_level )
345352
@@ -494,6 +501,28 @@ def processImage(self, i_dict):
494501 adu , adu_average = self .calculate_exposure (adu , exposure )
495502
496503
504+ # generate a new mask base once the target ADU is found
505+ # this should only only fire once per restart
506+ if self .generate_mask_base and self .target_adu_found :
507+ self .generate_mask_base = False
508+ self .write_mask_base_img (self .image_processor .image )
509+
510+
511+ # line detection
512+ if self .night_v .value and self .config .get ('DETECT_METEORS' ):
513+ self .image_processor .detectLines ()
514+
515+
516+ # star detection
517+ if self .night_v .value and self .config .get ('DETECT_STARS' , True ):
518+ self .image_processor .detectStars ()
519+
520+
521+ # additional draw code
522+ if self .config .get ('DETECT_DRAW' ):
523+ self .image_processor .drawDetections ()
524+
525+
497526 if self .config .get ('IMAGE_ROTATE' ):
498527 self .image_processor .rotate_90 ()
499528
@@ -512,21 +541,6 @@ def processImage(self, i_dict):
512541 self .image_processor .flip_h ()
513542
514543
515- # line detection
516- if self .night_v .value and self .config .get ('DETECT_METEORS' ):
517- self .image_processor .detectLines ()
518-
519-
520- # star detection
521- if self .night_v .value and self .config .get ('DETECT_STARS' , True ):
522- self .image_processor .detectStars ()
523-
524-
525- # additional draw code
526- if self .config .get ('DETECT_DRAW' ):
527- self .image_processor .drawDetections ()
528-
529-
530544 # crop
531545 if self .config .get ('IMAGE_CROP_ROI' ):
532546 self .image_processor .crop_image ()
@@ -1127,6 +1141,31 @@ def export_raw_image(self, i_ref, jpeg_exif=None):
11271141 self ._miscUpload .s3_upload_raw (raw_entry , raw_metadata )
11281142
11291143
1144+ def write_mask_base_img (self , data ):
1145+ logger .info ('Generating new mask base' )
1146+ f_tmpfile = tempfile .NamedTemporaryFile (mode = 'w+b' , delete = False , suffix = '.png' )
1147+ f_tmpfile .close ()
1148+
1149+ tmpfile_name = Path (f_tmpfile .name )
1150+
1151+
1152+ cv2 .imwrite (str (tmpfile_name ), data , [cv2 .IMWRITE_PNG_COMPRESSION , self .config ['IMAGE_FILE_COMPRESSION' ]['png' ]])
1153+
1154+ mask_file = self .image_dir .joinpath ('mask_base.png' )
1155+
1156+ try :
1157+ mask_file .unlink ()
1158+ except FileNotFoundError :
1159+ pass
1160+
1161+
1162+ shutil .copy2 (str (tmpfile_name ), str (mask_file ))
1163+ mask_file .chmod (0o644 )
1164+
1165+
1166+ tmpfile_name .unlink ()
1167+
1168+
11301169 def write_img (self , data , i_ref , camera , jpeg_exif = None ):
11311170 f_tmpfile = tempfile .NamedTemporaryFile (mode = 'w+b' , delete = False , suffix = '.{0}' .format (self .config ['IMAGE_FILE_TYPE' ]))
11321171 f_tmpfile .close ()
0 commit comments