资源简介
利用python进行图片裁剪,并设置有部分重叠区域,消除裁剪时的黑边。

代码片段和文件信息
import numpy as np
from PIL import Image
import os
import cv2
import matplotlib.pyplot as plt
import math
Image.MAX_IMAGE_PIXELS = 400000000
imagedir = ‘E:/sample/‘
savedir = ‘E:/cutresult/‘
imagelist = os.listdir(imagedir)
for i in range(0len(imagelist)):
path = os.path.join(imagedirimagelist[i])
filename = os.path.splitext(imagelist[i])[0]
filetype = os.path.splitext(imagelist[i])[1]
image = cv2.imread(path)
imagesize = image.shape
width = imagesize[1]
height = imagesize[0]
# image = Image.open(path)
# plt.imshow(image)
# plt.show()
# width = image.size[0]
# height = image.size[1]
numwidth = (math.ceil((width-500)/400)) + 1
numheight = (math.ceil((height-500)/400)) + 1
print(numwidth)
print(numheight)
for numH in range (0numheight):
up = 400 * numH
down = up + 500
for numW in range (0numwidth):
left = 400 * numW
right = left + 500
if numH == 0 and numW == 0:
box = [00500500]
elif numH == 0 and numW > 0:
if right > width:
box = [(width -500)0(width)500]
else:
box = [left0right500]#
else:
if right < width and down < height:
box = [leftuprightdown]
elif right > width and down < height:
box = [(width - 500)upwidthdown]
elif right < width and down > height:
box = [left(height - 500)rightheight]
else:
box = [(width - 500)(height - 500)widthheight]
#print (box)#
numH = ‘{:0>2d}‘.format(int(numH))
i = ‘{:0>2d}‘.format(int(i))
numW = ‘{:0>2d}‘.format(int(numW))
cutresult = os.path.join(savedirstr(i)+str(numH)+str(numW)+‘.png‘)
#newimage = image[box[0]:box[1]box[2]:box[3]]
newimage = image[box[1]:box[3]box[0]:box[2]]
#print (newimage)
cv2.imwrite(cutresultnewimage)
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2018-09-13 14:00 imagecunt\
文件 1816 2018-09-13 13:59 imagecunt\imagecut500.py
- 上一篇:RasaCore官方文档中文版
- 下一篇:Python调用QQ微信截图
相关资源
- 7.图像风格迁移 基于深度学习 pyt
- dronet源码+论文(深度学习)
- 012345手势识别神经网络代码
- 深度学习(SPOT-RNA)
- 深度学习YOLOv3分类算法
- Deep Learning Cookbook_ practical recipes to g
- 深度学习视频中的行为识别
- deep learning with python 中文版
- 吴恩达深度学习超参数调制完整程序
- 深度学习入门 基于python理论与实现
- Python-基于深度学习的语音增强使用
- 《深度学习Deep Learning with Python 2017》
- 深度学习进阶:自然语言处理
- 基于深度学习堆栈自动编码器模型的
- 深度学习入门:基于python的理论与实
- 吴恩达深度学习1-21-31-42-1编程作业线
- 基于Python的深度学习
- 安全帽检测detect.7z
- deep_learning_with_python.pdf(Jason Brownlee)
- 人脸识别python代码187268
- Make Your Own Neural Network - 搭建自己的神
- BrownLee Better Deep Learning
- python 直方图规定化代码
- 简单粗暴 TensorFlow
- 5. 深度学习中的目标检测 python代码实
- 深度学习入门:基于Python的理论与实
- Deep Learning from Scratch中文名:深度学习
- Deep Learning for Natural Language Processing.
- 字符型图片数字验证码识别完整过程
- Python深度学习122512
评论
共有 条评论