Welcome!

Sign in with your CogSci, Facebook, Google, or Twitter account.

Or register to create a new account.

We'll use your information only for signing in to this forum.

Supported by

[open] Trigger camera recording

amygdalaamygdala Posts: 15
edited May 2013 in OpenSesame

Hi,

I'd like to trigger camera recording in the middle of experiment, which could record the facial expression of the participants with built-in cameras. Unfortunately I only found audio input plug-in under the external devices. Is there a simple way that I can trigger the video recording?

What I've found is a software Ispy, which allows command line acess:
http://www.ispyconnect.com/userguide-commandline.aspx
I'm wondering whether I could send command using the python inline code, if there is no other way triggering the camera? I know very little about python und have no programming experience :(

Thanks in advance!

Ying

Comments

  • sebastiaansebastiaan Posts: 2,950
    edited 10:48AM

    Hi Ying,

    Recording video

    There are many ways to record video in Python, but it's always a little complicated. You can take a look at OpenCV. That's probably the best Python module for this kind of thing:

    I'm wondering whether I could send command using the python inline code, if there is no other way triggering the camera?

    In principle, yes: You can execute external commands using the Python subprocess module:

    I know very little about python und have no programming experience

    I'm afraid you will have to do a little coding here!

    An easy workaround

    If all of the above sounds to complicated, you could also consider simply recording the participant's faces with a standalone camera. You could have the experiment play a beep at the start of each trial, and feed this into the audio input of the camera, so that you have triggers to time-lock your analysis afterwards. Would that be an idea?

    Good luck!

    Cheers,
    Sebastiaan

    There's much bigger issues in the world, I know. But I first have to take care of the world I know.
    cogsci.nl/smathot

  • amygdalaamygdala Posts: 15
    edited July 2013

    Hello Sebastian,

    I've tried to do some coding to start video recording with OpenCV and the module Videocapture. I installed the python 2.7 and the python extension VideoCapture from http://videocapture.sourceforge.net/, as well as PIL1.1.7 and OpenCV 2.4.6.0. I wrote the following script in the python IDLE to test wether it works:
    image

    It did work well with python, which was pretty encouraging for the beginner like me. So I created a new experiment and simply copied the code to the OpenSesame Inline_script. It came out with an error message:
    image

    I didn't know how to install the VideoCapture into OpenSesame. So I copied the VideoCapture.py and vidcap.pyd to libopensesame like below and ran the experiment again.
    image

    Another error message showed up:
    image

    I could not understand the error. And I also made a compiled file of VideoCapture in the libopensesame to see if it worked better. Unluckily the result is depressing. Do you have an idea why this happened? And could you give me more suggestions how the modules like VideoCapture can be added to the OpenSesame and be used?

    Thank you as always!

    Ying

  • sebastiaansebastiaan Posts: 2,950
    edited 10:48AM

    Hi Ying,

    Well, you're almost there! Essentially, the font files need to be copied as well, which are the .png and .pil files located with VideoCapture.py in the VideoCapture download. Also, I would place the files directly in the OpenSesame folder, and not in the libopensesame subfolder.

    Alternatively, you could consider running OpenSesame from source, seeing as how you have already set up a Python environment:

    Good luck!

    Cheers,
    Sebastiaan

    There's much bigger issues in the world, I know. But I first have to take care of the world I know.
    cogsci.nl/smathot

  • amygdalaamygdala Posts: 15
    edited July 2013

    Hi Sebastiaan,

    it is indeed the problem with the .png and .pil files. It works good after copying. Thanks very very much for the tips.O:-)

    Now I've written a code with the help of the example 'exa3_observer.py' in the VideoCapture example files. There seems to be no example for video recording, but only capturing images. Is video recording achievable with VideoCapture?

    Anyway, I had following codes, which takes 30 pics per second. It worked well, but I am still wondering, whether this is the only way?? to make a video-like series of pictures, which need to be edited afterwards??

    from VideoCapture import Device
    import time, string
    
    ## Specify the amount of seconds to wait between individual captures.
    interval = 1.0 / 30
    vpnr = 5; ##No. of participant
    cam = Device()
    ## If you get horizontal stripes or other errors in the captured picture
    ## (especially at high resolutions), try setting showVideoWindow=0.
    #cam = Device(devnum=0, showVideoWindow=1)
    #cam = Device(devnum=1, showVideoWindow=1)
    
    ## Using the separate programs "setPropertiesDev0/1.pyw" before capturing
    ## works better for some devices.
    ## On the other hand, some devices don't remember their state, so the
    ## properties have to be set at every program start.
    #cam.displayCapturePinProperties()
    #cam.displayCaptureFilterProperties()
    
    print "press 'ctrl + c' to terminate"
    
    i = 0
    quant = interval * .1
    starttime = time.time()
    while i < 120:
        lasttime = now = int((time.time() - starttime) / interval)
        print i
        # FOLDER MUST EXIST
        cam.saveSnapshot('E:\Ying\\vp_' + str(vpnr) + '\\' + string.zfill(str(i), 4) + '.jpg', timestamp=3, boldfont=1)
        i += 1
        while now == lasttime:
            now = float((time.time() - starttime) / interval)
            time.sleep(quant)
    

    Another question is, how can I make the code running aside, while a film is played. (I want to record the facial expression when people watch film clips.) That is to say how to achieve the multi-tasking? As I imagined, there is a code, which triggers the camera and the recording is running and after the film there should be a stop-code which ends the recording. The strukture of OpenSesame GUI seems to be that the inline_script and the plug_ins would be executed one by one.

    I'm really appreciated that you are always there for various questions that we laymen have.

    And I wish you a nice evening!

    Ying

  • sebastiaansebastiaan Posts: 2,950
    edited 10:48AM

    Now I've written a code with the help of the example 'exa3_observer.py' in the VideoCapture example files. There seems to be no example for video recording, but only capturing images. Is video recording achievable with VideoCapture?

    Oddly enough, even though the package is called VideoCapture, it seems like you can only capture stills. But capturing a stream of stills and merging these afterwards should work perfectly well though. That's how I generally my optical illusions as well. A good tool to do this is MEncoder.

    Another question is, how can I make the code running aside, while a film is played. (I want to record the facial expression when people watch film clips.) That is to say how to achieve the multi-tasking?

    The easiest way to do this is using the parallel plug-in. You then add two sequences to the parallel item, the first to handle your trial execution, the second to run the VideoCapture script. The parallel plug-in doesn't work very well on some systems, I should add, but if it works well in your case then this would be the way to go.

    As an aside, I noticed that you manually specify the subject number. You could also just say:

    vpnr = self.get('subject_nr'); ##No. of participant
    

    See:

    Cheers!

    There's much bigger issues in the world, I know. But I first have to take care of the world I know.
    cogsci.nl/smathot

Sign In or Register to comment.