Bradley C
Bradley C

Reputation: 1

Python Video to frames?

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.

Upvotes: 0

Views: 167

Answers (1)

stateMachine
stateMachine

Reputation: 5815

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.

Upvotes: 1

Related Questions