首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >斑点检测+前景检测

斑点检测+前景检测
EN

Stack Overflow用户
提问于 2016-07-09 16:05:00
回答 3查看 493关注 0票数 1

我的帧差分(前景检测)工作得很好。现在,我想给它添加一个额外的功能,那就是斑点检测。基本上,我的想法是在检测到的物体的运动上形成斑点圆。

这是我的代码:

代码语言:javascript
复制
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不是数字数组,也不是标量“

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38279741

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档