我怎样才能使发现减速?

问题描述 投票:-1回答:2

我想找到一个物体的速度。首先,我测量两个球通过那里和他们的差异找到长度。还有时间..最后我将长度分为时间,但速度要快......

我的问题是计算机在视频中很快找到轮廓。当我使用time.sleep()时,滞后开始于视频。我不想这样。我只希望“找到轮廓减速的速度”没有任何fps或滞后(我不知道)改变

for c in cnts :
    M = cv2.moments(c)
    cX = int(M["m10"] / M["m00"])
    cY = int(M["m01"] / M["m00"])
    x, y, w, h = cv2.boundingRect(c)
    cv2.rectangle(video, (x, y), (x + w, y + h), (0, 255, 0), 2)
    cv2.circle(video, (cX,cY),7,(255,255,255),-1)

if cX != cX1:
    start1 = time.time()
    Lenght = math.sqrt(abs(cX-cX1)*abs(cX-cX1)+abs(cY-cY1)*abs(cY-cY1))
    Time = start1-end1
    Velocity = Lenght/Time
    print(Velocity)
    end1 = time.time()
cX1 = cX
cY1 = cY
python opencv
2个回答
1
投票

您是否可以获得帧时间并在此值之间测量帧之间的速度:

_, frame1 = video.read()
t1 = video.get(cv2.CAP_PROP_POS_MSEC)
_, frame2 = video.read()
t2 = video.get(cv2.CAP_PROP_POS_MSEC)
diff_sec = (t2 - t1) / 1000.0

0
投票

好的,我修复了这段代码

for i in range(0,1):
    start2 = time.time()
    if start2-end2>1.0 :
        cnts,_ = cv2.findContours(video, cv2.RETR_TREE , cv2.CHAIN_APPROX_SIMPLE)
    end2 = time.time()
© www.soinside.com 2019 - 2024. All rights reserved.