我试图找到在不同帧中检测到的所有对象,我认为这将给出阈值中检测到的每个区域的列表,但是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))
相关代码可以从这里测试
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()