Welcome! Log In Create A New Profile

Advanced

Webcam data structure, frame count

Posted by aboharbf 
Webcam data structure, frame count
October 08, 2019 02:43PM
so upon loading the webcam data for a particular trial, I find that the frame data is an X * Y * N structure, where X and Y seem to reasonably be the pixels, and N would have to be the number of frames.

when observing the same trial in mlplayer, it is 4.3 seconds long, and the camera data plays next to it the whole time. at the 30 FPS I was using, this should produce 129 frames, but the N in the structure is 65. I doubled checked the appropriate MLConfig field and 30 FPS was the setting. 65 frames isn't even enough to cover all 2.8 seconds of my stimulus presentation, so I am curious where the number comes from, and how to access the rest of the frames. Any help would be great. Thanks a ton.

Side note: Upon converting a bhv2 with camera data to a .mat, It went from nearly 10 GB to just under 3.5 GB. Is this expected behavior?
Re: Webcam data structure, frame count
October 09, 2019 12:04PM
You should check if your webcam really captures 30 frames per second first. Many webcams work at 15 fps, although they say 30 fps. Maybe they are using the interlaced mode. Each frame captured in NIMH ML has a timestamp, so you can compare it with your trial length.

MAT compresses data. BHV2 doesn't. There is no time to compress video during experiments.
Re: Webcam data structure, frame count
November 07, 2019 03:32PM
Is the lack of compression why the data files for each trial with video are so enormous?
Re: Webcam data structure, frame count
November 08, 2019 12:15PM
Yes, that is the reason. I reduced the size by taking only 16-bit color formats, but it is still huge. Compression methods work only when the video is saved as a file and you cannot keep the compressed size once you load the video into MATLAB, so it is necessary to choose the frame size of the video wisely.

I am thinking of exporting the videos as separate AVIs, but then we cannot keep them in BHV2 and have to allow long ITIs between trials.
Re: Webcam data structure, frame count
November 25, 2019 07:12PM
I added a compression option to the webcam. Choose 'Export as MP4 (or AVI)' on the menu. This option will create the video of each trial as a separate file, which is necessary for the compression. The start time of the first frame is not 0 in the webcam video, so you should refer to the AnalogData.Webcam1.Time field for the timestamp of each video frame.

For data files already collected, you can use the mlexportwebcam function to extract videos and keep them slim.
https://monkeylogic.nimh.nih.gov/docs_RuntimeFunctions.html#mlexportwebcam

The National Institute of Mental Health (NIMH) is part of the National Institutes of Health (NIH), a component of the U.S. Department of Health and Human Services.