def display_panel_mergeframe(self, arg_frame, arg_stepX, arg_stepY):
print '*** ',len(arg_frame.shape)
if len(arg_frame.shape)==3:
tmp_frame= cv2.cvtColor(arg_frame, cv2.COLOR_BGR2RGB)
else:
tmp_frame= cv2.cvtColor(arg_frame, cv2.COLOR_GRAY2RGB)
tmp_frame= cv2.resize(tmp_frame,(self.mergeframe_splitX,self.mergeframe_splitY),interpolation=cv2.INTER_LINEAR)
begX= gui_vars.interval_x+self.mergeframe_splitX*arg_stepX
begY= self.mergeframe_spaceY+ self.mergeframe_splitY* arg_stepY
self.mergeframe[begY:begY+ self.mergeframe_splitY, begX: begX+ self.mergeframe_splitX]= tmp_frame
#begY= self.mergeframe_height- 50- self.mergeframe_splitY*arg_stepY
#self.mergeframe[begY-self.mergeframe_splitY:begY, begX: begX+ self.mergeframe_splitX]= tmp_frame
self.mergeframe_stepX= arg_stepX
self.mergeframe_stepY= arg_stepY
print '>> mergeframe_splitY, splitX= ', self.mergeframe_splitY, ', ', self.mergeframe_splitX
print '>> tmp_frame.shape[0,1]= ', tmp_frame.shape[0],', ',tmp_frame.shape[1]
result = Image.fromarray(self.mergeframe)
result = ImageTk.PhotoImage(result)
self.panel_mergeframe.configure(image = result)
self.panel_mergeframe.image = result
python类PhotoImage()的实例源码
def onDetect(self):
if self.imageName == "":
mbox.showerror("Error", 'Citra masukan belum terisi\nSilakan pilih dengan menekan tombol "Open File"')
else:
self.textBoxLog.config(state='normal')
self.textBoxLog.insert(END, "Mendeteksi: "+self.imageName+"\n")
self.textBoxLog.see(END)
self.textBoxLog.config(state='disabled')
imageResultPath = CopyMoveDetection.detect(self.imagePath, self.imageName, '../testcase_result/', blockSize=32)
newImageRight = Image.open(imageResultPath)
imageRightLabel = ImageTk.PhotoImage(newImageRight)
self.labelRight = Label(self, image=imageRightLabel)
self.labelRight.image = imageRightLabel
self.labelRight.place(x=525, y=100)
self.textBoxLog.config(state='normal')
self.textBoxLog.insert(END, "Selesai.")
self.textBoxLog.see(END)
self.textBoxLog.config(state='disabled')
pass
pass
def __init__(self,*args,**kwargs):
tk.Tk.__init__(self,*args,**kwargs)
self.setup=tk.Button(self,text="Setup",command=self.setupFunc)
self.setup.pack()
self.play=tk.Button(self,text="Play",command=self.playFunc)
self.play.pack()
self.pause=tk.Button(self,text="Pause",command=self.pauseFunc)
self.pause.pack()
self.teardown=tk.Button(self,text="Teardown",command=self.teardownFunc)
self.teardown.pack()
self.img=ImageTk.PhotoImage(Image.open('tuned.jpg'))
self.video=tk.Label(self,image=self.img)
self.video.pack()
self.status="INIT"
self.c=0
self.initialize()
gui.py 文件源码
项目:Towards-a-Biologically-Plausible-Backprop
作者: bscellier
项目源码
文件源码
阅读 21
收藏 0
点赞 0
评论 0
def update_canvas(self, first_time = False):
units = [(28,28)] +[(10,n/10) for n in self.hidden_sizes]+[(1,10)]
pixels = [(140,140)]+ [(n/2,50) for n in self.hidden_sizes]+[(250,25)]
arrays = [256*layer.eval().reshape(dimensions) for layer,dimensions in zip(self.net.layers,units)]
images = [Image.fromarray(array).resize(dimensions) for array,dimensions in zip(arrays,pixels)]
self.imgTks = [ImageTk.PhotoImage(image) for image in images]
[energy, cost, _] = self.net.measure()
if first_time:
self.img_canvas = [self.canvas.create_image(400, (self.n_layers-k)*100, image=imgTk) for k,imgTk in enumerate(self.imgTks)]
self.energy_canvas = self.canvas.create_text( 20, 100, anchor=W, font="Purisa", text="Energy = %.1f" % (energy))
self.cost_canvas = self.canvas.create_text( 20, 200, anchor=W, font="Purisa", text="Cost = %.4f" % (cost))
else:
for img_canvas, imgTk in zip(self.img_canvas,self.imgTks):
self.canvas.itemconfig(img_canvas, image=imgTk)
self.canvas.itemconfig(self.energy_canvas, text="Energy = %.1f" % (energy))
self.canvas.itemconfig(self.cost_canvas, text="Cost = %.4f" % (cost))
def update(self):
while self.running:
# Read the length of the image as a 32-bit unsigned int.
data_len = struct.unpack('<L', self.connection.read(struct.calcsize('<L')))[0]
if data_len:
printD('Updating...')
printD('data_len: %s' % data_len)
data = self.connection.read(data_len)
deserialized_data = msgpack.unpackb(data, object_hook=msgpack_numpy.decode)
printD('Frame received')
#print(deserialized_data)
#stdout.flush()
img = Image.fromarray(deserialized_data)
newImage = ImageTk.PhotoImage(img)
self.gui.stream_label.configure(image=newImage)
self.gui.stream_label.image = newImage
printD("image updated")
else:
time.sleep(0.001)
def update_2(self):
if self.running == False:
return
# Read the length of the image as a 32-bit unsigned int.
data_len = struct.unpack('<L', self.connection.read(struct.calcsize('<L')))[0]
if data_len:
printD('Updating...')
printD('data_len: %s' % data_len)
data = self.connection.read(data_len)
deserialized_data = msgpack.unpackb(data, object_hook=msgpack_numpy.decode)
printD('Frame received')
#print(deserialized_data)
#stdout.flush()
img = Image.fromarray(deserialized_data)
newImage = ImageTk.PhotoImage(img)
self.gui.stream_label.configure(image=newImage)
self.gui.stream_label.image = newImage
self.gui.master.after(70, self.update_2)
def make_image(self):
self.image_frame = Frame()
self.image_frame.grid(row=3, column=1, columnspan=1)
self.confirm_button = Button(self.image_frame, command=self.confirm_callback, text="Confirm", state=DISABLED)
self.confirm_button.grid(row=3, column=1)
class_var = StringVar()
self.dropdown_class = OptionMenu(self.image_frame, class_var, self.classes_dictionary[self.classes[0]],
self.classes_dictionary[self.classes[1]], command=self.class_dropdown_callback)
self.dropdown_class.var = class_var
self.dropdown_class.grid(row=2, column=1)
if self.point_query_image.shape[1] == 1:
query_img = self.point_query_image[0, :, :].squeeze()
else:
query_img = self.point_query_image.squeeze().transpose(1, 2, 0)
query_img = Image.fromarray(np.uint8(255 * query_img))
query_img = ImageTk.PhotoImage(query_img)
imglabel = Label(self.image_frame, image=query_img, text="point query", compound=BOTTOM)
imglabel.image = query_img
imglabel.grid(row=1, column=1)
self.image_frame.pack()
return True
def __orders_tab_clicked(self, from_barcode = False):
#
# Orders tab click event
#
self.current_tab = "orders"
# update the images in the tab bar to show the selected tab
self.ordersicon = ImageTk.PhotoImage(Image.open(self.system_path + "tabbar-orders-selected.bmp"))
self.orders_button.config(image = self.ordersicon)
self.productsicon = ImageTk.PhotoImage(Image.open(self.system_path + "tabbar-products.bmp"))
self.products_button.config(image = self.productsicon)
self.partsicon = ImageTk.PhotoImage(Image.open(self.system_path + "tabbar-parts.bmp"))
self.parts_button.config(image = self.partsicon)
# clear any content from the content_scroll_frame and get a list of the current orders
self.uicommon.clear_frame(self.content_scroll_frame)
if (not from_barcode):
self.orders.orders_list(self.content_scroll_frame)
return()
def __products_tab_clicked(self, from_barcode = False):
#
# Products tab click events
#
self.current_tab = "products"
# update the images in the tab bar to show the selected tab
self.ordersicon = ImageTk.PhotoImage(Image.open(self.system_path + "tabbar-orders.bmp"))
self.orders_button.config(image = self.ordersicon)
self.productsicon = ImageTk.PhotoImage(Image.open(self.system_path + "tabbar-products-selected.bmp"))
self.products_button.config(image = self.productsicon)
self.partsicon = ImageTk.PhotoImage(Image.open(self.system_path + "tabbar-parts.bmp"))
self.parts_button.config(image = self.partsicon)
# clear any content from the content_scroll_frame and get a list of the products
self.uicommon.clear_frame(self.content_scroll_frame)
if (not from_barcode):
self.products.products_list(self.content_scroll_frame)
return()
def __parts_tab_clicked(self, from_barcode = False):
#
# Parts tab click event
#
self.current_tab = "parts"
# update the images in the tab bar to show the selected tab
self.ordersicon = ImageTk.PhotoImage(Image.open(self.system_path + "tabbar-orders.bmp"))
self.orders_button.config(image = self.ordersicon)
self.productsicon = ImageTk.PhotoImage(Image.open(self.system_path + "tabbar-products.bmp"))
self.products_button.config(image = self.productsicon)
self.partsicon = ImageTk.PhotoImage(Image.open(self.system_path + "tabbar-parts-selected.bmp"))
self.parts_button.config(image = self.partsicon)
# clear any content from the content_scroll_frame and get a list of the parts
self.uicommon.clear_frame(self.content_scroll_frame)
if (not from_barcode):
self.parts.parts_list(self.content_scroll_frame)
return()
def update_preview(self, psize):
# Safety check: Ignore calls during construction/destruction.
if not self.init_done: return
# Copy latest user settings to the lens object.
self.lens.fov_deg = self.f.get()
self.lens.radius_px = self.r.get()
self.lens.center_px[0] = self.x.get()
self.lens.center_px[1] = self.y.get()
# Re-scale the image to match the canvas size.
# Note: Make a copy first, because thumbnail() operates in-place.
self.img_sc = self.img.copy()
self.img_sc.thumbnail(psize, Image.NEAREST)
self.img_tk = ImageTk.PhotoImage(self.img_sc)
# Re-scale the x/y/r parameters to match the preview scale.
pre_scale = float(psize[0]) / float(self.img.size[0])
x = self.x.get() * pre_scale
y = self.y.get() * pre_scale
r = self.r.get() * pre_scale
# Clear and redraw the canvas.
self.preview.delete('all')
self.preview.create_image(0, 0, anchor=tk.NW, image=self.img_tk)
self.preview.create_oval(x-r, y-r, x+r, y+r,
outline='#C00000', width=3)
# Make a combined label/textbox/slider for a given variable:
def show_alert(drone,dBm, mac, ssid, channel):
global drone_img
frequency = get_frequency(channel)
distance = get_distance(dBm,frequency)
distance=round(distance,2)
text_file = open("logs.txt", "a")
text_file.write("\n"+str(datetime.datetime.now())+"\t"+mac+"\t"+ssid+"\t"+drone+" DRONE\t~"+str(distance)+"m.")
text_file.close()
if mac not in open('ignore.list').read():
ssid = ssid.split('_')
Label(f2, text='\n\n ALERT \n ', fg="red",font = "Verdana 10 bold").pack()
Label(f2, text='\n DRONE '+drone+' '+ssid[0]+' detected in approximately '+str(distance)+' meters \n\n{:%Y-%b-%d %H:%M:%S}'.format(datetime.datetime.now()),font = "Verdana 10 bold").pack()
image = Image.open("images/"+drone+".png")
image = image.resize((400, 400), Image.ANTIALIAS)
drone_img = ImageTk.PhotoImage(image)
Label(f2, image = drone_img).pack(side = "top", fill = "both", expand = "no")
Button(f2, text ="Ignore", command = lambda: ignore_it(mac)).pack(padx=255, pady=20, side=LEFT)
# Button(f2, text ="Deauth", command = lambda: deauth(channel)).pack(padx=5, pady=20, side=LEFT)
play_sound()
f2.after(9000, no_drone,f3)
else:
f2.after(0, no_drone,f3)
return
def convert2byte(self, depth=255):
(minimum, maximum) = self.getextrema()
m = 1
if maximum != minimum:
m = depth / (maximum-minimum)
b = -m * minimum
return self.point(lambda i, m=m, b=b: i * m + b).convert("L")
# returns a ImageTk.PhotoImage object, after rescaling to 0..255
def tkPhotoImage(self):
from PIL import ImageTk
return ImageTk.PhotoImage(self.convert2byte(), palette=256)
# --------------------------------------------------------------------
# Image series
# given a list of filenames, return a list of images
def convert2byte(self, depth=255):
(minimum, maximum) = self.getextrema()
m = 1
if maximum != minimum:
m = depth / (maximum-minimum)
b = -m * minimum
return self.point(lambda i, m=m, b=b: i * m + b).convert("L")
# returns a ImageTk.PhotoImage object, after rescaling to 0..255
def tkPhotoImage(self):
from PIL import ImageTk
return ImageTk.PhotoImage(self.convert2byte(), palette=256)
# --------------------------------------------------------------------
# Image series
# given a list of filenames, return a list of images
def __init__(self, master, text, width, foreground="black", truetype_font=None, font_path=None, family=None, size=None, **kwargs):
if truetype_font is None:
if font_path is None:
raise ValueError("Font path can't be None")
# Initialize font
truetype_font = ImageFont.truetype(font_path, size)
lines = textwrap.wrap(text, width=width)
width = 0
height = 0
line_heights = []
for line in lines:
line_width, line_height = truetype_font.getsize(line)
line_heights.append(line_height)
width = max(width, line_width)
height += line_height
image = Image.new("RGBA", (width, height), color=(0,0,0,0))
draw = ImageDraw.Draw(image)
y_text = 0
for i, line in enumerate(lines):
draw.text((0, y_text), line, font=truetype_font, fill=foreground)
y_text += line_heights[i]
self._photoimage = ImageTk.PhotoImage(image)
Label.__init__(self, master, image=self._photoimage, **kwargs)
def convert2byte(self, depth=255):
(minimum, maximum) = self.getextrema()
m = 1
if maximum != minimum:
m = depth / (maximum-minimum)
b = -m * minimum
return self.point(lambda i, m=m, b=b: i * m + b).convert("L")
# returns a ImageTk.PhotoImage object, after rescaling to 0..255
def tkPhotoImage(self):
from PIL import ImageTk
return ImageTk.PhotoImage(self.convert2byte(), palette=256)
# --------------------------------------------------------------------
# Image series
# given a list of filenames, return a list of images
def __init__(self, hat):
super(SortingHatGUI, self).__init__()
self.hat = hat
self.title('???')
self.configure(bg='#000000')
title_image = ImageTk.PhotoImage(Image.open('resources/hat.jpg'))
banner = tk.Label(self, image=title_image)
banner.image = title_image
banner.grid(columnspan=3)
self.initial_screen(init=True)
self.resizable(width=False, height=False)
threading.Thread(target=play_hedwig_theme, daemon=True).start()