Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add files via upload #54

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
227 changes: 227 additions & 0 deletions paint_robot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
#!/usr/bin/env python
#-*- coding: utf-8 -*-

import os
from time import sleep
from tkinter import *
import tkinter.messagebox
from PIL import Image, ImageTk

my_dir = os.path.abspath('.')
print (my_dir)

def my_resize(img, width,height):
(w,h) = img.size
#print(img.size)
if w*height > h*width:
img2 = img.resize(( width, int(width*h/w)),Image.ANTIALIAS)
elif w*height < h*width:
img2 = img.resize(( int(w*height/h), height),Image.ANTIALIAS)
else:
img2 = img.resize((width,height),Image.ANTIALIAS)
#print(img2.size)
return img2

top = Tk()#窗口定义
top.title('Paint_robot')#窗口标题
top.geometry('1200x600')#窗口大小

cwd = StringVar()
cwd.set(os.curdir)
last = cwd.get()

dirl = Label(top, fg='blue',font=('Helvetica', 12, 'bold'))#显示当前路径的标签
dirl.place(x = 10, y = 10, anchor = NW)#放置标签

dirfm = Frame(top)#框架

dirsb = Scrollbar(dirfm,orient=VERTICAL)#滚动条
dirsb.pack(side=RIGHT, fill=Y)#滚动条放置

dirs = Listbox(dirfm, height=15,width=30, yscrollcommand=dirsb.set)#列表

def setdirandgo(ev=None):
global last
global dirs
global cwd
global imglabel
global img
global img_
global photo
last = cwd.get()
dirs.config(selectbackground='red')#选中之后颜色变红
check = dirs.get(dirs.curselection())
if not check:
check = os.curdir
cwd.set(check)#将cwd置为选中的项
#print (check)
image_addr = check[-3:]
if image_addr == 'png' or image_addr == 'jpg':
img_ = Image.open(check)
img = my_resize(img_,400,550)
photo = ImageTk.PhotoImage(img)
imglabel["image"] = photo
top.update()
dols()#执行dols

dirs.bind('<Double-1>', setdirandgo)#绑定函数 setdirandgo,点击鼠标两次
dirsb.config(command = dirs.yview)#滚动条与列表同步
dirs.pack(side=LEFT, fill=BOTH)#列表填充

dirfm.place(x = 10,y = 40,anchor = NW)#放置框架

def dols(ev=None):
tdir = cwd.get()
if not tdir:
tdir = os.curdir
if not os.path.exists(tdir):
error = tdir + ': no such file'#如果不存在这个路径
cwd.set(error)#cwd置为error
top.update()#更新窗口
sleep(2)
cwd.set(last)
dirs.config(selectbackground='LightSkyBlue')
top.update()
return
elif os.path.isdir(tdir):
dirlist = os.listdir(tdir)
dirlist.sort()
os.chdir(tdir)
dirl.config(text=os.getcwd())
dirs.delete(0, END)
dirs.insert(END, os.curdir)
dirs.insert(END, os.pardir)
i = 1
for eachFile in dirlist:
if os.path.isdir(eachFile):
dirs.insert(END, eachFile)
i+=1
dirs.itemconfig(i,fg = 'Olive')
for eachFile in dirlist:
image_addr = eachFile[-3:]
if image_addr == 'png' or image_addr == 'jpg':
dirs.insert(END, eachFile)
i+=1
dirs.itemconfig(i,fg = 'DeepSkyBlue')
cwd.set(os.curdir)
dirs.config(selectbackground='LightSkyBlue')

cfm = Frame(top,height = 600, width = 550)

textlabel = Label(cfm, fg='blue',font=('Helvetica', 12, 'bold'),text = 'The picture to be changed')
textlabel.pack()

rt = my_dir + '\\img\\use\\welcome.jpg'
img_ = Image.open(rt)
img = my_resize(img_,400,550)
photo = ImageTk.PhotoImage(img)
imglabel = Label(cfm, image = photo)
imglabel.pack()

cfm.place(x = 250, y = 0, anchor = NW)

rt = my_dir + '\\img\\use\\white.jpg'
img_st = Image.open(rt)
img_style = my_resize(img_st,300,180)
photo_style = ImageTk.PhotoImage(img_style)
imglabel_style = Label(top,image = photo_style)
imglabel_style.place(x = 650,y = 580, anchor = 'se')
#imglabel_style.pack()

dfm = Frame(top,height = 600,width = 550)

textlabel2 = Label(dfm, fg='blue',font=('Helvetica', 12, 'bold'),text = 'The picture after changing style')
textlabel2.pack()

rt = my_dir + '\\img\\use\\blank.jpg'
img2_ = Image.open(rt)
img2 = my_resize(img2_,400,550)
photo2 = ImageTk.PhotoImage(img2)
imglabel2 = Label(dfm, image = photo2)
imglabel2.pack()

dfm.place(x = 800, y = 0, anchor = NW)

bfm = Frame(top,height = 10,width = 30)
dirn = Entry(bfm, width=30,textvariable = cwd)#输入框,变量为 cwd
dirn.bind('<Return>', dols)#绑定函数 dols,返回时运行
dirn.pack()#放置输入框

bfm.place(x = 10,y = 330,anchor = NW)

def clrdir():
cwd.set('')# 让cwd清零

clr = Button(bfm, width = 7,text='Clear',command=clrdir,activeforeground='white',activebackground='blue')#清除按钮
ls = Button(bfm,width = 12,text='List Directory',command=dols,activeforeground='white',activebackground='green')#列表按钮
quit = Button(bfm, width = 8,text='Quit',command=top.quit,activeforeground='white',activebackground='red')#退出按钮
clr.pack(side=LEFT)
ls.pack(side=LEFT)
quit.pack(side=LEFT)#放置按钮
bfm.place(x = 10,y = 330,anchor = NW)

def cubist():
addr = cwd.get()

def showresult(model_type):
global img2
global photo2
global imglabel2
global img2_
global img_st
global img_style
global photo_style
global imglabel_style

print(model_type)

rute = my_dir + '\\img\\style\\' + model_type + '.jpg'
img_st = Image.open(rute)
img_style = my_resize(img_st,300,180)
photo_style = ImageTk.PhotoImage(img_style)
imglabel_style["image"] = photo_style
top.update()

image_file = cwd.get()
#如果发现图片错误,则出现提示
if len(image_file) > 4:
tail = image_file[-3:]
if tail == 'png' or tail == 'jpg':

model_file = my_dir + '\\models\\' + model_type + '.ckpt-done'
print(model_file)
op = 'python eval.py --model_file ' + model_file + ' --image_file ' + image_file
print(op)
os.system(op)
#出现一个正在运行的消息框
rute = my_dir + '\\generated\\' + image_file
print(rute)
img2_ = Image.open(rute)
img2 = my_resize(img2_,400,550)
photo2 = ImageTk.PhotoImage(img2)
imglabel2["image"] = photo2
top.update()
else:
tkinter.messagebox.showerror('ERROR','Please enter the right picture.')
else:
tkinter.messagebox.showerror('ERROR','Please enter the right picture.')


efm = Frame(top,height = 500,width = 10)
cubist_b = Button(efm,text='Cubist',width=10,command =lambda : showresult('cubist'),activeforeground='white',activebackground='blue')
starry_b = Button(efm,text='Starry',width=10,command =lambda : showresult('denoised_starry'),activeforeground='white',activebackground='blue')
feather_b = Button(efm,text='Feather',width=10,command =lambda : showresult('feathers'),activeforeground='white',activebackground='blue')
mosaic_b = Button(efm,text='Mosaic',width=10,command =lambda : showresult('mosaic'),activeforeground='white',activebackground='blue')
scream_b = Button(efm,text='Scream',width=10,command =lambda : showresult('scream'),activeforeground='white',activebackground='blue')
udnie_b = Button(efm,text='Udnie',width=10,command =lambda : showresult('udnie'),activeforeground='white',activebackground='blue')
wave_b = Button(efm,text='Wave',width=10,command =lambda : showresult('wave'),activeforeground='white',activebackground='blue')
cubist_b.pack()
starry_b.pack()
feather_b.pack()
mosaic_b.pack()
scream_b.pack()
udnie_b.pack()
wave_b.pack()
efm.place(x = 685,y = 200,anchor = NW)
dols()
mainloop()
61 changes: 61 additions & 0 deletions sim.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#coding=utf-8

import pytesseract
from pytesser import *
from PIL import Image,ImageEnhance,ImageFilter
import os
import fnmatch
import re,time

import urllib, random


#import hashlib

def getGray(image_file):
tmpls=[]
for h in range(0, image_file.size[1]):#h
for w in range(0, image_file.size[0]):#w
tmpls.append( image_file.getpixel((w,h)) )

return tmpls

def getAvg(ls):#获取平均灰度值
return sum(ls)/len(ls)

def getMH(a,b):#比较100个字符有几个字符相同
dist = 0;
for i in range(0,len(a)):
if a[i]==b[i]:
dist=dist+1
return dist

def getImgHash(fne):
image_file = Image.open(fne) # 打开
image_file=image_file.resize((12, 12))#重置图片大小我12px X 12px
image_file=image_file.convert("L")#转256灰度图
Grayls=getGray(image_file)#灰度集合
avg=getAvg(Grayls)#灰度平均值
bitls=''#接收获取0或1
#除去变宽1px遍历像素
for h in range(1, image_file.size[1]-1):#h
for w in range(1, image_file.size[0]-1):#w
if image_file.getpixel((w,h))>=avg:#像素的值比较平均值 大于记为1 小于记为0
bitls=bitls+'1'
else:
bitls=bitls+'0'
return bitls
'''''
m2 = hashlib.md5()
m2.update(bitls)
print m2.hexdigest(),bitls
return m2.hexdigest()
'''


a=getImgHash("jay.png")#图片地址自行替换
files = os.listdir(".//generated")#图片文件夹地址自行替换
for file in files:
b=getImgHash(".//generated//"+str(file))
compare=getMH(a,b)
print (file,u'相似度',str(compare)+'%')
Binary file added 论文.pdf
Binary file not shown.