내 프레임 차이 (전경 감지)가 완벽하게 작동합니다. 이제 블롭 감지 기능을 추가하는 기능을 추가하겠습니다. 기본적으로, 제 생각은 검출 된 물체의 움직임에 얼룩 원을 형성하는 것입니다. 얼룩 감지 + 전경 감지
이
내 코드입니다 : 내 오류가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()
는 "이미지가 NumPy와의 arrary 아니라, 어느 스칼라"
예. 나는 그것을 고쳤다. 그러나 왜 빨간 원은 움직이는 물체를 추적하지 않습니다. 비디오의 한 지점에 고정되어 있습니다. –
@LeeAndroid 루프 끝 부분에서도'keypoints = detector.detect (current_frame) '를 추가하려고 했으므로 각 새로운 비디오 프레임에서 얼룩 탐지를 새로 고칠 수 있습니까? – Delgan
예. 나는 아직도 버그를 찾을 수 없습니다. 루프의 끝에 코드를 추가했습니다. 여전히 동일합니다. –