3
votes

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

2
Please post some code; would help us answer - Nathan
There's not really any code to worry.. @frank it's about frame not being same when loading using opencv. The first time it's one and in another video the same frame is different - poda_badu
Are you sure they're not the same frame? Did you look at them, or are you just using code to compare the two? - Nathan
Did my answer sort out your problem? If so, please consider accepting it as your answer - by clicking the hollow tick/checkmark beside the vote count. If not, please say what didn't work so that I, or someone else, can assist you further. Thanks. meta.stackexchange.com/questions/5234/… - Mark Setchell

2 Answers

3
votes

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

0
votes

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.