Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compare frames from videos opencv python

Tags:

python

opencv

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

like image 297
poda_badu Avatar asked Sep 11 '26 02:09

poda_badu


1 Answers

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

like image 55
Mark Setchell Avatar answered Sep 12 '26 17:09

Mark Setchell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!