首页 > 解决方案 > 开放简历。如何跟踪沉积物的速度

问题描述

我正在编写一个脚本来确定量筒中的沉降速度。我制作了一个间隔为 30 秒的延时视频。在您看到的图像上,左侧有 3 张图片 t0,而在 Richt 3 上则有更远的时间。我想确定沉降速度,但找不到解决问题的代码。

左 3 张图像 t0,右 t7

import cv2
import numpy as np
# import numpy as np
cnt = []
cap = cv2.VideoCapture('/Users/nite.mp4')


ret, frame1 = cap.read()
frame1 = cv2.cvtColor(frame1, cv2.COLOR_BGR2GRAY)

#hoogte,hoogte+ ..... breedte,breedte+
cropped1 = frame1[300:800, 920:1000]
cv2.imshow("cropped first frame", cropped1)

bg = None #achtergrond reference eerste frame

# Settings
interval = 5
active_line = None
frame_counter = 0
last_frame_number = 0

s_per_frame = 1 / 2  # FPS = 2
m_per_pixel = 0.11 / 264  # in meter afstand per pixel
distance = m_per_pixel * interval   #distance per measurement

velocities = list()
distances = list()

while(cap.isOpened()):
    contour_sum = 0
    ret, frame = cap.read()


    hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    cropped = frame[300:800, 920:1000]
    cv2.imshow('cropped',cropped)
        
    if bg is None:
        bg = cropped
        #bg = frame

    if active_line is None:
        active_line = cropped.shape[1] - 120
                
                
    # Haal nieuwe plaatje van eerste plaatje af
    subtracted = cv2.subtract(cropped, bg)
    cv2.imshow('subtracted',subtracted)
    # define a threshold, 128 is the middle of black and white in grey scale
    thresh = 50

    # assign blue channel to zeros 0 is black 255 is white
    ret, img_binary = cv2.threshold(subtracted, thresh, 255, 0)
    cv2.imshow('tresh',img_binary)      
    img_height = img_binary.shape[0]
        
    # canny = cv2.Canny(subtracted, 20,40)
    # cv2.imshow('canny', canny)
    # kernel = np.ones((5,5))
    # dilated = cv2.dolate()
         
    key = cv2.waitKey(1)
    if key == ord ('d'):
        break
    if key == ord('p'):
        cv2.waitKey(-1)    


cap.release()
cv2.waitKey(0)

cv2.destroyAllWindows()

标签: pythonopencv

解决方案


推荐阅读