Jos*_*key 3 algorithm opencv python-3.x
我已经使用 openCV 处理了图像以获得图像图案。图像图案分别由水平线和垂直线的 2 个Python列表表示。线条代表图案的边界。
fx = horizontal lines
fy = vertical lines
每个列表根据距图像左上角的距离按顺序排列。接下来,我使用以下命令来计算这些发现的线的交点:
def get_corners(fx,fy):
corners = []
for x_line in fx:
for y_line in fy:
corner = get_intersection(x_line,y_line)
if corner is not None:
corners.append(corner)
Run Code Online (Sandbox Code Playgroud)
这应该给我按从左到右、从上到下的corners
顺序(格式:) 。(x,y)
现在我想使用这些坐标从图像中裁剪出矩形。
列表的大小corners
各不相同并且模式堆叠,这意味着它们有共同点。给定点列表、线列表 和 的 和fx
大小fy
:
如何使用这些点来裁剪矩形?
get_corners()
如果需要,请随意更改。
下面是一个示例:模式检测在 2x2 中生成 4 个可能的矩形。这意味着列表points
中总共有 9 个值。
Points: [[],[],[],
[],[],[],
[],[],[]]
Run Code Online (Sandbox Code Playgroud)
我可以使用如下方式裁剪第一个矩形:
Points: [[],[],[],
[],[],[],
[],[],[]]
Run Code Online (Sandbox Code Playgroud)
在黑暗中刺伤,但这就是你的中间图像吗?我还假设您正在区分正方形和矩形,也就是说,您不需要正方形,只需要矩形。
如果是这种情况,我会使用以下步骤:
cnt_rectangles = 0
rectangle_list = []
for index in np.arange(len(points)-1):
p = points[index]
q = points[index+1]
if (p[0] == q[0]) || p[1] == q[1]
#the rectangle vertices must not have the same column or row. reject.
continue
else if abs(p[0] - q[0]) == abs(p[1] - q[1]):
#this is a square. reject
continue
else:
#this is a rectangle
cnt_rectangels+=1
rectangle_list.append((p, q))
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1933 次 |
最近记录: |