我正在研究一個檢測人的項目。因此,我在 opencv 中使用顯著性,并對顯著性的輸出應(yīng)用 k 均值聚類。問題是應(yīng)用 k-means 聚類后的輸出是全黑的這是代碼:import cv2import timeimport numpy as npcap=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'):? ? ? ? breakcap.release()cv2.destroyAllWindows()有人可以指出任何錯誤或更正嗎?
在 cv2.saliency 上應(yīng)用 k-means 時出現(xiàn)問題
慕田峪7331174
2023-08-15 16:45:13