-
-
Save chuanenlin/6c00fdd376e4f6d35cd2d596e1924001 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 as cv | |
import numpy as np | |
# Parameters for Shi-Tomasi corner detection | |
# feature_params = dict(maxCorners = 300, qualityLevel = 0.2, minDistance = 2, blockSize = 7) | |
# Parameters for Lucas-Kanade optical flow | |
# lk_params = dict(winSize = (15,15), maxLevel = 2, criteria = (cv.TERM_CRITERIA_EPS | cv.TERM_CRITERIA_COUNT, 10, 0.03)) | |
# The video feed is read in as a VideoCapture object | |
# cap = cv.VideoCapture("shibuya.mp4") | |
# Variable for color to draw optical flow track | |
# color = (0, 255, 0) | |
# ret = a boolean return value from getting the frame, first_frame = the first frame in the entire video sequence | |
# ret, first_frame = cap.read() | |
# Converts frame to grayscale because we only need the luminance channel for detecting edges - less computationally expensive | |
# prev_gray = cv.cvtColor(first_frame, cv.COLOR_BGR2GRAY) | |
# Finds the strongest corners in the first frame by Shi-Tomasi method - we will track the optical flow for these corners | |
# https://docs.opencv.org/3.0-beta/modules/imgproc/doc/feature_detection.html#goodfeaturestotrack | |
prev = cv.goodFeaturesToTrack(prev_gray, mask = None, **feature_params) | |
# while(cap.isOpened()): | |
# ret = a boolean return value from getting the frame, frame = the current frame being projected in the video | |
# ret, frame = cap.read() | |
# Converts each frame to grayscale - we previously only converted the first frame to grayscale | |
# gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY) | |
# Updates previous frame | |
# prev_gray = gray.copy() | |
# Frames are read by intervals of 10 milliseconds. The programs breaks out of the while loop when the user presses the 'q' key | |
# if cv.waitKey(10) & 0xFF == ord('q'): | |
# break | |
# The following frees up resources and closes all windows | |
# cap.release() | |
# cv.destroyAllWindows() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Secret your all codes in your minddisc....