pogucam 0.1.4__py3-none-any.whl → 0.1.6__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pogucam/buffers.py +157 -0
- pogucam/explore_u24_uni.py +90 -234
- {pogucam-0.1.4.dist-info → pogucam-0.1.6.dist-info}/METADATA +1 -1
- pogucam-0.1.6.dist-info/RECORD +9 -0
- pogucam-0.1.6.dist-info/entry_points.txt +2 -0
- pogucam-0.1.4.dist-info/RECORD +0 -8
- pogucam-0.1.4.dist-info/entry_points.txt +0 -2
- {pogucam-0.1.4.dist-info → pogucam-0.1.6.dist-info}/WHEEL +0 -0
pogucam/buffers.py
ADDED
@@ -0,0 +1,157 @@
|
|
1
|
+
|
2
|
+
import numpy as np
|
3
|
+
# ================================================================================
|
4
|
+
# jsut store uint +info
|
5
|
+
# --------------------------------------------------------------------------------
|
6
|
+
|
7
|
+
class FastAccumBuffer:
|
8
|
+
def __init__(self, max_frames, shape=(640, 480, 3)):
|
9
|
+
self.max_frames = max_frames
|
10
|
+
self.shape = shape
|
11
|
+
self._init_buffer()
|
12
|
+
self._last_retrieved_idx = -1 #???
|
13
|
+
|
14
|
+
def _init_buffer(self):
|
15
|
+
self.cube = np.empty((self.max_frames, *self.shape), dtype=np.uint8)
|
16
|
+
self.info = [None] * self.max_frames
|
17
|
+
self.idx = 0
|
18
|
+
self.count = 0
|
19
|
+
self._last_retrieved_idx = -1 #???
|
20
|
+
|
21
|
+
def add(self, img: np.ndarray, info: dict):
|
22
|
+
"""
|
23
|
+
inconsistent shape resets the buffer
|
24
|
+
"""
|
25
|
+
if img.dtype != np.uint8 or img.shape != self.shape:
|
26
|
+
self.shape = img.shape
|
27
|
+
self._init_buffer()
|
28
|
+
if self.cube.shape[0] != self.max_frames:
|
29
|
+
self._init_buffer()
|
30
|
+
self.cube[self.idx] = img
|
31
|
+
self.info[self.idx] = info
|
32
|
+
self.idx = (self.idx + 1) % self.max_frames
|
33
|
+
self.count = min(self.count + 1, self.max_frames)
|
34
|
+
|
35
|
+
def get_last_img(self):
|
36
|
+
if self.count == 0:
|
37
|
+
return None
|
38
|
+
last_idx = (self.idx - 1) % self.max_frames
|
39
|
+
return self.cube[last_idx]
|
40
|
+
|
41
|
+
def new_sum_available(self):
|
42
|
+
return self.idx == self.max_frames - 1
|
43
|
+
# True if buffer has wrapped around since last sum_images() call
|
44
|
+
if self.count < self.max_frames:
|
45
|
+
return False
|
46
|
+
return self.idx != self._last_retrieved_idx # ???
|
47
|
+
|
48
|
+
def get_sum_frames(self):
|
49
|
+
if self.count == 0:
|
50
|
+
return None
|
51
|
+
#print("!... SUM")
|
52
|
+
summed = np.sum(self.cube[:self.count].astype(np.uint16), axis=0)
|
53
|
+
np.clip(summed, 0, 255, out=summed)
|
54
|
+
self._last_retrieved_idx = self.idx # ???
|
55
|
+
return summed.astype(np.uint8)
|
56
|
+
|
57
|
+
def get_max_frames(self):
|
58
|
+
return self.max_frames
|
59
|
+
|
60
|
+
def set_max_frames(self, max_frames):
|
61
|
+
"""
|
62
|
+
reset the buffer
|
63
|
+
"""
|
64
|
+
if max_frames != self.max_frames:
|
65
|
+
self.max_frames = max_frames
|
66
|
+
self._init_buffer()
|
67
|
+
|
68
|
+
def __iter__(self):
|
69
|
+
"""
|
70
|
+
returns image,info_dict
|
71
|
+
"""
|
72
|
+
for i in range(self.count):
|
73
|
+
yield self.cube[(self.idx - self.count + i) % self.max_frames], self.info[(self.idx - self.count + i) % self.max_frames]
|
74
|
+
|
75
|
+
def __len__(self):
|
76
|
+
return self.count
|
77
|
+
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
# ==========================================================================================
|
82
|
+
# CLASS SLOW level 2 - averaging buffer.....
|
83
|
+
# ------------------------------------------------------------------------------------------
|
84
|
+
|
85
|
+
|
86
|
+
class AccumBuffer:
|
87
|
+
def __init__(self, frame=None, img_dtype=np.uint8):
|
88
|
+
self.frame = frame
|
89
|
+
self.img = type('img', (), {'dtype': img_dtype})()
|
90
|
+
self.accum_buffer_size = 0
|
91
|
+
self.accum_buffer = []
|
92
|
+
self.accum_count = 0
|
93
|
+
self.accum_index = 0
|
94
|
+
self.running_sum = None
|
95
|
+
|
96
|
+
def is_accum_index_at_end(self):
|
97
|
+
return self.accum_index >= self.accum_buffer_size - 1
|
98
|
+
|
99
|
+
def get_current_size(self):
|
100
|
+
return self.accum_count
|
101
|
+
|
102
|
+
def get_max_buffer_size(self):
|
103
|
+
return self.accum_buffer_size
|
104
|
+
|
105
|
+
def clear_buffer(self, some_frame):
|
106
|
+
self.accum_buffer = np.zeros((self.accum_buffer_size, *some_frame.shape), dtype=self.img.dtype)
|
107
|
+
self.accum_count = 0
|
108
|
+
self.accum_index = 0
|
109
|
+
self.running_sum = np.zeros(some_frame.shape, dtype=np.float64)
|
110
|
+
|
111
|
+
def get_frame_shape(self):
|
112
|
+
if self.frame is not None:
|
113
|
+
return self.frame.shape
|
114
|
+
else:
|
115
|
+
return None
|
116
|
+
|
117
|
+
def define_accum_buffer(self, n):
|
118
|
+
if self.frame is None:
|
119
|
+
return False
|
120
|
+
if (n == self.accum_buffer_size) and (len(self.accum_buffer) > 1):
|
121
|
+
return True
|
122
|
+
self.accum_buffer_size = n
|
123
|
+
self.accum_buffer = np.zeros((self.accum_buffer_size, *self.frame.shape), dtype=self.img.dtype)
|
124
|
+
self.accum_count = 0
|
125
|
+
self.accum_index = 0
|
126
|
+
self.running_sum = np.zeros(self.frame.shape, dtype=np.float64)
|
127
|
+
return True
|
128
|
+
|
129
|
+
def add_to_accum_buffer(self, frame):
|
130
|
+
if len(self.accum_buffer) < 1:
|
131
|
+
return False
|
132
|
+
if self.accum_count < self.accum_buffer_size:
|
133
|
+
self.running_sum += frame
|
134
|
+
self.accum_buffer[self.accum_index] = frame
|
135
|
+
self.accum_count += 1
|
136
|
+
else:
|
137
|
+
oldest_frame = self.accum_buffer[self.accum_index]
|
138
|
+
if frame.shape != oldest_frame.shape:
|
139
|
+
return False
|
140
|
+
self.running_sum += frame.astype(np.float64) - oldest_frame.astype(np.float64)
|
141
|
+
self.accum_buffer[self.accum_index] = frame
|
142
|
+
self.accum_index = (self.accum_index + 1) % self.accum_buffer_size
|
143
|
+
return True
|
144
|
+
|
145
|
+
def get_mean_accum_buffer(self):
|
146
|
+
if self.accum_count == 0:
|
147
|
+
return None
|
148
|
+
rimg = self.running_sum / self.accum_count
|
149
|
+
return rimg.astype(np.uint8)
|
150
|
+
|
151
|
+
def order_accum_buffer_frames(self):
|
152
|
+
if self.accum_count < self.accum_buffer_size:
|
153
|
+
frames_ordered = self.accum_buffer[:self.accum_count]
|
154
|
+
else:
|
155
|
+
frames_ordered = np.concatenate((self.accum_buffer[self.accum_index:], self.accum_buffer[:self.accum_index]))
|
156
|
+
for frame in frames_ordered:
|
157
|
+
yield frame
|
pogucam/explore_u24_uni.py
CHANGED
@@ -63,7 +63,10 @@ import base64
|
|
63
63
|
import getpass
|
64
64
|
import time
|
65
65
|
|
66
|
+
|
66
67
|
from pogucam.text_write import iprint, fonts_available, get_f_height, get_f_width, get_def_font, set_def_font
|
68
|
+
from pogucam import buffers
|
69
|
+
|
67
70
|
from console import fg, bg, fx
|
68
71
|
|
69
72
|
from astropy.io import fits
|
@@ -343,83 +346,6 @@ def crosson( frame, dix, diy, color = "g", box_small = True, box_large = False)
|
|
343
346
|
|
344
347
|
|
345
348
|
|
346
|
-
# ==========================================================================================
|
347
|
-
# CLASS
|
348
|
-
# ------------------------------------------------------------------------------------------
|
349
|
-
|
350
|
-
|
351
|
-
class AccumBuffer:
|
352
|
-
def __init__(self, frame=None, img_dtype=np.uint8):
|
353
|
-
self.frame = frame
|
354
|
-
self.img = type('img', (), {'dtype': img_dtype})()
|
355
|
-
self.accum_buffer_size = 0
|
356
|
-
self.accum_buffer = []
|
357
|
-
self.accum_count = 0
|
358
|
-
self.accum_index = 0
|
359
|
-
self.running_sum = None
|
360
|
-
|
361
|
-
def is_accum_index_at_end(self):
|
362
|
-
return self.accum_index >= self.accum_buffer_size - 1
|
363
|
-
|
364
|
-
def get_current_size(self):
|
365
|
-
return self.accum_count
|
366
|
-
|
367
|
-
def get_max_buffer_size(self):
|
368
|
-
return self.accum_buffer_size
|
369
|
-
|
370
|
-
def clear_buffer(self, some_frame):
|
371
|
-
self.accum_buffer = np.zeros((self.accum_buffer_size, *some_frame.shape), dtype=self.img.dtype)
|
372
|
-
self.accum_count = 0
|
373
|
-
self.accum_index = 0
|
374
|
-
self.running_sum = np.zeros(some_frame.shape, dtype=np.float64)
|
375
|
-
|
376
|
-
def get_frame_shape(self):
|
377
|
-
if self.frame is not None:
|
378
|
-
return self.frame.shape
|
379
|
-
else:
|
380
|
-
return None
|
381
|
-
|
382
|
-
def define_accum_buffer(self, n):
|
383
|
-
if self.frame is None:
|
384
|
-
return False
|
385
|
-
if (n == self.accum_buffer_size) and (len(self.accum_buffer) > 1):
|
386
|
-
return True
|
387
|
-
self.accum_buffer_size = n
|
388
|
-
self.accum_buffer = np.zeros((self.accum_buffer_size, *self.frame.shape), dtype=self.img.dtype)
|
389
|
-
self.accum_count = 0
|
390
|
-
self.accum_index = 0
|
391
|
-
self.running_sum = np.zeros(self.frame.shape, dtype=np.float64)
|
392
|
-
return True
|
393
|
-
|
394
|
-
def add_to_accum_buffer(self, frame):
|
395
|
-
if len(self.accum_buffer) < 1:
|
396
|
-
return False
|
397
|
-
if self.accum_count < self.accum_buffer_size:
|
398
|
-
self.running_sum += frame
|
399
|
-
self.accum_buffer[self.accum_index] = frame
|
400
|
-
self.accum_count += 1
|
401
|
-
else:
|
402
|
-
oldest_frame = self.accum_buffer[self.accum_index]
|
403
|
-
if frame.shape != oldest_frame.shape:
|
404
|
-
return False
|
405
|
-
self.running_sum += frame.astype(np.float64) - oldest_frame.astype(np.float64)
|
406
|
-
self.accum_buffer[self.accum_index] = frame
|
407
|
-
self.accum_index = (self.accum_index + 1) % self.accum_buffer_size
|
408
|
-
return True
|
409
|
-
|
410
|
-
def get_mean_accum_buffer(self):
|
411
|
-
if self.accum_count == 0:
|
412
|
-
return None
|
413
|
-
rimg = self.running_sum / self.accum_count
|
414
|
-
return rimg.astype(np.uint8)
|
415
|
-
|
416
|
-
def order_accum_buffer_frames(self):
|
417
|
-
if self.accum_count < self.accum_buffer_size:
|
418
|
-
frames_ordered = self.accum_buffer[:self.accum_count]
|
419
|
-
else:
|
420
|
-
frames_ordered = np.concatenate((self.accum_buffer[self.accum_index:], self.accum_buffer[:self.accum_index]))
|
421
|
-
for frame in frames_ordered:
|
422
|
-
yield frame
|
423
349
|
|
424
350
|
# ==========================================================================================
|
425
351
|
# CLASS
|
@@ -572,13 +498,15 @@ class StreamWidget(QLabel):
|
|
572
498
|
self.setup(action="r", number=4)
|
573
499
|
# ------------------------ capture
|
574
500
|
self.cap = None
|
575
|
-
|
576
|
-
self.
|
577
|
-
self.
|
578
|
-
self.
|
579
|
-
#
|
580
|
-
self.
|
581
|
-
|
501
|
+
# ------------------------- FastBuffer
|
502
|
+
self.FABuffer = buffers.FastAccumBuffer(1) # shape is default
|
503
|
+
#self.accum_n = 1 #
|
504
|
+
#self.accum_buffer = None #
|
505
|
+
#self.accum_image = None #
|
506
|
+
self.l_show_accum = False # THIS MUST BE KEPT
|
507
|
+
# ---- np stak-------------------------------------
|
508
|
+
#self.accum_buffer_size = 0 #
|
509
|
+
#self.accum_count = 0 # actual number of img in buff
|
582
510
|
# -------------------------------------------------
|
583
511
|
self.level2_buffer = None
|
584
512
|
self.level2_buffer_max_size = 10
|
@@ -617,15 +545,17 @@ class StreamWidget(QLabel):
|
|
617
545
|
print("X... no remote IP defined - nothing sent", data)
|
618
546
|
#--------------------------- ------------------------------------ACUUMULATE LOCALY
|
619
547
|
if ('accumtxt' in data):
|
620
|
-
val = int(data['accumtxt'])
|
548
|
+
val = int(data['accumtxt']) # SIZE OF THE BUFFER
|
621
549
|
# how to solve 0? the forgotten problem with 1 allowed here and not 0
|
622
550
|
if val == 0: val = 1 # trying to fix
|
623
|
-
if
|
624
|
-
self.
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
551
|
+
if len(self.FABuffer) != val and val > 0:
|
552
|
+
self.FABuffer.set_max_frames(val)
|
553
|
+
#if val != self.accum_n:
|
554
|
+
# self.accum_n = val
|
555
|
+
# #if val == 0: self.accum_n = val # This looks obsolete!; commenting out
|
556
|
+
# #
|
557
|
+
# ###self.accum_buffer = deque(maxlen=self.accum_n)
|
558
|
+
# self.define_accum_buffer( self.accum_n )
|
629
559
|
|
630
560
|
|
631
561
|
#-----------------------------------------------------------------SWITCHRES LOCALY
|
@@ -647,7 +577,8 @@ class StreamWidget(QLabel):
|
|
647
577
|
self.cap.set(cv2.CAP_PROP_FRAME_HEIGHT, height)
|
648
578
|
|
649
579
|
self.zoome = 1
|
650
|
-
self.
|
580
|
+
self.FABuffer.set_max_frames(1)
|
581
|
+
#self.define_accum_buffer(0 ) # RESET BUFFER
|
651
582
|
|
652
583
|
#----------------------------------------------------------
|
653
584
|
|
@@ -668,7 +599,8 @@ class StreamWidget(QLabel):
|
|
668
599
|
self.cap.set(cv2.CAP_PROP_FRAME_WIDTH, width)
|
669
600
|
self.cap.set(cv2.CAP_PROP_FRAME_HEIGHT, height)
|
670
601
|
|
671
|
-
self.define_accum_buffer(0 ) # RESET BUFFER
|
602
|
+
#self.define_accum_buffer(0 ) # RESET BUFFER
|
603
|
+
self.FABuffer.set_max_frames(1)
|
672
604
|
self.zoome = 1
|
673
605
|
|
674
606
|
#----------------------------------------------------------
|
@@ -949,10 +881,15 @@ class StreamWidget(QLabel):
|
|
949
881
|
if self.saving_fits_only:
|
950
882
|
FIT = f"FITS {self.FITS_INTERVAL_SECONDS:3d}"
|
951
883
|
|
952
|
-
|
953
|
-
|
954
|
-
|
955
|
-
|
884
|
+
# ---------------------- ACCUM
|
885
|
+
total_size = sys.getsizeof(self.FABuffer)
|
886
|
+
cur_size = len(self.FABuffer)
|
887
|
+
max_size = self.FABuffer.get_max_frames()
|
888
|
+
|
889
|
+
#if self.accum_buffer is not None:
|
890
|
+
# total_size = sys.getsizeof(self.accum_buffer) + sum(sys.getsizeof(arr) for arr in self.accum_buffer)
|
891
|
+
#BUF = f"BUF={self.accum_count:3d}/{self.accum_n:3d} {total_size/1024/1024:5.0f} MB"
|
892
|
+
BUF = f"BUF={cur_size:3d}/{max_size:3d} {total_size/1024/1024:5.0f} MB"
|
956
893
|
#
|
957
894
|
#
|
958
895
|
#
|
@@ -960,17 +897,18 @@ class StreamWidget(QLabel):
|
|
960
897
|
#
|
961
898
|
position = ( 0, self.frame.shape[0]-1 ) # 480 on x-axis
|
962
899
|
#
|
963
|
-
|
964
|
-
if self.resolution == "1920x1080":
|
965
|
-
shade_height = 20
|
966
|
-
else:
|
967
|
-
shade_height = 10
|
968
|
-
height, width = self.frame.shape[:2]
|
969
|
-
cv2.rectangle(overlay, (0, height - shade_height), (width, height), (0, 0, 0), -1)
|
970
|
-
alpha = 0.5
|
900
|
+
|
971
901
|
if blackbar:
|
972
|
-
|
973
|
-
|
902
|
+
overlay = self.frame.copy()
|
903
|
+
if self.resolution == "1920x1080":
|
904
|
+
shade_height = 20
|
905
|
+
else:
|
906
|
+
shade_height = 10
|
907
|
+
height, width = self.frame.shape[:2]
|
908
|
+
cv2.rectangle(overlay, (0, height - shade_height), (width, height), (0, 0, 0), -1)
|
909
|
+
alpha = 0.5
|
910
|
+
#alpha = 0.
|
911
|
+
cv2.addWeighted(overlay, alpha, self.frame, 1 - alpha, 0, self.frame)
|
974
912
|
#
|
975
913
|
font = "di"
|
976
914
|
if self.resolution == "1920x1080":
|
@@ -1091,7 +1029,6 @@ class StreamWidget(QLabel):
|
|
1091
1029
|
#hdu.header['DATE'] = '2025-05-12'
|
1092
1030
|
|
1093
1031
|
hdul.writeto(newfname, overwrite=True) # .gz is too expensive too
|
1094
|
-
#print(f" x {fg.red}FITS SAVED{fg.default} {newfname}", end=" ")
|
1095
1032
|
# -------------------------------------------------
|
1096
1033
|
thread = threading.Thread(target=save)
|
1097
1034
|
thread.start()
|
@@ -1126,14 +1063,13 @@ class StreamWidget(QLabel):
|
|
1126
1063
|
print(" xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ")
|
1127
1064
|
#mylst = []
|
1128
1065
|
n = 1
|
1129
|
-
for i in self.order_accum_buffer_frames(): # ITER WORKS BUT NO GREEN LABELS
|
1066
|
+
for i, info in self.FABuffer:#self.order_accum_buffer_frames(): # ITER WORKS BUT NO GREEN LABELS
|
1130
1067
|
i = np.moveaxis( i, [0, 1, 2], [1, 2, 0])
|
1131
1068
|
i = np.rot90(i, 2)
|
1132
1069
|
#mylst.append(i)
|
1133
1070
|
#data_cube3 = np.stack(mylst, axis=0)
|
1134
1071
|
self.save_fits_in_background(i, fname1, numero=n)
|
1135
1072
|
n += 1
|
1136
|
-
self.SAVED_NOW = True
|
1137
1073
|
elif dumpbuffer and (self.l_show_accum) and (use_buffer is not None): # I WILL NOT USE THIS ***********
|
1138
1074
|
print(" xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ")
|
1139
1075
|
#print("D... some way to save only one AVG image per Nbuf: TO DO!") # TODO
|
@@ -1147,30 +1083,25 @@ class StreamWidget(QLabel):
|
|
1147
1083
|
#data_cube3 = np.stack(mylst, axis=0)
|
1148
1084
|
self.save_fits_in_background(i, fname1, numero=n)
|
1149
1085
|
n += 1
|
1150
|
-
self.SAVED_NOW = True # BUFFER OF BUFFERS !!!!!!! TODO
|
1151
|
-
pass
|
1152
1086
|
elif (not dumpbuffer) and (not self.l_show_accum):
|
1153
1087
|
print("... just one foto in FITS, why not") # trivial ------- NOBUFFER
|
1154
|
-
mylast = self.accum_buffer[self.accum_index]
|
1088
|
+
mylast = self.FABuffer.get_last_img()#self.accum_buffer[self.accum_index]
|
1155
1089
|
i = np.moveaxis( mylast, [0, 1, 2], [1, 2, 0])
|
1156
1090
|
i = np.rot90(i, 2)
|
1157
1091
|
self.save_fits_in_background(i, fname1)
|
1158
|
-
self.SAVED_NOW = True
|
1159
|
-
pass
|
1160
1092
|
elif (not dumpbuffer) and (self.l_show_accum):
|
1161
1093
|
print(" ... provide average, 1 image in FITS") # trivial ------- NOBUFFER
|
1162
|
-
mymean = self.get_mean_accum_buffer()
|
1094
|
+
mymean = self.FABuffer.get_sum_frames()#get_mean_accum_buffer()
|
1163
1095
|
i = np.moveaxis( mymean, [0, 1, 2], [1, 2, 0])
|
1164
1096
|
i = np.rot90(i, 2)
|
1165
1097
|
self.save_fits_in_background(i, fname1)
|
1166
|
-
self.SAVED_NOW = True
|
1167
|
-
pass
|
1168
1098
|
# ------- JPG **** **** **** **** *** *** * * * *
|
1169
1099
|
else:# --------NOT FITS
|
1170
1100
|
if (dumpbuffer) and (not self.l_show_accum):
|
1171
1101
|
# dump buffer - straight
|
1172
1102
|
mycnt = 0
|
1173
|
-
for i in self.order_accum_buffer_frames(): # ITER WORKS BUT NO GREEN LABELS
|
1103
|
+
#for i in self.order_accum_buffer_frames(): # ITER WORKS BUT NO GREEN LABELS
|
1104
|
+
for i, info in self.FABuffer:
|
1174
1105
|
mycnt += 1
|
1175
1106
|
fff = fname1.replace(".jpg", f"_{mycnt:03d}.jpg")
|
1176
1107
|
print(fff)
|
@@ -1178,7 +1109,6 @@ class StreamWidget(QLabel):
|
|
1178
1109
|
cv2.imwrite(fff, i, [int(cv2.IMWRITE_JPEG_QUALITY), 90])
|
1179
1110
|
else:
|
1180
1111
|
cv2.imwrite(fff.replace("jpg", "png"), i )
|
1181
|
-
self.SAVED_NOW = True
|
1182
1112
|
pass
|
1183
1113
|
# -----------------------------------------------
|
1184
1114
|
elif (not dumpbuffer) and (not self.l_show_accum):
|
@@ -1187,20 +1117,14 @@ class StreamWidget(QLabel):
|
|
1187
1117
|
cv2.imwrite(fname1, self.img, [int(cv2.IMWRITE_JPEG_QUALITY), 90])
|
1188
1118
|
else:
|
1189
1119
|
cv2.imwrite(fname1.replace("jpg", "png"), self.img )
|
1190
|
-
self.SAVED_NOW = True
|
1191
|
-
pass
|
1192
1120
|
elif (dumpbuffer) and (self.l_show_accum):
|
1193
1121
|
print("D... the trickies - save every Nth-every new buffer - IDK ")
|
1194
|
-
self.SAVED_NOW = True
|
1195
|
-
pass
|
1196
1122
|
elif (not dumpbuffer) and (self.l_show_accum):
|
1197
|
-
mymean = self.get_mean_accum_buffer()
|
1123
|
+
mymean = self.FABuffer.get_sum_frames()#get_mean_accum_buffer()
|
1198
1124
|
if self.saving_jpg:
|
1199
1125
|
cv2.imwrite(fname1, mymean, [int(cv2.IMWRITE_JPEG_QUALITY), 90])
|
1200
1126
|
else:
|
1201
1127
|
cv2.imwrite(fname1.replace("jpg", "png"), mymean )
|
1202
|
-
self.SAVED_NOW = True
|
1203
|
-
pass
|
1204
1128
|
|
1205
1129
|
|
1206
1130
|
# ======================================================================
|
@@ -1559,23 +1483,7 @@ class StreamWidget(QLabel):
|
|
1559
1483
|
print(f" --- {self.frame_time} ; resolution /{self.frame.shape}/ ---- ", end="")
|
1560
1484
|
|
1561
1485
|
avg = self.frame # once per Nx it is AVG
|
1562
|
-
# -------------------------------------------- all buffer thing will go elsewhere--------------
|
1563
|
-
# if self.accum_n > 1:
|
1564
|
-
# #avg = self.frame.astype("float32")
|
1565
|
-
# if len(self.accum_buffer) == self.accum_n: # TRICK---- RESTARTED BUFFER EVERYTIME ----- EASY TO CONTROL SAVE
|
1566
|
-
# avg = np.mean(self.accum_buffer, axis=0).astype(np.uint8)
|
1567
|
-
# self.frame = avg
|
1568
|
-
# self.accum_image = avg # store for next loop
|
1569
|
-
# # I will use this for -bad-old-orientative-image AND SAVE!
|
1570
|
-
# # RESET BUFFER! count from Zero
|
1571
|
-
# self.accum_buffer = deque(maxlen=self.accum_n)
|
1572
|
-
# # I need to carefully sync saving
|
1573
|
-
# self.accum_buffer.append( self.frame.astype("float32") ) # always frame
|
1574
1486
|
self.img = avg # normally frame. but sometimes avg == really averaged img!
|
1575
|
-
# NICE.
|
1576
|
-
# I want to see accumulated....??????
|
1577
|
-
#if self.accum_image is not None and (len(self.accum_buffer) > self.accum_n / 2):
|
1578
|
-
# self.img = self.accum_image
|
1579
1487
|
return True
|
1580
1488
|
|
1581
1489
|
|
@@ -1691,62 +1599,7 @@ class StreamWidget(QLabel):
|
|
1691
1599
|
# " #
|
1692
1600
|
##################################################################
|
1693
1601
|
|
1694
|
-
def define_accum_buffer(self, n ):
|
1695
|
-
# NEED TO REDEFINE ON S-X !!!!
|
1696
|
-
if (self.frame is None):#
|
1697
|
-
return False
|
1698
|
-
if (n == self.accum_buffer_size) and (len(self.accum_buffer) > 1):
|
1699
|
-
return True
|
1700
|
-
self.accum_buffer_size = n
|
1701
|
-
self.accum_buffer = np.zeros((self.accum_buffer_size, *self.frame.shape), dtype=self.img.dtype)
|
1702
|
-
self.accum_count = 0
|
1703
|
-
self.accum_index = 0
|
1704
|
-
self.running_sum = np.zeros(self.frame.shape, dtype=np.float64)
|
1705
|
-
return True
|
1706
|
-
|
1707
|
-
def add_to_accum_buffer(self, frame):
|
1708
|
-
# When adding a new frame:
|
1709
|
-
if (len(self.accum_buffer) < 1):
|
1710
|
-
return False
|
1711
|
-
#print("addind")
|
1712
|
-
if self.accum_count < self.accum_buffer_size:
|
1713
|
-
self.running_sum += frame
|
1714
|
-
self.accum_buffer[self.accum_index] = frame
|
1715
|
-
self.accum_count += 1
|
1716
|
-
else:
|
1717
|
-
oldest_frame = self.accum_buffer[self.accum_index]
|
1718
|
-
if frame.shape != oldest_frame.shape:
|
1719
|
-
#self.define_accum_buffer(self.accum_buffer_size )
|
1720
|
-
return False
|
1721
|
-
self.running_sum += frame.astype(np.float64) - oldest_frame.astype(np.float64)
|
1722
|
-
self.accum_buffer[self.accum_index] = frame
|
1723
|
-
# do as before
|
1724
|
-
#@self.accum_buffer[self.accum_index] = frame
|
1725
|
-
self.accum_index = (self.accum_index + 1) % self.accum_buffer_size
|
1726
|
-
return True
|
1727
|
-
|
1728
|
-
def get_mean_accum_buffer(self):
|
1729
|
-
if self.accum_count == 0:
|
1730
|
-
return None
|
1731
|
-
rimg = self.running_sum / self.accum_count
|
1732
|
-
return rimg.astype(np.uint8)
|
1733
|
-
# #print(self.accum_count, self.accum_buffer_size)
|
1734
|
-
# if self.accum_count > 1:
|
1735
|
-
# img = np.mean(self.accum_buffer[:self.accum_count], axis=0)
|
1736
|
-
# return img
|
1737
|
-
# return None
|
1738
|
-
|
1739
|
-
def order_accum_buffer_frames(self):
|
1740
|
-
if self.accum_count < self.accum_buffer_size:
|
1741
|
-
frames_ordered = self.accum_buffer[:self.accum_count]
|
1742
|
-
else:
|
1743
|
-
frames_ordered = np.concatenate((self.accum_buffer[self.accum_index:], self.accum_buffer[:self.accum_index]))
|
1744
|
-
for frame in frames_ordered:
|
1745
|
-
yield frame
|
1746
|
-
#return frames_ordered
|
1747
1602
|
|
1748
|
-
#def iter_accum_buffer_ordered_frames(self):
|
1749
|
-
# frames_ordered = self.order_accum_buffer_frames()
|
1750
1603
|
|
1751
1604
|
|
1752
1605
|
|
@@ -1802,17 +1655,19 @@ class StreamWidget(QLabel):
|
|
1802
1655
|
# SAVING organization HERE
|
1803
1656
|
|
1804
1657
|
if self.level2_buffer is None:
|
1805
|
-
self.level2_buffer = AccumBuffer(self.img)
|
1658
|
+
self.level2_buffer = buffers.AccumBuffer(self.img)
|
1806
1659
|
self.level2_buffer.define_accum_buffer( self.level2_buffer_max_size ) # ???
|
1807
1660
|
|
1808
1661
|
|
1809
1662
|
# DEFINE BUFFER, if not yet / if overtext is before, i have blurred timemarks
|
1810
1663
|
# ---------------------------- if overtext is after , i do not have greentext on image
|
1811
|
-
|
1812
|
-
|
1664
|
+
self.FABuffer.add( self.img, {'name':'test', 'time': dt.datetime.now()} )
|
1665
|
+
#if self.define_accum_buffer( self.accum_n ): # does nothing if already exists
|
1666
|
+
# self.add_to_accum_buffer( self.img) # No idea why fits has wrong colors
|
1813
1667
|
|
1814
|
-
|
1815
|
-
|
1668
|
+
# showing or NOT the average image
|
1669
|
+
if self.l_show_accum and (len(self.FABuffer) > 1):# and (len(self.accum_buffer) > 1):
|
1670
|
+
rimg = self.FABuffer.get_sum_frames()#_mean_accum_buffer()
|
1816
1671
|
if rimg is not None:
|
1817
1672
|
self.img = rimg
|
1818
1673
|
self.overttext(blackbar=True) # applies on img
|
@@ -1849,106 +1704,104 @@ class StreamWidget(QLabel):
|
|
1849
1704
|
# ---- just save once ----------------- -------------------------------------------- ************ "s" ***********
|
1850
1705
|
if self.saving_once:
|
1851
1706
|
# jpg and NO AVG
|
1852
|
-
if (self.
|
1707
|
+
if (len(self.FABuffer) < 2) and (not self.l_show_accum) and (not self.saving_fits_only):
|
1853
1708
|
# no bufffer no loopshow no fits
|
1854
1709
|
self.save_img( time_tag=self.frame_time , dumpbuffer=False, use_fits=False ) # one simple image
|
1855
1710
|
print(fg.red, "s1", fg.default, end="")
|
1856
1711
|
self.saving_once = False
|
1857
1712
|
# jpg and NO AVG
|
1858
|
-
elif (self.
|
1713
|
+
elif (len(self.FABuffer) >= 2) and (not self.l_show_accum) and (not self.saving_fits_only):
|
1859
1714
|
self.save_img( time_tag=self.frame_time, dumpbuffer=False, use_fits=False ) # save one simple image only
|
1860
1715
|
print(fg.red, "s1", fg.default, end="")
|
1861
1716
|
self.saving_once = False
|
1862
1717
|
# jpg and AVG
|
1863
|
-
elif (self.
|
1718
|
+
elif (len(self.FABuffer) < 2) and (self.l_show_accum) and (not self.saving_fits_only):
|
1864
1719
|
# no bufffer no loopshow no fits
|
1865
1720
|
self.save_img( time_tag=self.frame_time, dumpbuffer=False, use_fits=False ) # just one simple image /lshow inside
|
1866
1721
|
print(fg.red, "F1", fg.default, end="")
|
1867
1722
|
self.saving_once = False
|
1868
1723
|
pass
|
1869
1724
|
# jpg and AVG
|
1870
|
-
elif (self.
|
1725
|
+
elif (len(self.FABuffer) >= 2) and (self.l_show_accum) and (not self.saving_fits_only):
|
1871
1726
|
# no bufffer no loopshow no fits
|
1872
|
-
if self.accum_index >= self.
|
1873
|
-
|
1874
|
-
|
1875
|
-
|
1876
|
-
pass
|
1727
|
+
#if self.accum_index >= len(self.FABuffer) - 1:
|
1728
|
+
self.save_img( time_tag=self.frame_time, dumpbuffer=False, use_fits=False ) # should be 1 AVG IMG
|
1729
|
+
print(fg.red, "F1", fg.default, end="")
|
1730
|
+
self.saving_once = False
|
1877
1731
|
# FITS and NO AVG ---------------------------------------------------------------------------- FITS
|
1878
|
-
elif (self.
|
1732
|
+
elif (len(self.FABuffer) < 2) and (not self.l_show_accum) and (self.saving_fits_only):
|
1879
1733
|
# no bufffer no loopshow YES fits
|
1880
1734
|
self.save_img( time_tag=self.frame_time , dumpbuffer=False, use_fits=True ) # 1 img
|
1881
1735
|
print(fg.red, "F1", fg.default, end="")
|
1882
1736
|
self.saving_once = False
|
1883
1737
|
pass
|
1884
1738
|
# FITS and NO AVG
|
1885
|
-
elif (self.
|
1739
|
+
elif (len(self.FABuffer) >= 2) and (not self.l_show_accum) and (self.saving_fits_only):
|
1886
1740
|
# no bufffer no loopshow no fits
|
1887
1741
|
self.save_img( time_tag=self.frame_time , dumpbuffer=True, use_fits=True ) # dump buffer once
|
1888
1742
|
print(fg.red, "F1", fg.default, end="")
|
1889
1743
|
self.saving_once = False
|
1890
1744
|
pass
|
1891
1745
|
# FITS and avg
|
1892
|
-
elif (self.
|
1746
|
+
elif (len(self.FABuffer) < 2) and (self.l_show_accum) and (self.saving_fits_only):
|
1893
1747
|
# no bufffer no loopshow no fits
|
1894
1748
|
self.save_img( time_tag=self.frame_time , dumpbuffer=False, use_fits=True ) # one AVG
|
1895
1749
|
print(fg.red, "F1", fg.default, end="")
|
1896
1750
|
self.saving_once = False
|
1897
1751
|
pass
|
1898
1752
|
# FITS and avg there are more
|
1899
|
-
elif (self.
|
1753
|
+
elif (len(self.FABuffer) >= 2) and (self.l_show_accum) and (self.saving_fits_only):
|
1900
1754
|
# no bufffer no loopshow no fits
|
1901
|
-
if self.accum_index >= self.
|
1902
|
-
|
1903
|
-
|
1904
|
-
|
1905
|
-
pass
|
1755
|
+
#if self.accum_index >= len(self.FABuffer) - 1:
|
1756
|
+
self.save_img( time_tag=self.frame_time , dumpbuffer=False, use_fits=True ) # many AVG IDK
|
1757
|
+
print(fg.red, "F1", fg.default, end="")
|
1758
|
+
self.saving_once = False
|
1906
1759
|
|
1907
1760
|
|
1908
1761
|
# ---- save ALL ----------------- -------------------------------------------- ************ "shift-s" ***********
|
1909
1762
|
# ---- save ALL ----------------- -------------------------------------------- ************ "shift-s" ***********
|
1910
1763
|
if self.saving_all: # --------------- Shift-S-------
|
1911
1764
|
# jpg and NO AVG
|
1912
|
-
if (self.
|
1765
|
+
if (len(self.FABuffer) < 2) and (not self.l_show_accum) and (not self.saving_fits_only):
|
1913
1766
|
self.save_img( time_tag=self.frame_time, dumpbuffer=False, use_fits=False) # every frame, BURSTING JPGS!
|
1914
1767
|
print(fg.red, "s!", fg.default, f"{bg.red}{fg.white}!!!!!!!!!!!!{bg.default}{fg.default}", end="\n")
|
1915
1768
|
# jpg and NO AVG
|
1916
|
-
elif (self.
|
1769
|
+
elif (len(self.FABuffer) >= 2) and (not self.l_show_accum) and (not self.saving_fits_only):
|
1917
1770
|
self.save_img( time_tag=self.frame_time, dumpbuffer=True, use_fits=False ) # Dump Full Buffer and stop
|
1918
1771
|
print(fg.red, "s-FuB DUMPED", fg.default, end="\n") # ONE DUMP
|
1919
1772
|
self.saving_all = False
|
1920
1773
|
# jpg and AVG
|
1921
|
-
elif (self.
|
1774
|
+
elif (len(self.FABuffer) < 2) and (self.l_show_accum) and (not self.saving_fits_only):
|
1922
1775
|
# no bufffer no loopshow no fits
|
1923
1776
|
#self.save_img( time_tag=self.frame_time, dumpbuffer=False, use_fits=False ) # just one simple image /lshow inside
|
1924
1777
|
self.saving_all = False
|
1925
1778
|
pass
|
1926
1779
|
# jpg and AVG
|
1927
|
-
elif (self.
|
1780
|
+
elif (len(self.FABuffer) >= 2) and (self.l_show_accum) and (not self.saving_fits_only):
|
1928
1781
|
# no bufffer no loopshow no fits
|
1929
1782
|
#self.save_img( time_tag=self.frame_time, dumpbuffer=False, use_fits=False ) # should be AVG
|
1930
|
-
if self.accum_index >= self.
|
1783
|
+
#if self.accum_index >= len(self.FABuffer) - 1:
|
1784
|
+
if self.FABuffer.new_sum_available():
|
1931
1785
|
self.save_img( time_tag=self.frame_time, dumpbuffer=False, use_fits=False ) # Dump Full Buffer and stop
|
1932
|
-
print(fg.red, "Save
|
1933
|
-
pass
|
1786
|
+
print(fg.red, "Save SUM evry Nth ", fg.default, end="\n")
|
1934
1787
|
# FITS and NO AVG ---------------------------------------------------------------------------- FITS
|
1935
1788
|
# FITS and NO AVG ---------------------------------------------------------------------------- FITS
|
1936
|
-
elif (self.
|
1789
|
+
elif (len(self.FABuffer) < 2) and (not self.l_show_accum) and (self.saving_fits_only):
|
1937
1790
|
print(" here fits for every image .... too low buffer --- so MAYBE ")
|
1938
1791
|
# no bufffer no loopshow YES fits
|
1939
1792
|
self.save_img( time_tag=self.frame_time, dumpbuffer=False, use_fits=True) # every frame, BURSTING FITS !?!?!
|
1940
1793
|
#print(fg.red, "every N frames to FITS-IDK", fg.default, f"{bg.red}{fg.white}???{bg.default}{fg.default}", end="\n")
|
1941
1794
|
pass
|
1942
1795
|
# FITS and NO AVG
|
1943
|
-
elif (self.
|
1796
|
+
elif (len(self.FABuffer) >= 2) and (not self.l_show_accum) and (self.saving_fits_only):
|
1944
1797
|
print(fg.red," here fits for ALL BUFFER NONONO no save ", fg.default, end="")
|
1945
1798
|
## no bufffer no loopshow no fits
|
1946
|
-
#if self.accum_index >= self.
|
1799
|
+
#if self.accum_index >= len(self.FABuffer) - 1:
|
1947
1800
|
# self.save_img( time_tag=self.frame_time , dumpbuffer=True, use_fits=True ) # dump buffer every time
|
1948
1801
|
# print(fg.red, "F-FuB", fg.default , f"{bg.red}{fg.white}!!!!!!!!!!!!{bg.default}{fg.default}", end="\n")
|
1949
1802
|
pass
|
1950
1803
|
# FITS and avg
|
1951
|
-
elif (self.
|
1804
|
+
elif (len(self.FABuffer) < 2) and (self.l_show_accum) and (self.saving_fits_only):
|
1952
1805
|
print(fg.red, " here - too low buffer+ ACCUM => no save ", fg.default, end="")
|
1953
1806
|
# no bufffer no loopshow no fits
|
1954
1807
|
#self.save_img( time_tag=self.frame_time , dumpbuffer=False, use_fits=True ) # one AVG (lshow handled inside)
|
@@ -1956,11 +1809,12 @@ class StreamWidget(QLabel):
|
|
1956
1809
|
self.saving_all = False
|
1957
1810
|
pass
|
1958
1811
|
# FITS and avg
|
1959
|
-
elif (self.
|
1812
|
+
elif (len(self.FABuffer) >= 2) and (self.l_show_accum) and (self.saving_fits_only):
|
1960
1813
|
# TOO COMPLEX -------------- I CHANGE TO FITS EVERY TIME NEW BUFFER IS OK -----------
|
1961
1814
|
# no bufffer no loopshow no fits
|
1962
1815
|
#self.save_img( time_tag=self.frame_time , dumpbuffer=False, use_fits=True ) # many AVG IDK
|
1963
|
-
if self.
|
1816
|
+
if self.FABuffer.new_sum_available():
|
1817
|
+
#if self.accum_index >= len(self.FABuffer) - 1: # ONLY THE ACCUM FRAME!
|
1964
1818
|
self.save_img( time_tag=self.frame_time , dumpbuffer=False, use_fits=True ) # SIMPLIFIED
|
1965
1819
|
print(fg.red, "F-Every Nth-AVG to FITS -IDK", fg.default, end="")
|
1966
1820
|
###########################################################################################################################################
|
@@ -2060,6 +1914,7 @@ class StreamWidget(QLabel):
|
|
2060
1914
|
#print(" + ".join(parts), f" /{chr(key)}/ .... {parts_set}")
|
2061
1915
|
# ----------------------------------------------------------------- s savings
|
2062
1916
|
if (key == Qt.Key.Key_S):
|
1917
|
+
self.SAVED_NOW = True # red blink
|
2063
1918
|
if ( len(parts_set) == 0) :
|
2064
1919
|
self.saving_once = True
|
2065
1920
|
self.saving_all = False
|
@@ -2311,6 +2166,7 @@ class StreamWidget(QLabel):
|
|
2311
2166
|
# 0 would be a problem (locally???); but 1 is not sent!!! ; SENDING 0, checking@send_command
|
2312
2167
|
elif (parts_set == {'Ctrl', 'Shift'}) :
|
2313
2168
|
self.l_show_accum = not self.l_show_accum
|
2169
|
+
print(f"i... ACCUMULATION IS {self.l_show_accum}")
|
2314
2170
|
|
2315
2171
|
# ----------------------------------------------------------------- b
|
2316
2172
|
if (key == Qt.Key.Key_B):
|
@@ -0,0 +1,9 @@
|
|
1
|
+
pogucam/__init__.py,sha256=Iij7VvXCrFPMtTia41mQ7LxFLaulf_fD5cb-AyjpUo0,53
|
2
|
+
pogucam/buffers.py,sha256=DwEmQYej6CJ7KwXLhR_ulIC_tziQAKM2yFQoEXZ-ocA,5432
|
3
|
+
pogucam/explore_u24_uni.py,sha256=BHsS7pAtJKMr7EqlcERF2_MaP6ZZ1Lyy1xs1EMGF8-c,109954
|
4
|
+
pogucam/installation.md,sha256=8qspiLlYjEBx5CedRfBU7Mm0A2pz0lfAnaupZyBm5Eo,128
|
5
|
+
pogucam/text_write.py,sha256=hyRyA1M5z-pda963T-k0i8fvvAlv1p3YBTZtYNdOeoE,19304
|
6
|
+
pogucam-0.1.6.dist-info/METADATA,sha256=jLLq8fx_VfVQCV6dKyIre54w9MUCtF__AOQ8tJ17M2I,466
|
7
|
+
pogucam-0.1.6.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
8
|
+
pogucam-0.1.6.dist-info/entry_points.txt,sha256=-97N0LsXIR8h0rJMzIMuNeNwuY8LvPYPTqnXsuAnVsM,63
|
9
|
+
pogucam-0.1.6.dist-info/RECORD,,
|
pogucam-0.1.4.dist-info/RECORD
DELETED
@@ -1,8 +0,0 @@
|
|
1
|
-
pogucam/__init__.py,sha256=Iij7VvXCrFPMtTia41mQ7LxFLaulf_fD5cb-AyjpUo0,53
|
2
|
-
pogucam/explore_u24_uni.py,sha256=Ff7f3JkeWDRdSI6o52ZBM4JoWxIMnGzxH5NV_Bn0zBI,115676
|
3
|
-
pogucam/installation.md,sha256=8qspiLlYjEBx5CedRfBU7Mm0A2pz0lfAnaupZyBm5Eo,128
|
4
|
-
pogucam/text_write.py,sha256=hyRyA1M5z-pda963T-k0i8fvvAlv1p3YBTZtYNdOeoE,19304
|
5
|
-
pogucam-0.1.4.dist-info/METADATA,sha256=cpcxAlTeU57rHTtTzc_tlsde57hRgK1Hf6v7nDfsBJo,466
|
6
|
-
pogucam-0.1.4.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
7
|
-
pogucam-0.1.4.dist-info/entry_points.txt,sha256=2HKUwWLXuAMIvwAMTSJ2BUasPkGK1SnDgIW7LJ8z-pA,55
|
8
|
-
pogucam-0.1.4.dist-info/RECORD,,
|
File without changes
|