python - 开放简历。如何跟踪沉积物的速度
问题描述
我正在编写一个脚本来确定量筒中的沉降速度。我制作了一个间隔为 30 秒的延时视频。在您看到的图像上,左侧有 3 张图片 t0,而在 Richt 3 上则有更远的时间。我想确定沉降速度,但找不到解决问题的代码。
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()
解决方案
推荐阅读
- blazor - Blazor,可选表行内的可选复选框
- reactjs - 我使用 expo CLI 在 reactjs 中创建了我的第一个应用程序,并在尝试启动它时出现此错误
- python-3.x - 无法使用 pulumi 在 aws 上通过事件桥触发 lambda
- amazon-web-services - “aws cloudformation delete-stack”不能使用 SAM CLI 使用的 StackName?
- c - 使用 realloc 的问题(旧大小)
- sql - 如何在 sequelize 中使用 group by 与当前年份月份和另一个数据字段
- chainlink - 在 Chainlink Keepers 中为 performUpkeep() 编码字节数组
- linux-kernel - 如何使用自定义内核 5.10 (PREEMPT RT) 构建 raspbian
- flutter - 为什么我的数组中的数据没有被正确评估?
- ios - Swift - AVSpeechSynthesizer - 如何运行回调 onError