# -*- coding: utf-8 -*-
"""
Created on Wed Nov 6 08:56:57 2019
@author: 01
"""
# -*- coding:utf-8 -*-
import MySQLdb
from hashlib import sha1
import tkinter
import tkinter.filedialog
import os
from PIL import ImageGrab
from time import sleep
from tkinter import *
import cv2
from PIL import Image,ImageTk
from tkinter.filedialog import askopenfilename
import json
import codecs
from tkinter.filedialog import askdirectory
import tkinter.messagebox
import sys,time
from tkinter import ttk
import numpy as np
#登录界面===============================================
def jiunu():
def cv_imread(filePath):
cv_img=cv2.imdecode(np.fromfile(filePath,dtype=np.uint8),-1)
## imdecode读取的是rgb,如果后续需要opencv处理的话,需要转换成bgr,转换后图片颜色会变化 ##cv_img=cv2.cvtColor(cv_img,cv2.COLOR_RGB2BGR)
return cv_img
# 创建tkinter主窗口
root = tkinter.Tk()
root.title('图片处理')
# 指定主窗口位置与大小
root.geometry('1000x800+100+50') # width x height + widthoffset + heightoffset
# 不允许改变窗口大小
root.resizable(False, False)
root.focusmodel()
def choosepic():
path_ = askopenfilename()
path.set(path_)
img_open = Image.open(file_entry.get())
img_open=img_open.resize((350,350))
img = ImageTk.PhotoImage(img_open)
image_label.config(image=img)
image_label.image = img # keep a reference
treeview.insert('', 0, values=(path_))
def choosepic1():
pat = askdirectory()
path.set(pat)
j=0
def choosepic2():
pat1 = askdirectory()
a=file_entry.get()
img_list=os.listdir(a)
ade=0
for i in img_list:
ww=a+"/"+i
img_array=cv_imread(ww)
print("chaungkuan",img_array.shape[0])
bili=int(int(img_array.shape[1]*300)/int(img_array.shape[0]))
new_array=cv2.resize(img_array,(bili,300))
save_path=pat1+"/"+str(ade)+".jpg"
cv2.imwrite(save_path,new_array)
ade=ade+1
xy_text1.set("执行完毕")
xy_text1 = StringVar()
path = StringVar()
tkinter.Button(root, text = '选择图片路径' ,command=choosepic1).place(x = 440, y = 155,w = 100, h = 40)
file_entry = Entry(root, state='readonly', text=path)
file_entry.place(x=20, y=55,width = 850, height = 40)
label1 =Label(root, textvariable=xy_text1,fg = 'blue')
label1.place(x=80, y=555,width = 850, height = 40)
path1 = StringVar()
tkinter.Button(root, text = '选择保存图片路径' ,command=choosepic2).place(x = 440, y = 355,w = 100, h = 40)
file_entry1 = Entry(root, state='readonly', text=path1)
file_entry1.place(x=20, y=255,width = 850, height = 40)
root.mainloop()
jiunu()