我正在研究一个检测人的项目。因此,我在 opencv 中使用显着性,并对显着性的输出应用 k 均值聚类。
问题是应用 k-means 聚类后的输出是全黑的
这是代码:
import cv2
import time
import numpy as np
cap=cv2.VideoCapture("video.avi")
while(cap.isOpened()):
#time.sleep(0.05)
_,frame=cap.read()
image=frame
saliency = cv2.saliency.StaticSaliencySpectralResidual_create()
(success, saliencyMap) = saliency.computeSaliency(image)
saliencyMap = (saliencyMap * 255).astype("uint8")
#cv2.imshow("Image", image)
#cv2.imshow("Output", saliencyMap)
saliency = cv2.saliency.StaticSaliencyFineGrained_create()
(success, saliencyMap) = saliency.computeSaliency(image)
threshMap = cv2.threshold(saliencyMap.astype("uint8"), 0, 255,cv2.THRESH_BINARY | cv2.THRESH_OTSU)[1]
# show the images
#cv2.imshow("Image", image)
cv2.imshow("saliency", saliencyMap)
#cv2.imshow("Thresh", threshMap)
##############implementing k-means clustering#######################
kouts=saliencyMap
clusters=7
z=kouts.reshape((-1,3))
z=np.float32(z)
criteria= (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER,10,1.0)
ret,label,center=cv2.kmeans(z,clusters,None,criteria,10,cv2.KMEANS_RANDOM_CENTERS)
center=np.uint8(center)
res=center[label.flatten()]
kouts=res.reshape((kouts.shape))
cv2.imshow('clustered image',kouts)
k = cv2.waitKey(1) & 0xff
if k == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
有人可以指出任何错误或更正吗?
SMILET
相关分类