Defining new variable (picture) for each loop

Asked by Eric Vaughn

So I work in a psychology lab. Basically, I have over 300 hour-long videos, and at some point in the video, a picture will be displayed where the participant has a big facial reaction (based on how they rated the picture). The 11 second reaction I want to clip can happen at any point in the video and is one of about 30 different photos.

I'm trying to write something that will find the picture (the computer screen is also recorded), stop the video and record the 11 second reaction, then on a loop, continue onto the next video, and the next and the next. I have done that part. But it's only now that I've realized that I need the "picture" variable defined at the top to change in almost every video. Here's what I have:
-----

picture= ("4230-1.png")
App.focus("chrome") # Be sure Chrome is open to the correct spreadsheet
type(Key.DOWN) #Moves cursor down to select new participant ID for each loop
type("c",KeyModifier.CTRL) #Starts on ID xxxx and copies ID
click("1429908306921.png") #brings focus to the explorer folder with videos in it
click(Pattern("1429908644602.png").exact()) #Insert the name of where you'll be searching
type("v", KeyModifier.CTRL) #pastes ID copied above
wait(2)
if exists(Pattern("1429908782248.png").exact()):
    doubleClick(Pattern("1429908782248.png").exact())
    wait(2)
    type("t", KeyModifier.CTRL)
    type("010735")
    type(Key.ENTER)
    Settings.ObserveScanRate = 5.0 # Sikuli searches screen 5 times/second
    while exists(picture, FOREVER): #Pauses VLC during picture, captures 11 second reaction and closes VLC. Exports to My Videos
        click("1424897770073.png")
        type(Key.LEFT, KeyModifier.ALT) # Be sure 'short jump back' hotkey is set to 9 seconds in VLC
        click("1429909306834.png")
        click("1429909283119.png")
        wait(12)
        click("1429909306834.png")
        click("1429909438710.png")
        break
    else:
        pass
else:
    pass;
App.focus("search")
click("1429909648444.png")
click(Pattern("1429909709906.png").similar(0.91))#Brings search ability back;

----
It may not be perfect code, but I've tested it and it does exactly what I want, but only for one video with one picture. I just need it to be able to switch the "picture" variable.

Does anyone know how or if I can specify a different picture for every repetition of the loop? I have an Excel Spreadsheet with all the corresponding picture ID names, in order, that can be used to tell Sikuli what picture file to insert as the new "picture" variable for each loop.

This would help so much!

Thanks,
Eric

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

this is an example for a principal approach:

pictures = []

# this might be revised as a loop to fill pictures
App.focus("chrome") # Be sure Chrome is open to the correct spreadsheet
type(Key.DOWN) #Moves cursor down to select new participant ID for each loop
type("c",KeyModifier.CTRL) #Starts on ID xxxx and copies ID
picture = Env.getClipboard() # reads clipboard content
print picture # to see what it contains
pictures.append(picture) # add image to the list

# example for a list containing some image filenames
# to simulate the usage with a filled pictures list
pictures = ("4230-1.png", "4230-2.png", "4230-3.png", "4230-4.png")

for picture in pictures:
  click("1429908306921.png") #brings focus to the explorer folder with videos in it
  click(Pattern("1429908644602.png").exact()) #Insert the name of where you'll be searching
  type("v", KeyModifier.CTRL) #pastes ID copied above
  wait(2)
  if exists(Pattern("1429908782248.png").exact()):
     doubleClick(Pattern("1429908782248.png").exact())
     wait(2)
     type("t", KeyModifier.CTRL)
     type("010735")
     type(Key.ENTER)
     Settings.ObserveScanRate = 5.0 # Sikuli searches screen 5 times/second
     while exists(picture, FOREVER): #Pauses VLC during picture, captures 11 second reaction and closes VLC. Exports to My Videos
         click("1424897770073.png")
         type(Key.LEFT, KeyModifier.ALT) # Be sure 'short jump back' hotkey is set to 9 seconds in VLC
         click("1429909306834.png")
         click("1429909283119.png")
         wait(12)
         click("1429909306834.png")
         click("1429909438710.png")
         break
     else:
         pass
  else:
     pass;
  App.focus("search")
  click("1429909648444.png")
  click(Pattern("1429909709906.png").similar(0.91))#Brings search ability back;

Can you help with this problem?

Provide an answer of your own, or ask Eric Vaughn for more information if necessary.

To post a message you must log in.