图片有四个值,a为这四个值横坐标,b为纵坐标,c为四个值,都一一对应,因为图片可能有稍微倾斜,所以只按照a从小到大的顺序输出c会顺序不同,想从左到右从上到下的输出c该怎么做
第一种方法把图片摆正,第二种就是从行列最小的开始在图片上搜,有没有这个点
计算图片的中心,把x,y结合起来排序。
# 构建图片轮廓中心点的list 并使用python lambda表达式进行排序
ms = [cv2.moments(c) for c in cnts]
centors = [[int(M["m10"] / M["m00"]), int(M["m01"] / M["m00"])] for M in ms]
print(centors)
my_sorted_list = sorted(centors, key=lambda item: (item[0], item[1]))
可参考: https://blog.csdn.net/qq_40985985/article/details/119777827