是否有可能在python中使用opencv从实况视频中提取帧。我正在尝试为文本识别软件编写代码。使用opencv和tesseract,但除非帧内显示,否则我无法让tesseract来查看视频。
[我的男人,您需要提取每个视频帧并将其解析为cv Mat。这是一个片段代码(在C ++中),用于读取mp4视频,提取每个帧并将其转换为OpenCV矩阵:
// 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
//...
}
对于此C ++实现,我以前#include OpenCV的视频io定义。