OpenCV从blob检测返回关键点坐标和区域,Python [英] OpenCV return keypoints coordinates and area from blob detection, Python

查看:3494
本文介绍了OpenCV从blob检测返回关键点坐标和区域,Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我按照blob检测示例(使用 cv2.SimpleBlobDetector )并成功检测到二进制图像中的斑点。但后来我不知道如何提取关键点的坐标和面积。以下是blob检测的代码:

I followed a blob detection example (using cv2.SimpleBlobDetector) and successfully detected the blobs in my binary image. But then I don't know how to extract the coordinates and area of the keypoints. Here are the code for the blob detections:

# 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)

因此变量 keypoints_black 包含blob的信息。当我打印变量时,它看起来像这样(找到2个blob):

So the variable keypoints_black contains the information of the blob(s). When I printed the variable it looked something like this (2 blobs were found):

KeyPoint 0x10b10b870, KeyPoint 0x10b1301b0

那么如何获取关键点及其区域的质心坐标,以便我可以将它们作为用于交互的osc消息。

So how to I get the coordinates of the centre of mass of the keypoints and their area so that I can send them as osc messages for interaction.

推荐答案

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]

某些文档

这篇关于OpenCV从blob检测返回关键点坐标和区域,Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆