# import image/array manipulation packages
import cv2
import numpy as np
# read image with OpenCV 2
img = cv2.imread("path/to/file/z4Xje.jpg")
# identify one line of pixels that has dashes
dashes = img[761,:,:]
# check where to split the picture and store that information
splits = [0]
for i in range(img.shape[0]):
# np.allclose allows you to have small differences between dashed lines
if np.allclose(img[i,:,:], dashes):
splits.append(i)
# add last split (height of picture)
splits.append(img.shape[0])
# write each cropped picture to your desired directory
for j in range(len(splits)-1):
new_img = img[splits[j]:splits[j+1],:]
cv2.imwrite("/path/to/export/"+str(j)+".jpg", new_img)
在@efirvida的评论之后,下面是一个非常基本的方法
它所做的只是检查给定图片中的每一行像素值是否等于包含虚线的第一行,然后裁剪图片以将其分割为多个图片
这当然不是一个完美的解决方案,但我希望它能为您提供如何改进当前算法的线索
它给了我这些你提供的照片:
相关问题 更多 >
编程相关推荐