Note that there are some explanatory texts on larger screens.

plurals
  1. POOpenCV compare two images and get different pixels
    text
    copied!<p>For some reason the code bellow is not working. I have two 640*480 images which are very similar but not the same (at least few hundred/thousand pixels should be different).</p> <p>This is how I am comparing them and counting different pixels:</p> <pre><code>unsigned char* row; unsigned char* row2; int count = 0; // this happens in a loop // fIplImageHeader is current image // lastFIplImageHeader is image from previous iteration if ( NULL != lastFIplImageHeader-&gt;imageData ) { for( int y = 0; y &lt; fIplImageHeader-&gt;height; y++ ) { row = &amp;CV_IMAGE_ELEM( fIplImageHeader, unsigned char, y, 0 ); row2 = &amp;CV_IMAGE_ELEM( lastFIplImageHeader, unsigned char, y, 0 ); for( int x = 0; x &lt; fIplImageHeader-&gt;width*fIplImageHeader-&gt;nChannels; x += fIplImageHeader-&gt;nChannels ) { if(row[x] != row2[x] || row[x+1] != row2[x+1] || row[x+2] != row2[x+2]) count++; } } } } </code></pre> <p>Now at the end I get number 3626 which would seem alright.</p> <p>But, I tried opening one of the images in MS Paint and drawing thick red lines all over it which should increase the number of different pixels substantially. I got the same number again: 3626.</p> <p>Obviously I am doing something wrong here.</p> <p>I am comparing these images in a loop.</p> <p>This line is before the loop:</p> <pre><code>IplImage* lastFIplImageHeader = cvCreateImageHeader(cvSize(640, 480), 8, 3); </code></pre> <p>Then inside the loop I load images like this:</p> <pre><code>IplImage* fIplImageHeader = cvLoadImage( filePath.c_str() ); // here I compare the pixels (the first code snippet) lastFIplImageHeader-&gt;imageData = fIplImageHeader-&gt;imageData; </code></pre> <p>So lastFIplImageHeader is storing the image from the previous iteration and fIplImageHeader is storing the current image.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload