我试图找到在不同帧中检测到的所有对象,我认为这将给出阈值中检测到的每个区域的列表,但是 find_objects给出一堆“无”和整个图像的范围?
...
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
(slice(0, 972, None), slice(0, 1296, None))
相关代码可从here 测试import numpy as np
import cv2
from matplotlib import pyplot as plt
import pylab
from scipy import ndimage
import os
for img in os.listdir('.'):
if img.endswith('.jpg'):
image = cv2.imread(img)
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
gray_image = cv2.resize(gray_image, (int(gray_image.shape[1]/2), int(gray_image.shape[0]/2) ))
ret, threshimg = cv2.threshold(gray_image,0,255,cv2.THRESH_BINARY)
cv2.imshow('opening',threshimg)
objects = ndimage.find_objects(threshimg)
for ob in objects:
print(ob)
cv2.waitKey(0) # Waits forever for user to press any key
cv2.destroyAllWindows()
最佳答案
scipy.ndimage.find_objects
函数返回
A list of tuples, with each tuple containing N slices (with N the dimension of the input array). Slices correspond to the minimal parallelepiped that contains the object. If a number is missing, None is returned instead of a slice.
我认为在您的数据中,标签不是从 1 开始的(0 是背景,被
find_objects
忽略)。不是 None 的条目的索引是对象的整数值。
关于python - 为什么 find_objects 会给出一堆无,然后是整个图像的范围?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62734440/