python - 如何让轮廓第一个坐标始终位于左上角?
问题描述
好的,所以我的轮廓总是矩形或正方形,所以我每个只有 4 个坐标([top_left,bottom_left,bottom_right,top_right])。但是对于某些轮廓,第一个坐标不是 top_left 上的坐标,它可以从 4 个角中的任何一个开始。我怎样才能让他们每次都从一个角落开始?
以下是数字代表坐标顺序的图片: https ://i.imgur.com/bPt7Wah.png
我使用这些坐标来裁剪图像,但如果坐标的顺序不正确,它就不起作用。这是裁剪的代码:
def get_colors(img, squares):
for square in squares:
x0, y0 = square[0]
x1, y1 = square[1]
x2, y2 = square[2]
x3, y3 = square[3]
top_left_x = max([x0, x1])
top_left_y = max([y0, y3])
bot_right_x = min([x2, x3])
bot_right_y = min([y1, y2])
croped = img[top_left_y:bot_right_y, top_left_x:bot_right_x]
解决方案
推荐阅读
- python - 如何解决“int”对象不可调用错误
- windows - ism 文件中设置的 INSTALLSOURCE 属性在哪里
- flutter - 有条件的颜色变化 Dart Flutter
- amazon-web-services - 在 AWS IOT 核心 (MQTT) 中接收长影文档时出错
- flutter - 如何使用 intl_phone_number_input 使国家代码进入 Flutter 的表单字段中
- javascript - 如何以角度解决“无法在模块外使用导入语句”
- delphi - 如何在 TGrid 的单元格中渲染 TBitmap 图像?
- ffmpeg - 通过 mlt xml 传递 ffmpeg 选项
- kibana - 在 Vega Spec 中将字符串解析为 JSON 对象
- docker - 错误:找不到文件:github 操作 CI 构建中的“docker”