使用Webcam OpenCV连接多条线到屏幕中心的blob

2024-09-27 00:13:41 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用OpenCV BlobDetection来检测出现在我的网络摄像头上的blob。我正在尝试使用cv2.arrowedLine函数从每个blob的中心到屏幕中间绘制线。你知道吗

我使用

pts = [k.pt for k in keypoints]

当我尝试使用

cv2.arrowedLine(img=frame, pt1=(centre), pt2=(int(pts)), color=(0,0,255), thickness=2)

什么都没出现。你知道吗

有解决办法吗? 非常感谢你的帮助。你知道吗


Tags: 函数in网络ptfor屏幕绘制中心
1条回答
网友
1楼 · 发布于 2024-09-27 00:13:41

也许先来点代码

# Standard imports
import cv2
import numpy as np

# Read image
im = cv2.imread("blob.jpg", cv2.IMREAD_GRAYSCALE)

# Set up the detector with default parameters.
detector = cv2.SimpleBlobDetector_create()

# Detect blobs.
keypoints = detector.detect(im)

我想你已经走了这么远。现在,当你运行以下行

pts = [k.pt for k in keypoints]

pts是[(x, y), (x, y), ... ]形式的坐标元组列表。Opencv无法在单个点center和点列表之间绘制箭头。因此,我们必须以for循环的形式进行检查

pts = [k.pt for k in keypoints]
centre = (200, 320) # This should be changed to the center of your image

for pt in pts:
    pt = tuple(map(int, pt))
    cv2.arrowedLine(img=im, pt1=(centre), pt2=(pt), color=(0, 0, 255), thickness = 2)

pt = tuple(map(int, pt))用于将列表中的所有数字映射为整数。仅仅调用int(list)是行不通的。你知道吗

如果你再看看结果,我想这是你想要的。你知道吗

# Show keypoints
cv2.imshow("Keypoints", im)
cv2.waitKey(0)

blobs before arrowsblobs with arrows

相关问题 更多 >

    热门问题