Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 如何计算喷雾速度?密集光流_Python 3.x_Opencv_Video - Fatal编程技术网

Python 3.x 如何计算喷雾速度?密集光流

Python 3.x 如何计算喷雾速度?密集光流,python-3.x,opencv,video,Python 3.x,Opencv,Video,我正试图测量水雾的速度。 代码可以在这里看到: import cv2 import numpy as np # Get a VideoCapture object from video and store it in vs vc = cv2.VideoCapture('spray.avi') # Read first frame ret, first_frame = vc.read() # Scale and resize image resize_dim = 600 max_dim = ma

我正试图测量水雾的速度。 代码可以在这里看到:

import cv2

import numpy as np
# Get a VideoCapture object from video and store it in vs
vc = cv2.VideoCapture('spray.avi')
# Read first frame
ret, first_frame = vc.read()
# Scale and resize image
resize_dim = 600
max_dim = max(first_frame.shape)
scale = resize_dim / max_dim
first_frame = cv2.resize(first_frame, None, fx=scale, fy=scale)
# Convert to gray scale
prev_gray = cv2.cvtColor(first_frame, cv2.COLOR_BGR2GRAY)
# Create mask
mask = np.zeros_like(first_frame)
# Sets image saturation to maximum
mask[..., 1] = 255
out = cv2.VideoWriter('video.mp4', -1, 1, (600, 600))
while (vc.isOpened()):
    # Read a frame from video
    ret, frame = vc.read()
    # Convert new frame format`s to gray scale and resize gray frame obtained
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    gray = cv2.resize(gray, None, fx=scale, fy=scale)
    # Calculate dense optical flow by Farneback method
    # https://docs.opencv.org/3.0-beta/modules/video/doc/motion_analysis_and_object_tracking.html#calcopticalflowfarneback
    flow = cv2.calcOpticalFlowFarneback(prev_gray, gray, None, pyr_scale=0.5, levels=5, winsize=11, iterations=5,
                                        poly_n=5, poly_sigma=1.1, flags=0)
    # Compute the magnitude and angle of the 2D vectors
    magnitude, angle = cv2.cartToPolar(flow[..., 0], flow[..., 1])
    # Set image hue according to the optical flow direction
    mask[..., 0] = angle * 180 / np.pi / 2
    # Set image value according to the optical flow magnitude (normalized)
    mask[..., 2] = cv2.normalize(magnitude, None, 0, 255, cv2.NORM_MINMAX)
    # Convert HSV to RGB (BGR) color representation
    rgb = cv2.cvtColor(mask, cv2.COLOR_HSV2BGR)
    # Resize frame size to match dimensions
    frame = cv2.resize(frame, None, fx=scale, fy=scale)
    # Open a new window and displays the output frame
    dense_flow = cv2.addWeighted(frame, 1, rgb, 2, 0)
    cv2.imshow("Dense optical flow", dense_flow)
    #cv2.imshow("Initial video", vc )
    out.write(dense_flow)
    # Update previous frame
    prev_gray = gray
    # Frame are read by intervals of 1 millisecond. The programs breaks out of the while loop when the user presses the 'q' key
    if cv2.waitKey(10) & 0xFF == ord('q'):
        break
# The following frees up resources and closes all windows
vc.release()
cv2.destroyAllWindows()
我可以得到密集光流的视频。很好。 (见下图)

但我想找出速度剖面的实际数字

它在代码中的某个地方吗?我还没有理解它? 或者需要更多的补充来找到它们吗

谢谢


(代码来自此处:

您必须通过问题中的相关代码。请阅读和。您必须通过问题中的相关代码。请阅读和。