Created
May 28, 2022 07:33
-
-
Save BuyMyMojo/2fdc6c7b7102419f0a16490cd86950d4 to your computer and use it in GitHub Desktop.
A basic method to measure video fps using OpenCV's countNonZero function.
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
def framerateMeasure(pngPath, csvPath, rate): | |
start = time() | |
differenceValues = [] | |
for i in range(rate): | |
differenceValues.append(0) | |
fields=['Frame','FPS'] | |
writeCSV(fields, csvPath) | |
j = 1 | |
# len(os.listdir(pngPath))-1 | |
for x in range(len(os.listdir(pngPath))-1): | |
img1 = cv.imread(pngPath + str(j) + ".png") | |
j = j + 1 | |
img2 = cv.imread(pngPath + str(j) + ".png") | |
difference = cv.subtract(img1, img2) | |
diffImg = cv.cvtColor(difference, cv.COLOR_BGR2GRAY) | |
nzCount = cv.countNonZero(diffImg) | |
if nzCount == 0: | |
# Dupe Frame | |
differenceValues.pop(0) | |
differenceValues.append(0) | |
else: | |
# New frame | |
differenceValues.pop(0) | |
differenceValues.append(1) | |
updateCSV(calcFPS(differenceValues), x, csvPath) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment