Created
April 16, 2020 09:40
-
-
Save jiristepan/aa40dc44214636bbe827e9040e1a04b7 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 numpy as np | |
import cv2 | |
# open capturing device and check | |
cap = cv2.VideoCapture("DJI160.MOV") | |
# define color range - bottom and top of color space in GBR (reverse RGB) | |
boundaries = ([00, 00, 123], [88, 88 , 190]) | |
frames=0 #frame counter | |
# main loop - frame by frame proceesing | |
while(True): | |
# Capture next frame | |
ret, frame = cap.read() | |
frame = frame + 1 | |
# create NumPy arrays from the color boundaries | |
lower = np.array(boundaries[0], dtype = "uint8") | |
upper = np.array(boundaries[1], dtype = "uint8") | |
# create range color mas and apply | |
mask = cv2.inRange(frame, lower, upper) | |
filteredImg = cv2.bitwise_and(frame, frame, mask = mask) | |
#count number of not zero pixels - must be grayscale, countNonZero don't work | |
grayImg = cv2.cvtColor(filteredImg, cv2.COLOR_BGR2GRAY) | |
count = cv2.countNonZero(grayImg) | |
print("Frame: %d\tRed pixels:%s" % (frame,count)) | |
# end of main loop | |
# When everything done, release the capture and output | |
cap.release() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment