jumpy video processing in opencv - c++

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

Related

C++ (OpenCV) How could I split a video down the middle to make two subvideos in real time?

I have a live video that is being inputted into a C++ program. Right now, the video is of two cameras that are side by side. I want to split the video into two different subvideos, with each video being its own camera.
I honestly don't even know where to start with this. It's my first time programming around a live video input.
I tried using OpenCV and cv::resize(), but that doesn't split the video, it only resizes it.

Detecting a black/blank frame in video using OpenCV

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.

Grabbing a 10 second clip after motion detection in OpenCV

I am currently writing a code in order to detect small objects that are moving using OpenCV and C++. I have motion detection, logging of detects, and bounding boxes working well. Now I am stuck on a way to take the video, and after I get a detection, grab 5 seconds before and 5 seconds after the detection period and save it out to a different .avi file. Does anyone have ideas on a way to do this? Even a point in the general direction would be helpful as I can't seem to find anything on taking out clips from a .avi file and saving them to different files.

How to average all the frames of a video file in which objects are not moving in OpenCV?

I have different frames of a video file. Now, on observing each frames separately, I noticed there are many frames in which objects has not moved. I need to do averaging of all those frames and make a single frame using OpenCV.
I am totally new in OpenCV, so It will be great help if can able to get codes for frame averaging.
One simple technique...
Subtract previous frame from present frame...using this opencv function. Take only those frame which have difference negative or positive above a threshold...like in the frames where the object is almost static then on doing frame difference you will get low value...skip those frames....again when only the object is moving and the rest of the background is more or less static like a man moving in a park, there just you can store the position of the man and the background gets duplicated...

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.