【发布时间】:2023-01-30 22:18:40
【问题描述】:
我有这个输入图像(请随意下载并尝试您的解决方案):
我需要找到最靠近左下角和右上角的点 A 和 B。而不是我想削减的形象。查看所需的输出:
到目前为止我有这个功能,但它没有正确找到点 A、B:
def CheckForLess(list1, val):
return(all(x < val for x in list1))
def find_corner_pixels(img):
# Get image dimensions
height, width = img.shape[:2]
# Find the first non-black pixel closest to the left-down and right-up corners
nonempty = []
for i in range(height):
for j in range(width):
# Check if the current pixel is non-black
if not CheckForLess(img[i, j], 10):
nonempty.append([i, 1080 - j])
return min(nonempty) , max(nonempty)
你能帮我吗?
【问题讨论】:
-
在此示例中,尝试使用定义范围的书籍颜色创建蒙版。然后使用 find_contour() 并获取边界
-
@AchilleG 我试过了,但它没有正确找到轮廓。也许我做错了什么,你能试试吗?
-
return min(nonempty) , max(nonempty) -> min() 不会在左下角找到你。代码必须找到最低的 y,它具有最低的 x 位置。不幸的是,这张图片中的“最低”点将具有较高的值,因为您的坐标十字可能位于左上角?