PDA

View Full Version : use ScanLine function to comapare 2 images?



harshita
22nd September 2011, 12:20
hi
how can i use QImage::scanLine() to compare pixel data of 2 images.


QImage image("C:\\Documents and Settings\\All Users\\Documents\\My Pictures\\Sample Pictures\\Winter.jpg");
int height=image.height();
int width=image.width();
QImage image1("C:\\Documents and Settings\\All Users\\Documents\\My Pictures\\Sample Pictures\\Winter.jpg");
int height1=image1.height();
int width1=image1.width();

if(height1!=height||width1!=width){
qDebug()<<"Images are different";
}
else
for(int i=0,j=0;i<height,j<height1;i++,j++){

QRgb * img=(QRgb *)image.scanLine(i);
QRgb * img1=(QRgb *)image.scanLine(j);
if(*img==*img1){
qDebug()<<"images matched:";

}
else
qDebug()<<"images do not match";
}

i know this code is error prone, kindly explain to me how scanLine works

thanx

yeye_olive
22nd September 2011, 13:41
A lot of things are wrong in your program:
- you assume your images have 32 bit depth;
- your compare the first pixel of each row, regardless of the width of the images;
- in fact you print a statement about the equality of the image for each row;
- the two indices i and j in the loop are always the same.

I would recommend:
- learning how to use pointers and arrays in C++;
- thinking about your algorithm before writing any code;
- using QImage::operator==().