python open 判断图形进行分页截取

分析图像,在横向有一灰线,首先要判断位置,约在
480-530间,只有白色和灰线,则取500为判断点位,另外在两页间,有广告,广告高度小于200
广告与页面间也有灰线,判断小于200的,视为广告,不截取

import os
import cv2  #pip install opencv-python
# from matplotlib import pyplot as plt


def cut(start_y, end_y, width, number):
    save_path = "D:\\image"  + str(number) + ".png"
    page = img[start_y:end_y, 480:1424]
    print(save_path)
    cv2.imwrite(save_path, page)

#for image in os.listdir("../img"):
    # img_path = "./Book/" + image
    # img = cv2.imread(img_path)
img = cv2.imread(r'D:\\longpng.png',cv2.IMREAD_COLOR)		#opencv不支持中文,请使用英文名称
cv2.namedWindow("bug",cv2.WINDOW_AUTOSIZE)
cv2.imshow("bug",img)
cv2.waitKey(0)
cv2.destroyAllWindows()
# plt.imshow(img.real)
# plt.xticks([]), plt.yticks([])  # to hide tick values on X and Y axis
# plt.show()
# print(img)


height = img.shape[0]
width = img.shape[1]
print(height,width)
lines=[]
lines.append(0)

# 判断在500位置左右有一横线,RGB为233,233,233,【233或234】的值,按此分割
for point in range(0, height):
	px=img[point,500]
	if px[0]!=255:
		#print(px,point,500)
		lines.append(point)
lines.append(height)
print(lines)
page=1
for num in range(1,len(lines)):
	print('NO.',num)
	if abs(lines[num-1]-lines[num])>=200:
		cut(lines[num-1],lines[num],500,page)
		page+=1

原图在这里插入图片描述
分解的图片
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值