pointextractor.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:opentrack-prototyping 作者: DaMichel 项目源码 文件源码
def threshold_and_label_blobs(intensity, blob_list, threshold):
  # we cheat a little here because we take the list of
  # known blob locations to fill the thresholded areas
  # surrounding the blob centers. This way false blob detections
  # are avoided.
  assert(intensity.dtype == np.uint8)
  W, H = intensity.shape
  _, blobs_mask = cv2.threshold(intensity, threshold, 1, cv2.THRESH_BINARY)
  labels = 255 - blobs_mask
  for num, pk in enumerate(blob_list):
    iy, ix = int(pk.y), int(pk.x)
    if labels[ix, iy] < 254: # was the area under the blob location already filled by another blob?
        return None # overlapping non-separable blobs
    if labels[ix, iy] == 255:
        return None # blob center is not in thresholded area
    cv2.floodFill(labels.reshape((W, H, 1)), None, (iy, ix), (num,), (0,), (0,))
  labels[labels == 254] = 255 # everything not a proper blob is assigned label 255
  return labels
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号