J_y*_*ang 12 python opencv blob image-processing keypoint
我按照blob检测示例(使用cv2.SimpleBlobDetector)并成功检测到二进制图像中的斑点.但后来我不知道如何提取关键点的坐标和面积.以下是blob检测的代码:
# I skipped the parameter setting part.
blobParams = cv2.SimpleBlobDetector_Params()
blobVer = (cv2.__version__).split('.')
if int(blobVer[0]) < 3:
detector = cv2.SimpleBlobDetector(blobParams)
else:
detector = cv2.SimpleBlobDetector_create(blobParams)
# Detect Blobs
keypoints_black = detector.detect(255-black_blob)
trans_blobs = cv2.drawKeypoints(gray_video_crop, \
keypoints_white, np.array([]), (0,0,255), cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
Run Code Online (Sandbox Code Playgroud)
因此变量keypoints_black包含blob的信息.当我打印变量时,它看起来像这样(发现了2个blob):
KeyPoint 0x10b10b870, KeyPoint 0x10b1301b0
Run Code Online (Sandbox Code Playgroud)
那么如何获得关键点及其区域的质心坐标,以便我可以将它们作为osc消息发送以进行交互.
Joã*_*ulo 11
该pt属性:
keypoints = detector.detect(frame) #list of blobs keypoints
x = keypoints[i].pt[0] #i is the index of the blob you want to get the position
y = keypoints[i].pt[1]
Run Code Online (Sandbox Code Playgroud)
如果您有关键点列表.然后您可以打印如下所示
for keyPoint in keyPoints:
x = keyPoint.pt[0]
y = keyPoint.pt[1]
s = keyPoint.size
Run Code Online (Sandbox Code Playgroud)
编辑:大小确定有意义的关键点邻域的直径.您可以使用该大小并粗略计算blob的面积.
| 归档时间: |
|
| 查看次数: |
22969 次 |
| 最近记录: |