[Python] 纯文本查看 复制代码
import os
from tkinter import N
import cv2
#读取图片
def read():
for file in os.listdir(os.getcwd()):
if file.endswith("jpg") or file.endswith("jpeg") or file.endswith("png") or file.endswith("tif") or file.endswith("tif"):
break
return file
#入口
if __name__=="__main__":
file=read()
lname=os.path.splitext(file)[-1]
os.rename(file, "img" + lname)
img = cv2.imread("img" + lname)
os.rename("img" + lname, file)
#选择
def put():
k = input("\n "+read()+"""\n
1.三联画160x60(40x60 80x60 40x60)
2.三联画200x70(50x70 100x70 50x70)
3.三联画240x80(60x80 120x80 60x80)
4.三联画280x90(70x90 140x90 70x90)
5.四联画140x90(30x60 40x80 40x80 30x60)
6.四联画180x110(40x80 50x100 50x100 40x80)
7.四联画220x130(50x100 60x120 60x120 50x100)
8.五联画180x90(36x50 36x70 36x90 36x70 36x50)
9.五联画200x100(40x40 40x80 40x100 40x80 40x40)
10.五联画200x100(40x60 40x80 40x100 40x80 40x60)
11.五联画200x100(40x100 40x100 40x100 40x100 40x100)
12.五联画250x120(50x50 50x100 50x120 50x100 50x50)
13.五联画250x120(50x80 50x100 50x120 50x100 50x80)
14.五联画240x130(60x60 40x120 40x120 40x120 60x60)
15.五联画300x150(60x90 60x120 60x150 60x120 60x90)
请选择:""")
return k
k=put()
#切割
def qg(ns,names):
i=0
while i<len(names):
cv2.imwrite(names[i],ns[i],[cv2.IMWRITE_TIFF_RESUNIT,3,cv2.IMWRITE_TIFF_XDPI,100,cv2.IMWRITE_TIFF_YDPI,100])
i=i+1
return
#修改尺寸
def rsz(img,w,h):
n=cv2.resize(img, (w, h), interpolation=cv2.INTER_AREA)
return n
# 三联画160x60(40x60 80x60 40x60)
if k == '1':
n=rsz(img,16000,6000)
qg((n[0:6000, 0:4000],n[0:6000, 4000:12000],n[0:6000, 12000:16000]),('A6x60.tif','B80x60.tif','C40x60.tif'))
# 三联画200x70(50x70 100x70 50x70)
elif k == '2':
n=rsz(img,20000,7000)
qg((n[0:7000, 0:5000],n[0:7000, 5000:15000],n[0:7000, 15000:20000]),('A50x70.tif','B100x70.tif','C50x70.tif'))
# 三联画240x80(60x80 120x80 60x80)
elif k == '3':
n=rsz(img,24000,8000)
qg((n[0:8000, 0:6000],n[0:8000,6000:18000],n[0:8000, 18000:24000]),('A60x80.tif','B120x80.tif','C60x80.tif'))
# 三联画280x90(70x90 140x90 70x90)
elif k == '4':
n=rsz(img,28000,9000)
qg((n[0:9000, 0:7000],n[0:9000, 7000:21000],n[0:9000, 21000:28000]),('A70x90.tif','B140x90.tif','C70x90.tif'))
# 四联画140x90(30x60 40x80 40x80 30x60)
elif k == '5':
n=rsz(img,14000,9000)
qg((n[2000:8000, 0:3000],n[1000:9000, 3000:7000],n[0:8000, 7000:11000],n[1000:7000,11000:14000]),('A30x60.tif','B40x80.tif','C40x80.tif','D30x60.tif'))
# 四联画180x110(40x80 50x100 50x100 40x80)
elif k == '6':
n=rsz(img,18000,11000)
qg((n[2000:10000, 0:4000],n[1000:11000, 4000:9000],n[0:10000,9000:14000],n[1000:9000,14000:18000]),('A40x80.tif','B50x100.tif','C50x100.tif','D40x80.tif'))
# 四联画220x130(50x100 60x120 60x120 50x100)
elif k == '7':
n=rsz(img,22000,13000)
qg((n[2000:12000, 0:5000],n[1000:13000, 5000:11000],n[0:12000, 11000:17000],n[1000:11000, 17000:22000]),('A50x100.tif','B60x120.tif','C60x120.tif','D50x100.tif'))
# 五联画180x90(36x50 36x70 36x90 36x70 36x50)
elif k == '8':
n=rsz(img,18000,9000)
qg((n[2000:7000, 0:3600],n[1000:8000, 3600:7200],n[0:9000, 7200:10800],n[1000:8000, 10800:14400],n[2000:7000, 14400:18000]),('A36x50.tif','B36x70.tif','C36x90.tif','D36x70.tif','E36x50.tif'))
# 五联画200x100(40x40 40x80 50x100 40x80 40x40)
elif k == '9':
n=rsz(img,20000,10000)
qg((n[3000:7000, 0:4000],n[1000:9000, 4000:8000],n[0:10000, 8000:12000],n[1000:9000, 12000:16000],n[3000:7000, 16000:20000]),('A40x40.tif','B40x80.tif','C40x100.tif','D40x80.tif','E40x40.tif'))
# 五联画200x100(40x60 40x80 50x100 40x80 40x60)
elif k == '10':
n=rsz(img,20000,10000)
qg((n[2000:8000, 0:4000],n[1000:9000, 4000:8000],n[0:10000, 8000:12000],n[1000:9000, 12000:16000],n[2000:8000, 16000:20000]),('A40x60.tif','B40x80.tif','C40x100.tif','D40x80.tif','E40x60.tif'))
# 五联画200x100(40x100 40x100 40x100 40x100 40x100)
elif k == '11':
n=rsz(img,20000,10000)
qg((n[0:10000, 0:4000],n[0:10000, 4000:8000],n[0:10000,8000:12000],n[0:10000, 12000:16000],n[0:10000, 16000:20000]),('A40x100.tif','B40x100.tif','C40x100.tif','D40x100.tif','E40x100.tif'))
# 五联画250x120(50x50 50x100 50x120 50x100 50x50)
elif k == '12':
n=rsz(img,25000,12000)
qg((n[3500:8500, 0:5000],n[1000:11000, 5000:10000],n[0:12000, 10000:15000],n[1000:11000, 15000:20000],n[3500:8500, 20000:25000]),('A50x50.tif','B50x100.tif','C50x120.tif','D50x100.tif','E50x50.tif'))
# 五联画250x120(50x80 50x100 50x120 50x100 50x80)
elif k == '13':
n=rsz(img,25000,12000)
qg((n[2000:10000, 0:5000],n[1000:11000, 5000:10000],n[0:12000, 10000:15000],n[1000:11000, 15000:20000],n[2000:10000, 20000:25000]),('A50x80.tif','B50x100.tif','C50x120.tif','D50x100.tif','E50x80.tif'))
# 五联画240x130(60x60 40x120 40x120 40x120 60x60)
elif k == '14':
n=rsz(img,24000,13000)
qg((n[3500:9500, 0:6000],n[0:12000,6000:10000],n[1000:13000, 10000:14000],n[0:12000,14000:18000],n[3500:9500, 18000:24000]),('A60x60.tif','B40x120.tif','C40x120.tif','D40x120.tif','E60x60.tif'))
# 五联画300x150(60x90 60x120 60x150 60x120 60x90)
elif k == '15':
n=rsz(img,30000,15000)
qg((n[6000:24000, 0:6000],n[1500:13500, 6000:12000],n[0:15000, 12000:18000],n[1500:13500, 18000:24000],n[3000:12000, 24000:30000]),('A60x90.tif','B60x120.tif','C60x150.tif','D60x120.tif','E60x90.tif'))