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:
[color=green](* Verify that an image is flashing between the two specified images and log appropriately *)[/color]
[color=darkblue]to verifyFlash image1, image2, searchRec, pc[/color]
	[color=green](* assume correct pc is connected if not given *)[/color]
	[color=darkblue]if pc is not empty and pc is not null and pc is not "pc" then[/color]
		[color=violet]connect pc[/color]
	[color=darkblue]end if[/color]
	
    [color=green](* Constrain the search area as specified *)[/color]
	[color=darkblue]if searchRec is empty or searchRec is null or searchRec is "searchRec" then[/color]
		[color=violet]set searchRec to[/color] [color=orange](0, 0, 2560, 1024)[/color]
	[color=darkblue]end if[/color]
	
	[color=violet]setOption SearchRectangle, searchRec[/color]
	
    [color=green](* Detect flashing image *)[/color]
[color=darkblue]	if ImageFound(2, image1) then
		if ImageFound(2, image2) then[/color]
			[color=violet]setOption SearchRectangle, fullscreen[/color]
			[color=red]Log "VERIFIED: Flashing" && image1 && "detected"[/color]
[color=darkblue]			return 
		end if
	end if[/color]
	[color=violet]setOption SearchRectangle, fullscreen[/color]
	[color=red]LogError "VERIFICATION FAILURE: Flashing" && image1 && "*NOT* detected"[/color]
[color=darkblue]end verifyFlash[/color]
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?

Comments

  • 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
  • vkazavkaza Member
    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
  • EggplantMattEggplantMatt ForumAdmin admin
    This is something that needs to be addressed directly by email to support with screenshots that demonstrate the issue.
Sign In or Register to comment.