opencv 运行下面代码,可以看到如图
http://image.xujialiang.net/WX20180114-172635@2x.png很容易看出从第一行开始切割。。
import cv2
import numpy as np
import matplotlib.pyplot as plt
ori_img = cv2.imread('./TestData/' + '111.png')
im_gray = cv2.cvtColor(ori_img, cv2.COLOR_BGR2GRAY)
im_at_mean = cv2.adaptiveThreshold(im_gray, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, 5, 10)
cv2.imshow('im_at_mean' , im_at_mean)
im_at_mean_inv = cv2.bitwise_not(im_at_mean)
horizontal_sum = np.sum(im_at_mean_inv, axis=1)
plt.plot(horizontal_sum, range(horizontal_sum.shape[0]))
plt.gca().invert_yaxis()
plt.show()
cv2.waitKey(0)
cv2.destroyAllWindows()