Comparing Images

Hi,

I am currently doing a code where I need to screenshot one area of the screen then wait for a few seconds and the screenshot that again then compare them.

I found this one

then I rewrote this to fit in my code


set CaptureArea to  (331,154, 892, 505)
	captureScreen "originalImage", CaptureArea
	Wait 30
	captureScreen "afterImage", CaptureArea
	
	if file "originalImage" as data is not equal to file "afterImage" as data then
		logSuccess "The Image updated/changed"
	Else
	        logError "The Image did not updated/changed"
	End If

I wanted to check if the certain area i was having to screenshot is updating/changing but I am always getting the message that it did not update but when I compare the images manually, it turns out that the image is updated/changed

really need this code to work

Thanks in advance

The problem with your code is that when you capture your images, they’re being saved to the result folder for the current run of your script, and they’re being saved with a file extension (png on Windows; tiff on Mac). Because you don’t specify any path information, your subsequent references are to files that will be in the working directory, which is usually the Default Suite Directory. You end comparing two files that don’t exist, which are equal in SenseTalk.

One way to fix this is to get the actual path to the files, which will be in the “the result” variable after the screen capture:

set CaptureArea to  (331,154, 892, 505) 
   captureScreen "originalImage", CaptureArea 
   put the result into original
   wait 30
   captureScreen "afterImage", CaptureArea
   put the result into after
    
   if file original as data is not equal to file after as data then 
      logSuccess "The Image updated/changed" 
   Else 
           logError "The Image did not updated/changed" 
   End If 

The way I would approach this is not to capture two images, but to just capture one and check it against the screen:

 set CaptureArea to  (331,154, 892, 505) 
   captureScreen rectangle:CaptureArea 
   put the result into original
   wait 30
   if not imageFound(original) 
      logSuccess "The Image updated/changed" 
   Else 
           logError "The Image did not updated/changed" 
   End If 

Thanks! I’ve tried your advice on just looking for the captured image and its much better that way! thanks again