compare two pictures app This is a topic that many people are looking for. bluevelvetrestaurant.com is a channel providing useful information about learning, life, digital marketing and online courses …. it will help you have an overview and solid multi-faceted knowledge . Today, bluevelvetrestaurant.com would like to introduce to you OpenCV3 Tutorials 9: Comparing Images and Displaying Difference – YouTube. Following along are instructions in the video below:
“This is abrahamic dad and i am going to talk about comparing two images are are using open cv and python 27. This video is basically a continuation to the videos. I ve been making on open cv and hopefully this tutorial will make you do interesting things so let s jump right in i ve prepared the images that we want to compare i ve prepared them right here. So what we are going to do this is basically one the jpeg.
Which is an ice cream image. It sizzix. I ve just copy and pasted this image to total jpeg so these images are the same however on 3d jpg. I ve edited dots here hope you can see it so we want to do to be able to detect the dots and tell if the images are the same or not i ve also added this image here this is a banana now this is a this is an exact copy duplicated this one banana banana.
One and banana are the same however in banana to have added a line so we want to be able to detect the line here and tell if the images are the same now this is very simple and very straightforward let me go ahead and create a new file to start coding as always you need to import cv to and imports an import numpy as mp now as in the previous videos. We ve seen how to load an image using open cv using i am reed so i m going to load the first image and store it in image one using cv to put i am reed and then we re going to supply in the path to the image. Since my source code is going to reside in the same location where the images are i understand this is not a very organized way. But this is just so for simplifying things.
It s just for demonstration purposes. So i m going to supply in just the name of the image and then i m going to load in the second image same approach using. I am did read i am real sorry. And then supply in the name of the image like so now we ve loaded the two images now to tell that is a method in opencv that does the comparison for us or basically that that returns the difference in the two images.
So that s simply called subtract so sub c. Be to put subtract and then we re going to give in the first image and then the second image. So this would result in a an image or an array of zeros..
We re going to store this indifference variable and to elaborate further the difference. If the images are the same this will be all zeros. If there are difference in the images this will not be all zeros. So we know now if this one is all zeros.
The images are the same so what we need to do now we need to use an umpire. Oh. You ve named it mp. Numpy function called any so basically what any does this will return true.
If there is a true array like what what do i mean by this if this one was all zeros and the other mp dot. Any will return false let me write it here if difference is all zeros. It will return false. It will return true if this is if it s a true array.
It s a nonzero array. So we re going to give it in the array that we ve named here the difference so this one will return. We ll store this the result of storage and results variable so this will return false if the images are the same what we need to do is we want to make it easier for us to to answer. The question are the image is the same we want to say true if the images are the same.
However this one returns false. If the images are the same so what would what s our what do i mean by the same is basically if the images are the same it means that the this array is all zeroes so we re just going to invert so if it s mp dot na. Which means the arrays are the same it will return false and not will make it true so in this case..
What we will do here sorry. What we will do here is we test the result. If true what we are going to print. I know there is a typo there i ll fix it in a bit the images are the same correct this result.
Now. If else. Which basically this is false it would mean that the images are not the same so what we want to do we want to store the image as we have done in the previous videos using i am that s right and then we re going to store. It under the name result jpg.
And then we re going to supply in the difference variable. Which contains the image the difference in the images like so and then we re going to print. All the images sorry. The images are different let s go ahead and save this one let s make all this image.
Comparison come on like so and then we re going to run. It using f5. Oh. The if result is come on there s a typo here save again and run.
So the images are the same now we know that the first image and the second image are the same let s go ahead and compare the first image and number 3. So instead of 2 here let s give it the name. 3..
And then we want to be able to see the difference so the images are different let me just go ahead and check. If there is a result yeah here it is let s see if there is oh here is there is the dot. It was able to detect the dot. If we want back to the original image that is the difference between the first image and the second image.
This is the difference here let s for a better example. Let s use nana. So the first image and the second image should be the same so let s go ahead. Banana.
One. So we are basically comparing this one and this one they should be the same because i just copy and pasted them and the images are indeed the same now let s go ahead and compare banana banana and instead of one this right and the images are different let s go ahead and check results. And there is the difference in the two images. So the process was very simple a quick recap.
I ve loaded the images that we want to compare of course. I ve loaded the library s reading opencv and numpy. I ve loaded the images that we want to compare i ve used the subtract method to get the difference between the two images and then i ve used numpy dot eddie to tell us if this array is actual is an array. If this was all zeros.
It will return which will give us false and we just inverted the false for a lot for easier readability. So if the difference. If the images are the same this will contain true and we will also put this set and we ll also put the string..
If the images are different we re going to store the difference in result the jpg. And print. The images are different. So that s it and hope.
I hope that was helpful of course. There are other methods to compare two images you might find that there is other approaches say like comparing the indexes comparing the hash keys. Converting an image to hash and of course. There are several other methods that one sorry that one could actually use for example.
There is the there are of course you know numpy. There are several other methods instead of using any but this is basically consumes less memory and stuff that is of course. There is the np that s all and of course. There are several other approaches you could actually utilize.
The is also the comparison. There is basically several ways numerous ways you could actually use to compare images anyways. I hope that was helpful and if you have any questions feel free to shoot to my work and have a good day goodbye. ” .
Thank you for watching all the articles on the topic OpenCV3 Tutorials 9: Comparing Images and Displaying Difference – YouTube. All shares of bluevelvetrestaurant.com are very good. We hope you are satisfied with the article. For any questions, please leave a comment below. Hopefully you guys support our website even more.
In this tutorial we explore how to compare two images and display the difference. We will be using opencv and numpy libraries.
The code implemented here can be found here: https://github.com/ibininja/openCV3_tutorials
This video demonstrates how to use opencv 3 and python 2.7 to detect faces in a stream of frames. be it a webcam/camera stream or a video file.
This video is part of the series OpenCV and Python. For a better understanding feel free to visit other videos.
The code used can be found here: https://github.com/ibininja/openCV3_t…
My website: ibrahimokdad.com
opencv, opencv3, python, python27, numpy, comparing images, images, image processing