我的帧差分(前景检测)工作得很好。现在,我想给它添加一个额外的功能,那就是斑点检测。基本上,我的想法是在检测到的物体的运动上形成斑点圆。
这是我的代码:
import cv2
cap = cv2.VideoCapture('14.mp4')
ret, current_frame = cap.read()
previous_frame = current_frame
# Setup SimpleBlobDetector parameters.
params = cv2.SimpleBlobDetector_Params()
# Change blob detection thresholds
params.minThreshold = 200
params.maxThreshold = 255
params.minDistBetweenBlobs = 100
# Filter by Area.
params.filterByArea = True
params.minArea = 1200
params.maxArea = 40000
# Filter by Circularity
params.filterByCircularity = False
params.minCircularity = 0.1
# Filter by Convexity
params.filterByConvexity = False
params.minConvexity = 0.87
# Filter by Inertia
params.filterByInertia = True
params.minInertiaRatio = 0.02
# Create a detector with the parameters
detector = cv2.SimpleBlobDetector_create(params)
#Detect blobs
keypoints = detector.detect(current_frame)
while(cap.isOpened()):
current_frame_gray = cv2.cvtColor(current_frame, cv2.COLOR_BGR2GRAY)
previous_frame_gray = cv2.cvtColor(previous_frame, cv2.COLOR_BGR2GRAY)
frame_diff = cv2.absdiff(current_frame_gray,previous_frame_gray)
im_with_keypoints = cv2.drawKeypoints(frame_diff, keypoints, np.array([]), (0,0,255), cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
cv2.imshow('frame diff ',im_with_keypoints )
if cv2.waitKey(1) & 0xFF == ord('q'):
break
previous_frame = current_frame.copy()
ret, current_frame = cap.read()
keypoints = detector.detect(current_frame)
cap.release()
cv2.destroyAllWindows()
我的错误是"image不是数字数组,也不是标量“
https://stackoverflow.com/questions/38279741
复制相似问题