用户:
坦率的木叶龙7bzN查看:0 回复:0 评论:0 创建时间:2021-02-22T21:11:21
【作品展示】

【作品介绍】
哈哈镜,超好玩
【作品源代码】
from PIL import Image, ImageTk
from tkinter.filedialog import askopenfilename
from tkinter import Label, Tk, Button, Canvas, Scale, HORIZONTAL
from main import maxMirror, minMirror
from skimage import io
class HaHaMirror(object):
def __init__(self):
self.root = Tk()
self.root.title('哈哈镜')
self.root.geometry('1200x500')
decoration = Image.open('bg.png').resize((1200, 500))
render = ImageTk.PhotoImage(decoration)
img = Label(image=render)
img.image = render
img.place(x=0, y=0)
Button(self.root, text="打开图片", command=self.showOriginalPic).place(x=50, y=120) # 原图的展示
Button(self.root, text="放大效果", command=self.maxMirrorFunc).place(x=50, y=200)
Button(self.root, text="缩小效果", command=self.minMirrorFunc).place(x=50, y=280)
Button(self.root, text="退出软件", command=self.quit).place(x=900, y=40)
self.path1 = None
self.width, self.height = 0, 0
Label(self.root, text="原始图片", font=10).place(x=380, y=120)
self.cv_orinial1 = Canvas(self.root, bg='white', width=270, height=270)
self.cv_orinial1.create_rectangle(8, 8, 260, 260, width=1, outline='red')
self.cv_orinial1.place(x=280, y=150)
self.label_Img_original1 = Label(self.root)
self.label_Img_original1.place(x=280, y=150)
Label(self.root, text="结果展示", font=10).place(x=820, y=120)
cv_seg = Canvas(self.root, bg='white', width=270, height=270)
cv_seg.create_rectangle(8, 8, 260, 260, width=1, outline='red')
cv_seg.place(x=720, y=150)
self.label_Img_seg = Label(self.root)
self.label_Img_seg.place(x=720, y=150)
Label(self.root, text="中心x坐标", font=10, bg="green").place(x=1050, y=120)
Label(self.root, text="中心y坐标", font=10, bg="green").place(x=1050, y=200)
self.root.mainloop()
def showOriginalPic(self):
self.path1 = askopenfilename(title='选择文件')
Img = Image.open(r'{}'.format(self.path1))
self.width, self.height = Img.size
self.width_scale = Scale(self.root, from_=0, to=self.width, orient=HORIZONTAL) # Scale组件
self.width_scale.place(x=1050, y=150)
self.height_scale = Scale(self.root, from_=0, to=self.height, orient=HORIZONTAL) # Scale组件
self.height_scale.place(x=1050, y=230)
print(self.width, self.height)
Img = Img.resize((270,270), Image.ANTIALIAS) # 调整图片大小至270x270
img_png_original = ImageTk.PhotoImage(Img)
self.label_Img_original1.image = img_png_original # keep a reference
self.cv_orinial1.create_image(5, 5,anchor='nw', image=img_png_original)
def maxMirrorFunc(self):
img = io.imread(self.path1)
save_name = self.path1.replace(".jpg", "_save.jpg").replace(".png", "_save.png")
final_img = maxMirror(img, self.width_scale.get(), self.height_scale.get(), radius=400)
print(type(final_img))
# final_img = final_img[..., ::-1]
io.imsave(save_name, final_img)
Img = Image.open(r'{}'.format(save_name))
Img = Img.resize((270, 270), Image.ANTIALIAS) # 调整图片大小至256x256
img_png_seg = ImageTk.PhotoImage(Img)
self.label_Img_seg.config(image=img_png_seg)
self.label_Img_seg.image = img_png_seg # keep a reference
def minMirrorFunc(self):
img = io.imread(self.path1)
save_name = self.path1.replace(".jpg", "_save.jpg").replace(".png", "_save.png")
final_img = minMirror(img, self.width_scale.get(), self.height_scale.get(), radius=200)
print(type(final_img))
# final_img = final_img[..., ::-1]
io.imsave(save_name, final_img)
Img = Image.open(r'{}'.format(save_name))
Img = Img.resize((270, 270), Image.ANTIALIAS) # 调整图片大小至256x256
img_png_seg = ImageTk.PhotoImage(Img)
self.label_Img_seg.config(image=img_png_seg)
self.label_Img_seg.image = img_png_seg # keep a reference
def quit(self):
self.root.destroy()
if __name__ == '__main__':
HaHaMirror()
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn