Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

This will be in two parts. First, give a look at the function absdiff . It might very well replace your compareImgs(), give a look at it (maybe not, just give a look). Personally, I have lost some time in the past trying to implement some function that where already present in OpenCV, C++, etc. Still, if you don't know a function exists, how do you look for it? I am no better than anyone at this, sometime I just ask on this site! ;)

Second: You need to understand (or state explicitly if you do) what type of comparison you are doing. I'll ask some question and just think about them, you might as well have good reasons for doing the way you have done.

  • You have a src_input that you convert to grayscale. Why? Comparing greyscale vs a 3 channels BGR (OpenCV reverse the order of RGB for some historical reason) is shorter, but converting from BRG takes time too. By going greyscale, you are losing information. Do you think scraping the colour is relevant for a comparison? Maybe yes, maybe no. More on this later.

  • Same thing for the db_img.

  • What is the relation between the database and your src_img? Is it a database including a mix of different stuff, or at the opposite is it a database that includes 1000 minor variations of the same image? I mean, a pixel by pixel comparison can only go as far as telling you up to which point two images are perfectly identical. Should your src_img be shifted by one row of pixel, it would dramatically decrease the match. If shifted by 2 rows, worse. (You can imagine that by shifting by a row, I mean any even small difference in your src_image that would defeat a px by px comparison).

  • If you do indeed need to do a px by px comparison, you should consider to branch out (break;) from your loop after some number of mismatch; I mean if you scan the whole top quarter of the image (or even less) and the matching is no good, don't bother matching the rest...

  • If your expect some difference in px between the src_img and the database, you should try alternate strategies such as computing the histogram of each image of the database and to histogram matching

I hope this bag of comment will help you. If you need any more info, feel free to ask in the comments!