I am trying to extract images out of video using opencvsharp and I need to create a pdf and store only those images in pdf where there is a text content in the image.
I have written following code till now, Please help or advice further on how to identify and extract frames only where there is a text in image.
Thanks in advance!
using OpenCvSharp;
using System;
using System.IO;
namespace VideoToImage
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("Begin video to image program..");
var videoFile = "C:\\Users\\sinequa\\Downloads\\cloud-computing-in-6-minutes-what-is-cloud-computing-cloud-computing-explained-simplilearn.mp4"; // Specify path to MP4 video file.
var outputPath = "output_images"; // Path is relative to working directory of the app
System.IO.Directory.CreateDirectory(outputPath);
var capture = new VideoCapture(videoFile);
var image = new Mat();
int i = 0;
Console.WriteLine("Begin extracting frames from video file..");
bool capOpen=capture.Open(videoFile);
bool isCapOpen=capture.IsOpened();
Console.WriteLine(isCapOpen);
int counter=0;
//Adding counter to only save 5th frame
while (capture.IsOpened())
{
// Read next frame in video file
Console.WriteLine("capture is open");
counter+=1;
capture.Read(image);
if (image.Empty())
{
break;
}
if(counter == 5){
// Save image to disk.
Cv2.ImWrite(String.Format("output_images\\frame{0}.png", i), image);
Console.WriteLine(String.Format("Succesfully saved frame {0} to disk.", i));
counter=0;
}
i++;
}
Console.WriteLine(String.Format("Finished, check output at: {0}.", Path.GetFullPath(outputPath)));
}
}
}