小编Blu*_*ack的帖子

在两个给定点之间画线(OpenCV,Python)

我现在在这个问题上挣扎了一个小时......

我有一个里面有一个矩形的图像:

矩形

这是我为寻找角点而编写的代码:

import cv2
import numpy as np


img = cv2.imread('rect.png')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
gray = np.float32(gray)

points = cv2.goodFeaturesToTrack(gray, 100, 0.01, 10)
points = np.int0(points)

for point in points:
    x, y = point.ravel()
    cv2.circle(img, (x, y), 3, (0, 255, 0), -1)

print(points[0])
print(points[1])
print(points[2])
print(points[3])

cv2.imshow('img', img)
cv2.waitKey(0)
cv2.imwrite('rect.png', img)
Run Code Online (Sandbox Code Playgroud)

这是结果:

第一个

如您所见,它运行完美。我想要的是沿着上/下点(x1,x2 - x3,x4)画一条线。

我从现在开始生产的是这个......

cv2.line(img, (points[0]), (points[1]), (0, 255, 0), thickness=3, lineType=8)

cv2.imshow('img', img)
cv2.waitKey(0)
Run Code Online (Sandbox Code Playgroud)

但它不起作用。

任何的想法 ?

结果应该是这样的:

出去

两条线必须通过点的坐标。print(points[0])上面给出了下一个输出,例如:

[[561 168]]
[[155 168]] …
Run Code Online (Sandbox Code Playgroud)

python opencv point lines

7
推荐指数
2
解决办法
2万
查看次数

删除空文件夹 (Python)

这是文件夹树:

FOLDER\\
       \\1\\file
       \\2\\file
       \\3\\
       \\4\\file
Run Code Online (Sandbox Code Playgroud)

脚本应该扫描(循环)FOLDER 中的每个文件夹并检查子文件夹是否为空。如果是,则必须将其删除。

到目前为止,我的代码是这样的:

folders = ([x[0] for x in os.walk(os.path.expanduser('~\\Desktop\\FOLDER\\DIGITS\\'))])
folders2= (folders[1:])
Run Code Online (Sandbox Code Playgroud)

此扫描文件夹,并使用folders2DIGITS. 在DIGITS有编号的目录:1,2,3,4等

怎么办?尝试使用,os.rmdir但它给了我一个错误,关于字符串。其实folders2是一个列表,不是一个字符串,只是说...

python directory

6
推荐指数
4
解决办法
1万
查看次数

标签 统计

python ×2

directory ×1

lines ×1

opencv ×1

point ×1