parameters: (img)
docstring: 横向切割
docstring_summary: 横向切割
docstring_tokens: 横向切割
function: def horizontal_cut(img):
      """横向切割"""
      width, _ = img.size
      px = list(np.sum(np.array(img) == 0, axis=1))
      # 列表保存像素累加值大于0的行
      y0 = []
      for y in range(len(px)):
          if px[y] > 1:
              y0.append(y)
  
      # 找出边界
      cut_list = [y0[0]]
      for i in range(1, len(y0)):
          if abs(y0[i] - y0[i - 1]) > 1:
              cut_list.extend([y0[i - 1], y0[i]])
      cut_list.append(y0[-1])
  
      # 切割顺利的话应该是长度为4的list
      if len(cut_list) == 4:
          cut_img1 = img.crop([0, cut_list[0], width, cut_list[1]])
          cut_img2 = img.crop([0, cut_list[2], width, cut_list[3]])
          return [cut_img1, cut_img2]
      else:
          print('Horizontal cut failed.')
          return
function_tokens: def horizontal_cut ( img ) : width , _ = img . size px = list ( np . sum ( np . array ( img ) == 0 , axis = 1 ) ) # 列表保存像素累加值大于0的行 y0 = [ ] for y in range ( len ( px ) ) : if px [ y ] > 1 : y0 . append ( y ) # 找出边界 cut_list = [ y0 [ 0 ] ] for i in range ( 1 , len ( y0 ) ) : if abs ( y0 [ i ] - y0 [ i - 1 ] ) > 1 : cut_list . extend ( [ y0 [ i - 1 ] , y0 [ i ] ] ) cut_list . append ( y0 [ - 1 ] ) # 切割顺利的话应该是长度为4的list if len ( cut_list ) == 4 : cut_img1 = img . crop ( [ 0 , cut_list [ 0 ] , width , cut_list [ 1 ] ] ) cut_img2 = img . crop ( [ 0 , cut_list [ 2 ] , width , cut_list [ 3 ] ] ) return [ cut_img1 , cut_img2 ] else : print ( 'Horizontal cut failed.' ) return