How to compare two images

I want to compare two images they captured in a script.

I tried the solution from the discussion of next URL.

Although it seemingly succeeded in Case2 below, even if "originalImage" and "laterImage" are actually different, the script don't go to the 'logFailure "The images are different" '.

Could you please help me?

[Case1]
set areaOfInterest to (100,100,300,300) -- the area of the screen to compare 
captureScreen "/tmp/originalImage", areaOfInterest 

-- do some other processing 

captureScreen "/tmp/laterImage", areaOfInterest -- capture the same area again 

if file "/tmp/originalImage.png" as data is equal to file "/tmp/laterImage.png" as data then 
logSuccess "The images are the same" 
else 
logFailure "The images are different" 
end if 

[Result:Case1]
2018/07/12 16:33:56 START Running ccbizmate.script
>>> 04:33:57 Start handler 1: ccbizmate
set areaOfInterest to (100,100,300,300) -- the area of the screen to compare 
captureScreen "/tmp/originalImage", areaOfInterest 
2018/07/12 16:33:57 LogWarning Unable to save C:/Users/kiarima/Documents/test0705.suite/Results/ccbizmate/20180712_163356.968/tmp/originalImage.png
captureScreen "/tmp/laterImage", areaOfInterest -- capture the same area again 
2018/07/12 16:33:58 LogWarning Unable to save C:/Users/kiarima/Documents/test0705.suite/Results/ccbizmate/20180712_163356.968/tmp/laterImage.png
if file "/tmp/originalImage.tiff" as data is equal to file "/tmp/laterImage.tiff" as data then 
logSuccess "The images are the same" 
2018/07/12 16:33:58 LogSuccess The images are the same
end if 
<<< 04:33:58 End handler 1: ccbizmate (normal exit)
2018/07/12 16:33:58 EndTestCase (Duration:"1.212", Errors:"0", Exceptions:"0", StartTime:"2018-07-12 16:33:56 +0900", Successes:"1", TestCase:"ccbizmate.script", Warnings:"2")
2018/07/12 16:33:58 SUCCESS Execution Time 0:00:02 ccbizmate.script

[Case2]
set areaOfInterest to (100,100,300,300) -- the area of the screen to compare 
captureScreen "/originalImage", areaOfInterest 

-- do some other processing 

captureScreen "/laterImage", areaOfInterest -- capture the same area again 

if file "/tmp/originalImage.png" as data is equal to file "/laterImage.png" as data then 
logSuccess "The images are the same" 
else 
logFailure "The images are different" 
end if 

[Result:Case2]
2018/07/12 16:36:22 START Running ccbizmate.script
>>> 04:36:22 Start handler 1: ccbizmate
set areaOfInterest to (100,100,300,300) -- the area of the screen to compare 
captureScreen "/originalImage", areaOfInterest 
2018/07/12 16:36:23 capturescreen originalImage.png (100,100,300,300)
captureScreen "/laterImage", areaOfInterest -- capture the same area again 
2018/07/12 16:36:23 capturescreen laterImage.png (100,100,300,300)
if file "/tmp/originalImage.png" as data is equal to file "/laterImage.png" as data then 
logSuccess "The images are the same" 
2018/07/12 16:36:23 LogSuccess The images are the same
end if 
<<< 04:36:23 End handler 1: ccbizmate (normal exit)
2018/07/12 16:36:23 EndTestCase (Duration:"1.231", Errors:"0", Exceptions:"0", StartTime:"2018-07-12 16:36:22 +0900", Successes:"1", TestCase:"ccbizmate.script", Warnings:"0")
2018/07/12 16:36:23 SUCCESS Execution Time 0:00:01 ccbizmate.script

Comments

  • kin_arimakin_arima Member
    That solved.

    set CaptureArea to (0, 0, 100, 100) -- Set Capture Area.
    CaptureScreen "C:\Users\[UserName]\Image-Before.png", CaptureArea
    -- do some other processing 
    CaptureScreen "C:\Users\[UserName]\Image-After.png", CaptureArea
    if file "C:\Users\[UserName]\Image-Before.png" as data is equal to file "C:\Users\[UserName]\Image-After.png" as data then
    log "Image-Before and Image-After are same images."
    else
    log "Image-Before and Image-After are different images."
    end if
Sign In or Register to comment.