Results 1 to 5 of 5

Thread: Compare 2 images in QT?

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

    Default Compare 2 images in QT?

    hi all,
    i want to compare 2 QImages, please share the logic, i have already used operator==, but it takes to much time.
    Can someone explain how scanline function works?

    thanks in advance

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Compare 2 images in QT?

    scanLine() returns a pointer to bytePerLine() bytes of data representing one horizontal line in the image. If the images are of identical size and format then loop over all the lines in the image to access the raw data and compare them however you like. I haven't looked, but I suspect the operator==() checks for equal pixels (if the answer is not trivial) regardless of image format.

    What is the source of the two images? Files, generated, captured? Same source or different sources?

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

    Default Re: Compare 2 images in QT?

    Quote Originally Posted by ChrisW67 View Post
    scanLine() returns a pointer to bytePerLine() bytes of data representing one horizontal line in the image. If the images are of identical size and format then loop over all the lines in the image to access the raw data and compare them however you like. I haven't looked, but I suspect the operator==() checks for equal pixels (if the answer is not trivial) regardless of image format.

    What is the source of the two images? Files, generated, captured? Same source or different sources?
    Thanx Chris,
    For now i am testing comparison so the source is the File and image can be of different format and sizes, this is what i have assumed in the actual scenario. can u please sketch a code for using scanline() .
    thanx again

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Compare 2 images in QT?

    If the image is of a different size then the images are not equal.
    If the images are of the same format then you could possibly compare scanline by scanline until you find a byte that differs (memcmp()) , or run out of bytes.
    If the images are of different formats then you have to fetch the RGBA components of each pixel in turn until you find a pixel that differs, or run out of pixels.

    If you look at the implementation of QImage:perator==() you'll find that this is exactly how it does it.


    The reason I asked about the source is that there may be other definitions of "compare image" that are more efficient. If you are after an absolute equality then it may be adequate to check if the source files are identical at a byte level (directly our using a hash) rather than a pixel-by-pixel logical equality check.

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

    Default Re: Compare 2 images in QT?

    hey chris,
    thats exactly wot i am looking for. I want to calculate hash of an image.
    QCryptographicHash class seems to be a solution, but i ma not sure?

    how do i convert a QImage to QByteArray?

    thanx

Similar Threads

  1. how to locale compare two string ?
    By narutokage in forum Qt Programming
    Replies: 4
    Last Post: 16th August 2011, 09:13
  2. How do compare the two icons
    By addu in forum Qt Programming
    Replies: 1
    Last Post: 10th July 2009, 16:19
  3. How to Compare Characters ASCII value?
    By merry in forum Qt Programming
    Replies: 5
    Last Post: 14th July 2008, 12:05
  4. do we can't compare QIcon or QPixmap????
    By sudheer in forum Qt Programming
    Replies: 2
    Last Post: 13th May 2008, 14:53
  5. Compare
    By merry in forum Qt Programming
    Replies: 1
    Last Post: 14th March 2007, 15:03

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.