poda_badu
poda_badu

Reputation: 161

Compare frames from videos opencv python

I've been trying to compare videos from frames taken from video using opencv videocapture() python!

Took the first frame from a video let's call it frame1 and when I saved the video and took the same first frame again let's call it frame2

Comparing frame 1 and frame 2 returns false. When I expected true.

I also saved the frame as an image in png(lossless format) and saved video and again same first frame. But they don't match? How to get the same frame everytime when dealing with videos opencv! Python

Upvotes: 3

Views: 2207

Answers (2)

Martin Faucheux
Martin Faucheux

Reputation: 1005

I don't know why it doesn't work but to solve your problem I would suggest to implement a new function which returns true even if there is a small difference for each pixel color value.

Using the appropriate threshold, you should be able to exclude false negatives.

Upvotes: 0

Mark Setchell
Mark Setchell

Reputation: 207520

I guess you saved the frame as a PNG file, which amongst other things, contains the date and time the file was encoded, so the files will appear to differ if you use diff or cmp in the shell.

The solution is either to use a format that doesn't encode the date and time, such as PPM, or to use a tool such as ImageMagick which will allow you to generate a hash for comparison, but exclusively over the pixel data and not the metadata:

identify -format %# someImage.png
e74164f4bab2dd8f7f612f8d2d77df17106bac77b9566aa888d31499e9cf8564

More discussion here

Upvotes: 3

Related Questions