Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
OpenCV python的Blob ID标记_Python_Opencv_Image Processing_Cvblobslib - Fatal编程技术网

OpenCV python的Blob ID标记

OpenCV python的Blob ID标记,python,opencv,image-processing,cvblobslib,Python,Opencv,Image Processing,Cvblobslib,我目前正在为有方向的人员编制python代码。我使用了“矩”方法来收集坐标,最终当它穿过某条线时,计数器会递增。但是,这种方法被证明是非常低效的。关于斑点检测,我的问题是: python opencv是否有任何blob检测技术?或者可以用cv2.findContours完成? 我正在研究raspberry pi,所以有人能建议如何在debian linux上获取blob库吗 即使有,我如何为每个blob获得唯一的ID?是否有任何算法提供唯一ID的标记 如果有更好的方法,请推荐一种算法 提前感谢。

我目前正在为有方向的人员编制python代码。我使用了“矩”方法来收集坐标,最终当它穿过某条线时,计数器会递增。但是,这种方法被证明是非常低效的。关于斑点检测,我的问题是:

  • python opencv是否有任何blob检测技术?或者可以用cv2.findContours完成? 我正在研究raspberry pi,所以有人能建议如何在debian linux上获取blob库吗
  • 即使有,我如何为每个blob获得唯一的ID?是否有任何算法提供唯一ID的标记
  • 如果有更好的方法,请推荐一种算法

  • 提前感谢。

    对于斑点检测,您可以使用OpenCV中的SimpleBlobDetector:

    # Setup SimpleBlobDetector parameters.
    params = cv2.SimpleBlobDetector_Params()
    
    # Filter by Area.
    params.filterByArea = True
    params.minArea = 100
    params.maxArea =100000
    
    # Don't filter by Circularity
    params.filterByCircularity = False
    
    # Don't filter by Convexity
    params.filterByConvexity = False
    
    # Don't filter by Inertia
    params.filterByInertia = False
    
    
    # Create a detector with the parameters
    detector = cv2.SimpleBlobDetector_create(params)
    
    # Detect blobs.
    keypoints = detector.detect(imthresh)
    
    # Draw detected blobs as red circles.
    # cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS ensures
    # the size of the circle corresponds to the size of blob
    im_with_keypoints = cv2.drawKeypoints(imthresh, keypoints, np.array([]), (0,0,255), cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
    
    对于标签,使用scipy.ndimage.label通常是一个更好的主意:

    label_im, nb_labels = ndimage.label(mask)
    

    对于斑点检测,您可以使用OpenCV中的SimpleBlobDetector:

    # Setup SimpleBlobDetector parameters.
    params = cv2.SimpleBlobDetector_Params()
    
    # Filter by Area.
    params.filterByArea = True
    params.minArea = 100
    params.maxArea =100000
    
    # Don't filter by Circularity
    params.filterByCircularity = False
    
    # Don't filter by Convexity
    params.filterByConvexity = False
    
    # Don't filter by Inertia
    params.filterByInertia = False
    
    
    # Create a detector with the parameters
    detector = cv2.SimpleBlobDetector_create(params)
    
    # Detect blobs.
    keypoints = detector.detect(imthresh)
    
    # Draw detected blobs as red circles.
    # cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS ensures
    # the size of the circle corresponds to the size of blob
    im_with_keypoints = cv2.drawKeypoints(imthresh, keypoints, np.array([]), (0,0,255), cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
    
    对于标签,使用scipy.ndimage.label通常是一个更好的主意:

    label_im, nb_labels = ndimage.label(mask)
    

    真的谢谢你,伙计。你能详细说明标签部分需要做什么吗?这行就足够了,还是需要添加一些额外的行?抱歉,我是python新手。我已经给了你函数的名称,你可以很容易地在google上找到示例代码,例如:真的谢谢你。你能详细说明标签部分需要做什么吗?这行就足够了,还是需要添加一些额外的行?抱歉,我是python新手。我已经为您提供了函数的名称,您可以使用google轻松找到示例代码,例如: