Is it possible in python to extract frames from a LIVE video using opencv. I am trying to write code for a text recognition software. Using opencv and tesseract but I cant get tesseract to review the video unless it is in frames.
-
3yes it is possibleAhmet– Ahmet2020年01月19日 20:38:52 +00:00Commented Jan 19, 2020 at 20:38
1 Answer 1
My man, you need to extract each video frame and parse it as a cv Mat. Here's a snippet code (in C++) that reads an mp4 video, extracts each frame and converts it to an OpenCV matrix:
// Video input:
std::string filePath= "C://myPath//";
std::string videoName = "videoTest.mp4";
// Open video file:
cv::VideoCapture vid( filePath + videoName );
// Check for valid data:
if ( !vid.isOpened() ){
std::cout<<"Could not read video"<<std::endl;
//handle the error here...
}
//while the vid is opened:
while( vid.isOpened() ){
// Mat object:
cv::Mat inputFrame;
// get frame from the video
vid >> ( inputFrame);
// carry out your processing
//...
}
For this C++ implementation, I've previously #included for OpenCV's video io definitions.
answered Jan 20, 2020 at 0:27
stateMachine
5,8954 gold badges18 silver badges36 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
Bradley C
Thanks this will really help.
lang-py