Results 1 to 2 of 2

Thread: use ScanLine function to comapare 2 images?

  1. #1
    Join Date
    Sep 2011
    Posts
    9
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows Maemo/MeeGo

    Default use ScanLine function to comapare 2 images?

    hi
    how can i use QImage::scanLine() to compare pixel data of 2 images.
    Qt Code:
    1. QImage image("C:\\Documents and Settings\\All Users\\Documents\\My Pictures\\Sample Pictures\\Winter.jpg");
    2. int height=image.height();
    3. int width=image.width();
    4. QImage image1("C:\\Documents and Settings\\All Users\\Documents\\My Pictures\\Sample Pictures\\Winter.jpg");
    5. int height1=image1.height();
    6. int width1=image1.width();
    7.  
    8. if(height1!=height||width1!=width){
    9. qDebug()<<"Images are different";
    10. }
    11. else
    12. for(int i=0,j=0;i<height,j<height1;i++,j++){
    13.  
    14. QRgb * img=(QRgb *)image.scanLine(i);
    15. QRgb * img1=(QRgb *)image.scanLine(j);
    16. if(*img==*img1){
    17. qDebug()<<"images matched:";
    18.  
    19. }
    20. else
    21. qDebug()<<"images do not match";
    22. }
    To copy to clipboard, switch view to plain text mode 

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

    thanx

  2. #2
    Join Date
    Oct 2009
    Posts
    483
    Thanked 97 Times in 94 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: use ScanLine function to comapare 2 images?

    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==().

Similar Threads

  1. Replies: 1
    Last Post: 20th January 2011, 10:26
  2. Replies: 1
    Last Post: 16th November 2010, 17:45
  3. Replies: 0
    Last Post: 10th March 2010, 08:13
  4. Replies: 4
    Last Post: 27th July 2009, 15:45
  5. Replies: 3
    Last Post: 16th December 2008, 14:38

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.