what is the best way to detect a flashing image?

I posed this question to the email support team but I think other people would find this useful

I have a function like so, which tries to determine if an image is flashing:

(* Verify that an image is flashing between the two specified images and log appropriately *)
to verifyFlash image1, image2, searchRec, pc
	(* assume correct pc is connected if not given *)
	if pc is not empty and pc is not null and pc is not "pc" then
		connect pc
	end if
	
    (* Constrain the search area as specified *)
	if searchRec is empty or searchRec is null or searchRec is "searchRec" then
		set searchRec to (0, 0, 2560, 1024)
	end if
	
	setOption SearchRectangle, searchRec
	
    (* Detect flashing image *)
	if ImageFound(2, image1) then
		if ImageFound(2, image2) then
			setOption SearchRectangle, fullscreen
			Log "VERIFIED: Flashing" && image1 && "detected"
			return 
		end if
	end if
	setOption SearchRectangle, fullscreen
	LogError "VERIFICATION FAILURE: Flashing" && image1 && "*NOT* detected"
end verifyFlash

But this function returns false every time I have tested it, when expecting true. The image switches about every .7 seconds or so, so i figured 2 seconds would be sufficient to detect the change.

I see that there is an option for a search type of ?pulsing? but I?m guessing that?s for mac-only?and that it doesn?t mean ?flashing?

matt came up with a promising solution–thanks.

Hi, Craig,

I think you’re going to need to adjust the search parameters inside that function in order for this to work. I was going to suggest that you set the searchRectangle property to a smaller area around where you expect to find the image, but I see that you are already doing that.

For the search parameters, I’d add code like this:

// store the current settings
put getOptions() into currentSettings
// reduce the image search delay
setOption imageSearchDelay, .1
// increase the image search count
setOption imageSearchCount, 20
If imageFound(4, image1) then
If imageFound(4, image2) then
// restore the original settings before returning
setOptions currentSettings
Return true
End if
End if
// restore the original settings before returning
setOptions currentSettings
Return false

It might also work to start your search for either image and then search for the other one based on which is found:

if imageFound(4, image1, image2) then
if foundImageInfo().imageName is image1 then
if imagefound(4, image2) then
// restore the original settings before returning
setOptions currentSettings
return true
end if
else
if imagefound(4, image1) then
// restore the original settings before returning
setOptions currentSettings
return true
end if

End if

end if

The processing time should be inconsequential. You could clean this up a bit by having only a single return statement, so the whole thing becomes:

(* Verify that an image is flashing between the two specified images and log appropriately )
on verifyFlash image1, image2, searchRec, pc
(
assume correct pc is connected if not given *)
if pc is not empty and pc is not null and pc is not “pc” then
connect pc
end if

(* Constrain the search area as specified *)
if searchRec is empty or searchRec is null or searchRec is "searchRec" then
	set searchRec to (0, 0, 2560, 1024)
end if

put getOptions() into currentSettings
// reduce the image search delay
setOption imageSearchDelay, .1
// increase the image search count
setOption imageSearchCount, 20
setOption SearchRectangle, searchRec
set flashingFound to false

(* Detect flashing image *)
if imageFound(4, image1, image2) then
	if foundImageInfo().imageName is image1 then
		if imagefound(4, image2) then
			// restore the original settings before returning
			Log "VERIFIED: Flashing" && image1 && "detected"
			set flashingFound to true
		end if
	else
		if imagefound(4, image1) then
			// restore the original settings before returning
			Log "VERIFIED: Flashing" && image1 && "detected"
			set flashingFound to true
		end if
		
	End if
end if
setOption SearchRectangle, fullscreen
LogError "VERIFICATION FAILURE: Flashing" && image1 && "*NOT* detected"
setOptions currentSettings
return flashingFound

end verifyFlash

I don’t have a flashing image to test this against, so I can’t guarantee it will work. Let me know how it goes.

Regards,
Matt

Hi,

I am in a similar situation but do not know how many flash images keep flashing. It will be dynamic one or unknown…can someone suggest how this can be tackled ? Any help…? The different flashing ones can be captured for validation but while scripting, how can it be generically scripted.

Thanks,
Vasavi

This is something that needs to be addressed directly by email to support with screenshots that demonstrate the issue.