Detecting a black/blank frame in video using OpenCV - c++

I'm using OpenCV 2.4.2 VideoCapture class to grab frames from multiple videos and my aim is to compare the frames between videos to retrieve similar videos (visually similar).
I'm facing two issues.
The videos contain blank/black frames.
I can loop over each individual frame (while capturing the video) and check the pixels etc. to detect these frames. Is there a faster and more efficient way to somehow do this? I have more than 1k videos and each video has around 5k-20k frames [I'm capturing 1 frame per second]. I'm coding in C++.
Comparing two huge matrices to check how "similar" they are.
I eventually compute a huge matrix for each video where the rows correspond to the number of the frames, and the cols correspond to the dimensionality of the descriptor being computed on each frame. If I need to compare two videos for similarity, the simplest thing I found was to compute Euclidean matrix. But again, horribly inefficient if I scale up to 1000s of videos.
Any advice and suggestion will be appreciated.
Thanks,

Concerning the first problem, I think cv::countNonZero is the most suitable method, it works very fast as well. cv::countNonZero returns the number of non-zero elements in input single-channel array.

Related

emgu.cv - difference between two frames

I am checking a video, and would like to compare each frame with the previous one and return a black and white image consisting of all differences between the two frames.. like a "mask" of differences between the frames
Detect and visualize differences between two images with OpenCV Python
this link contains exactly what I would need, but it is in pythong, and I was not able to find the same method in .net. Its also my very first time working with emgu and I feel a bit lost.
I have 3 Mats, one is currentframe, oldframe and diffframe
any help on how this can be done is greatly appreciated!

Most efficient way to store video data

In order to accomplish some specific editing on some .avi files, I'd like to create an application (in C++) that is able to load, edit, and save those .avi files. But, what is the most efficient way? When first thinking about it, a simple 3D-Array containing a 2D-array of pixels for every frame seems the simplest solution; But then its size would be ENORMOUS. I mean, let's assume that a pixel only needs a color. One color would mean 3bytes (1char r, 1char b, 1char g). If I now have a 1920x1080 video format, this would mean 2MEGABYTES for only one frame! This data may or may not be smaller if using pointers for the colors, so that alreay used colors wont take more size - I don't really know, since I'm pretty new to C++ and the whole low-level stuff. (As a comparison: One of my AVI files recorded with Xvid codec is 40seconds long, 30fps, and only has 2MB.)
So how would you actually store the video data (Not even the audio, just the video) efficiently (while still being easily able to perform per-frame-changes on it)?
As you have realised, uncompressed video is enormous and it is not practical to store an entire video in this way.
Video compression is an extremely complex topic, but more-or-less, it works as follows: certain "key-frames" are compressed using fairly standard compression techniques similar or identical to still-photo compression such as JPEG. Frames following key-frames are compressed by comparing the frame with the previous one and looking for changes (such as moving blocks). Every now and again, a new key-frame is used.
You don't really have to worry much about that as you are not going to write your own video coder/decoder (codec). There are standard ones.
What will happen is that your program will decode the compressed video frame-by-frame and keep a certain number of frames in memory while you are working on them and then re-encode them when it is finished. In the uncompressed form, you will have access to the individual pixels and can work on them how you want.
You are probably not going to do that either by yourself - it is very hard. You probably need to use a framework, such as OpenCV. There are a huge number of standard filters and tools built in to these frameworks, and it may be that what you want to do is already implemented somewhere.
The OpenCV framework can return individual frames in a Mat object and you can then access the pixels. See this post Get Pixels from Mat
OpenCV
Tutorial page: Open CV Tutorial

How to find object on video using OpenCV

To track object on video frame, first of all I extract image frames from video and save those images to a folder. Then I am supposed to process those images to find an object. Actually I do not know if this is a practical thing, because all the algorithm did this for one step. Is this correct?
Well, your approach will consume a lot of space on your disk depending on the size of the video and the size of the frames, plus you will spend a considerable amount of time reading frames from the disk.
Have you tried to perform real-time video processing instead? If your algorithm is not too slow, there are some posts that show the things that you need to do:
This post demonstrates how to use the C interface of OpenCV to execute a function to convert frames captured by the webcam (on-the-fly) to grayscale and displays them on the screen;
This post shows a simple way to detect a square in an image using the C++ interface;
This post is a slight variation of the one above, and shows how to detect a paper sheet;
This thread shows several different ways to perform advanced square detection.
I trust you are capable of converting code from the C interface to the C++ interface.
There is no point in storing frames of a video if you're using OpenCV, as it has really handy methods for capturing frames from a camera/stored video real-time.
In this post you have an example code for capturing frames from a video.
Then, if you want to detect objects on those frames, you need to process each frame using a detection algorithm. OpenCV brings some sample code related to the topic. You can try to use SIFT algorithm, to detect a picture, for example.

jumpy video processing in opencv

heylo!
I have a bunch of old video files converted from old vhs tapes. The problem is, since those tapes were really old, the videos are jumpy (sometimes the bottom of the frame is in the middle of the screen followed by the top of the next frame)
My goal is to write something in opencv to automatically remove the frames where the image is not lined up properly.
My idea is to detect the difference between the previous frame and the next frame. If the video were smooth, the difference would be minimal. If the frame is jumpy then the difference would be noticeable.
My question: how would opencv calculate this difference between two frames?
Thx!!!!
I hope you know how to grab frames from video. If not, check here. Fortunately, it also finds similarity between two videos.
What you will learn in this tutorial:
How to open and read video streams
Two ways for checking image similarity: PSNR and SSIM
I think you can just make small adaptations to it as per your requirements. This tutorial has all enough information about it.
You can also check this SOF : Simple and fast method to compare images for similarity

Get most clear iplimage from the buffer

How can I get most clear iplimage among rest , using OpenCV.? When there is no training image to compare.
As a example there is a web cam input which move a hand. But when I stream this video ,I get 10 iplimages. But only 5th one is more clear. I want to filter that 5th one using openCV.
Its good to evaluate each and every iplimage (10 images) and assign rank using clearness of the images. Is there any way to do it so..?
I hope kindness support from your all.
Thank you.
Several measures of 'clearness' or blur in pictures have been quantified in research papers. So what you're looking for probably is to estimate the amount of blur present in an image and then use it to decide whether it is to be discarded or not. I found this study to be quite helpful, gives a comparative overview of the different metrics of blurriness. Google Scholar's always there with a search string of estimating blur in images if you want to check other resources.
You could choose whichever method gives you the best results with your set of images, experimentally determining which threshold of the measure will be 'clear' enough. Or of course you could run the blur estimation on every frame and choose the one with the lowest blur.