3

I'm trying to use OpenCV to analyze a 10 min video for green in the top right corner and printing out the time stamps every time there is green. I've used meanshift and tried splitting it into frames but a 10 minute long video would require a lot of frames -- especially since I'm trying to be accurate.

I was thinking of masking over the green, but there isn't a way to print the time stamps... any tips on what packages or tools I should use?

Here's what I have, and I've tried basically everything in OpenCV but I've never used it before so I'm lost...

import cv2 
import numpy as np  

cap = cv2.VideoCapture('video.mp4')  

# This drives the program into an infinite loop. 
while(1):        
    # Captures the live stream frame-by-frame 
    _, frame = cap.read()  
    # Converts images from BGR to HSV 
    hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV) 
    lower_red = np.array([121, 240, 9]) # darker green
    upper_red = np.array([254,255,255])  # white green

# Defining range of green color in HSV 
# This creates a mask
mask = cv2.inRange(hsv, lower_red, upper_red) 

# that only the green coloured objects are highlighted  

res = cv2.bitwise_and(frame,frame, mask= mask) 
cv2.imshow('frame',frame)
cv2.imshow('mask',mask) 
cv2.imshow('res',res) 

k = cv2.waitKey(5) & 0xFF
# if k == 27: break

# Destroys all of the HighGUI windows. 
cv2.destroyAllWindows() 

# release the captured frame 
cap.release() 

Splitting the frames gives me thousands of images and just reading the video doesn't give me time stamps, which is what I want it to print out. Thanks!

ClaireBookworm
  • 101
  • 1
  • 9

0 Answers0