Presenting webcam on PsychoPy

I am hoping to present 3 videos and webcam footage on one screen in my PsychoPy experiment. I have added the 3 video stimuli to the screen and have used the code below to turn on the webcam on my laptop and get it to take a still picture, which it presents to me after the experiment.
Does anyone have any suggestions for how to add code that will present the webcam footage (as a video or as several still frames) on the screen as it’s recording it? Thank you for any help.

Code:

from psychopy import visual, event, core
from PIL import Image
import time, pylab, cv2, numpy
myWin = visual.Window(allowGUI=False, monitor=‘testMonitor’, units=‘norm’,colorSpace=‘rgb’,color=[-1,-1,-1], fullscr=True)
myWin.setMouseVisible(True)
cam = cv2.VideoCapture(0)
cam.open(0, cv2.CAP_DSHOW)
status, frame = cam.read()
cv2.imshow(‘camera1’, frame)
visual.ImageStim(myWin, image=frame)
webcam = Image.fromarray(frame, ‘RGB’)
webcam.show()

Hi There,

There is some info on how to sample and present the webcam through code here that might help.

I personally would add code snippets to builder so that I could easily present the movie alongside the webcam stream! Here is a demo that might help.

webcam.psyexp (7.5 KB)

Hope this helps!
Becca

Hi Becca,
Wonderful, this is great! You have no idea how much this has helped, thanks so much!
Best, Chloe