class InfoFrame(tk.Frame, CustomWidget): bgcolor = util.rgb(41, 43, 44) txcolor = util.rgb(255, 255, 255) def __init__(self, master): super(InfoFrame, self).__init__(master, background=InfoFrame.bgcolor) self.pack(side=tk.LEFT, fill=tk.BOTH) self.create_widgets() def create_widgets(self): lblfont = font.Font(family="Verdana") tk.Label( self, font=lblfont, background=InfoFrame.bgcolor, foreground=InfoFrame.txcolor, text="Instituto Politecnico Nacional\nEscuela Superior de Computo\n" ).grid(row=0, columnspan=2) tk.Label(self, font=lblfont, background=InfoFrame.bgcolor, foreground=InfoFrame.txcolor, text="Instrumentacion").grid(row=1, column=0) tk.Label(self, font=lblfont, background=InfoFrame.bgcolor, foreground=InfoFrame.txcolor, text=PROPS["grupo"]).grid(row=1, column=1) names = PROPS["integrantes"].split(";") lblteam = tk.Label(self, font=lblfont, background=InfoFrame.bgcolor, foreground=InfoFrame.txcolor, justify="left", text='\n'.join(names)) lblteam.grid(row=3, columnspan=2) self.measurement = tk.DoubleVar(self, value=0) tk.Entry(self, text="Valor de prueba", justify="center", state="readonly", textvariable=self.measurement, width=10).grid(row=5, column=0) tk.Label(self, font=lblfont, background=InfoFrame.bgcolor, foreground=InfoFrame.txcolor, text="% de humedad").grid(row=5, column=1) self.grid_rowconfigure(2, minsize=100) self.grid_rowconfigure(4, minsize=50)
def draw(self, k, h, y0, data=None): """Отрисовка холста""" """[Row(format_='DBK', glub=1477, ampl='0', lenth=0.48, timdata=time.struct_time(tm_year=2019, tm_mon=6, tm_mday=17, tm_hour=12, tm_min=5, tm_sec=19, tm_wday=0, tm_yday=168, tm_isdst=-1), shir='', dolg='', vs='', kurs='', vz='1500', zg='0.0', ku='15', depth='M', rej='R', frek='50', cnt=2, m='2', m_man='', color_mm='', m_avto='', all_data=[(1477, 20, 0.48), (1500, 62, 2.88)]), ...]""" self.can.delete('point') dx = 6 # размер пикселя i = 0 for ix in data: # print(ix.all_data) for gl, am, ln in ix.all_data: Y = (gl / k * h / 200 - y0) * dx / 2 L1 = (ln / k * h / 20) * dx / 2 L = L1 if L1 > dx else dx color = rgb(am) X0 = 200 - dx * i X1 = 200 - dx * (i + 1) # print(y0, i, Y) self.can.create_rectangle(X0, Y, X1 + 1, Y + L, fill=color, outline='', tag='point') i += 1
def __call__(self, img, show_plots=False): hits = self.get_hits(img) heat = make_heatmap(img.shape[0:2], hits) if self._last_heatmap is None: self._last_heatmap = heat filtered_heat = (1 - self._alpha) * self._last_heatmap + self._alpha * heat self._last_heatmap = filtered_heat binary = filtered_heat >= self._threshold labels = label_image(binary) boxes = [] for i in range(labels[1]): y_points, x_points = np.where(labels[0] == i + 1) box = ((np.min(x_points), np.min(y_points)), (np.max(x_points), np.max(y_points))) width = box[1][0] - box[0][0] height = box[1][1] - box[0][1] if width >= 32 and height >= 32: boxes.append(box) if show_plots: f, ((a0, a1), (a2, a3)) = plt.subplots(2, 2) a0.set_title('Raw Hits') a0.imshow(draw_boxes(rgb(img, self._cspace), hits)) a1.set_title('Heatmap') a1.imshow(heat.astype(np.float32) / np.max(heat), cmap='gray') a2.set_title('Thresholded Heatmap') a2.imshow(binary, cmap='gray') a3.set_title('Label Image') a3.imshow(labels[0], cmap='gray') return boxes
def start(self, colors, interval): cols = [] widths = [] self._totalWidth = 0 for stripe in colors: widths.append(int(stripe['width'])) cols.append(rgb(stripe['color'])) self._totalWidth += int(stripe['width']) self._offset = 0 self._interval = interval self._frames = 0 self._cols = cols self._widths = widths
def data_pdf(self): """Рисуем данные в масштабе, масштаб как и в просмоторщике 'глубина','амплитуда','%d.%m.%y %H:%M:%S','широта','долгота', 'метка ручн', 'метка txt(avto)', [all]. """ W, H, dx, dy = self.W, self.H, self.dx, self.dy y = 10 # смещение гор. надписи относит. верха оси X hide_met, view_len = self.master.gethide_metka() dat = [i.glub / 1.0 for i in self.data] # глубина [1] .glub # glub = [i[2] for i in self.data] # амплитуда [2] .ampl dat_all = None try: dat_all = [g.all_data for g in self.data ] # [[(),(),...],[(), (),...],...] .all_data [-1] except Exception: pass man_met = [i.m_man for i in self.data] # ручн. метка .m_man [8] color_mm = [i.color_mm for i in self.data] # цвет ручн. метки .color_mm [] avt_met = [i.m_avto for i in self.data] # авт.. метка .m_avto [10] txt = [i.timdata for i in self.data] # объект времени .timdata [3] # scal = ([5, 10, 15, 20], [10, 20, 30, 40], [50, 100, 150, 200], [100, 200, 300, 400], # [200, 400, 600, 800], [500, 1000, 1500, 2000], [1000, 2000, 3000, 4000], # [1500, 3000, 4500, 6000], [2000, 4000, 6000, 8000], [2500, 5000, 7500, 10000]) scal = ([5, 10, 15, 20], [10, 20, 30, 40], [25, 50, 75, 100], [50, 100, 150, 200], [100, 200, 300, 400], [200, 400, 600, 800], [250, 500, 750, 1000], [500, 1000, 1500, 2000], [1000, 2000, 3000, 4000], [1500, 3000, 4500, 6000], [2000, 4000, 6000, 8000], [2500, 5000, 7500, 10000]) j, n = self.list_scale[ self.scale] if self.scale else self.list_scale[0] self.c.saveState() self.c.setDash([]) self.c.setFont('Helvetica', 10) self.XY_dat(scal[j]) self.c.restoreState() # self.k = self.k * 2 # for i in range(self.w): if i >= len(self.data): break # если данных меньше чем w то будет except if not self.master.can_show.flag_on_point: # если показ всех целей if dat_all[i]: # [(), (),...] for gl in dat_all[ i]: # проход по всем (глубинам, амплитудам) можно сменить цвет if i != 0: if gl[0] / 1.0 <= scal[j][ -1] * 10: # 100000 подрезка выпадающих за низ холста color = rgb(gl[1]) self.c.setFillColor(color) # self.c.setStrokeColor(color) if not view_len: self.c.circle(dx + W - i * self.k - 1, dy + H - round(gl[0] * n) * H / 400, 0.8, stroke=0, fill=1) else: ln = round(gl[-1] * 10 * n) * H / 400 Yi = H - round(gl[0] * n * H / 400) lnn = Yi if ln > Yi else ln self.c.rect( dx + W - i * self.k - 1, dy + Yi, # 450/400 = 1.125 1, 1 - lnn, stroke=0, fill=1) else: # показ одной цели if dat[i]: # 10km if dat[i] <= 100000: # выкидываю > 10км, чтобы не вылезало за ось снизу #color1 = rgb(glub[i]) #color1 = rgb(dat_all[i][0][1]) color1 = '#444' # self.c.setFillColor(color1) # self.c.setStrokeColor(color1) self.c.circle( dx + W - i * self.k - 1, dy + H - round(dat[i] * n) * H / 400, # 0.80, stroke=0, fill=1) self.c.saveState() self.c.setDash([]) self.c.setFont('Helvetica', 10) if dat[i] != 0: Y = dy + H - round(dat[i] * n) * H / 400 if Y < dy: Y = dy else: #Y = dy Y = dy + H numa = avt_met[i].strip() if numa and hide_met: # авто метка self.c.setFillColor('blue') self.c.setStrokeColor('blue') self.c.setLineWidth(0.25) self.c.line(dx + W - i * self.k, Y, dx + W - i * self.k, dy + H + 5) # avto_metka self.c.translate(dx + W - i * self.k - 6, dy + y + H + 15) self.c.drawCentredString(5, -15, f'{numa}') self.c.setFillColor('blue') self.c.setStrokeColor('blue') self.c.drawCentredString(5, 0, self.txt_time(txt[i])) num = man_met[i].strip() if num and hide_met: # ручная метка color_ = color_mm[i] # "red" or "green" if color_ == 'spring green': # 00ff7f color_ = 'green' self.c.setFillColor(color_) self.c.setStrokeColor(color_) self.c.setLineWidth(0.5) self.c.line(dx + W - i * self.k, Y, dx + self.W - i * self.k, dy + H + 5) # man_metka self.c.translate(dx + W - i * self.k - 6, dy + y + H) self.c.drawCentredString(5, 0, f'{num}') self.c.restoreState() self.c.setFillColor('#777') self.c.setFont('Arial', 11) self.c.drawString(dx * 1.2, dy // 2 - 12, self.info()) # 2
def set_data(self, canv): """Выводим данные и надписи на осях и метки""" W, H, m_top, m_left = self.W, self.H, self.m_top, self.m_left color_p = '#f59400' color_t = 'black' color_d = 'darkgreen' font_t = self.font ofsetY = 12 # y_len = 2 line = canv.create_line text = canv.create_text for j in range(W): if j < len(self.data): # if 1: # глубина, в amp цвет !!! self.data[j].glub # all_data = self.data[j].all_data # if self.data[j].all_data: # бывает есть глубина а all_data=[] !!! [-1] # if self.data[j].glub: # all_data Y = (self.data[j].glub / self.k * H / 200) # else: # continue if Y < H and Y != 0: line( m_left + W - j, m_top + Y, m_left + W - j, H + m_top - 2, fill=self.colorf, tag='dno' ) # дно рисуем раньше точек (иначе затрём нижние цели) if not self.flag_on_point: all_data = self.data[j].all_data for gl, amp, ln in all_data: Y1 = (gl / self.k * H / 200) L1 = (ln / self.k * H / 20) if self.flag_on_lentht else 2 color1 = rgb(amp) if Y1 < H: y_len = L1 if L1 > 2 else 2 if Y1 + y_len > H: y_len = H - Y1 line( m_left + W - j, m_top + Y1, # point_all m_left + W - j, m_top + Y1 + y_len, fill=color1, width='1', tag='point_all') else: if Y < H and Y != 0: line( m_left + W - j, m_top + Y, # point one m_left + W - j, m_top + Y + 2, fill=color_p, width='1', tag='point') if j == W // 4 - 1: txtX = time.strftime("%H:%M", self.data[j].timdata) # [3] text( m_left + W * 3 // 4, m_top + H + ofsetY, text=f'{txtX}', # text_X_time1 anchor='n', font=font_t, fill=color_t, tag='text') if self.day != time.strftime("%d.%m", self.data[j].timdata): txtXD = time.strftime("%d.%m", self.data[j].timdata) text( m_left + W * 3 // 4 + self.ofsetd, m_top + H + ofsetY, text=f'/{txtXD}', # text_X_data1 anchor='n', font=font_t, fill=color_d, tag='text') self.day = txtXD if j == W // 2 - 1: txtX = time.strftime("%H:%M", self.data[j].timdata) text( m_left + W // 2, m_top + H + ofsetY, text=f'{txtX}', # text_X_time2 anchor='n', font=font_t, fill=color_t, tag='text') if self.day != time.strftime("%d.%m", self.data[j].timdata): txtXD = time.strftime("%d.%m", self.data[j].timdata) text( m_left + W // 2 + self.ofsetd, m_top + H + ofsetY, text=f'/{txtXD}', # text_X_data1 anchor='n', font=font_t, fill=color_d, tag='text') self.day = txtXD if j == W * 3 // 4 - 1: txtX = time.strftime("%H:%M", self.data[j].timdata) text( m_left + W // 4, m_top + H + ofsetY, text=f'{txtX}', # text_X_time3 anchor='n', font=font_t, fill=color_t, tag='text') if self.day != time.strftime("%d.%m", self.data[j].timdata): txtXD = time.strftime("%d.%m", self.data[j].timdata) text( m_left + W // 4 + self.ofsetd, m_top + H + ofsetY, text=f'/{txtXD}', # text_X_data1 anchor='n', font=font_t, fill=color_d, tag='text') self.day = txtXD if j == W - 1: txtX = time.strftime("%H:%M", self.data[j].timdata) text(m_left, m_top + H + ofsetY, text=f'{txtX}', anchor='n', font=font_t, fill=color_t, tag='text') if self.day != time.strftime("%d.%m", self.data[j].timdata): txtXD = time.strftime("%d.%m", self.data[j].timdata) text( m_left + self.ofsetd, m_top + H + ofsetY, text=f'/{txtXD}', # text_X_data1 anchor='n', font=font_t, fill=color_d, tag='text') self.day = txtXD Y = m_top + self.data[j].glub // self.k * H // 200 # int() if Y > m_top + H: Y = m_top + H num = self.data[j].m_man.strip() # [8] if num: # мануал метка 8 color = self.data[j].color_mm # [9] self.create_manmetka(j, num, color, Y) numa = self.data[j].m_avto.strip() # [10] if numa: # авто метка 10 self.create_avtometka(j, numa, Y)