Hi
I am try to set an experiment where I have a real-time webcam (30fps) on screen and I would like to apply an image process (e.g., filter the blue channel or converting the image to grayscale) to this video and at the same time I want to present stimulus on screen that has to flicker at specific frequencies (e.g., an object flickering at 8 Hz).
I am using the piece of code (below) to capture the video and put it on screen. However, if I set 'waitforImage' to zero, the flip is not longer ~1/60 (i.e., monitor refresh rate) so it doesn't ensure my stimulus flickers at a desire frequency. On the other hand, if I set 'waitforImage' to 4 it displays the video just fine and presents the stimulus at the right frequencies but the pointer out from 'GetCaptureImage' doesn't return any image (it returns 0) thus I can't do any image processing on-line procedure to the video and display it in real time. How can I do image processing on the video, flick stimulus on the video (when necessary) and all that while ensuring the 'flip' goes at 1/60Hz?
Screen('HookFunction'..., maybe? Is there another fast command to capture and display video than using the little known PsychCV and it's ARRenderImage arguments? I have tried using Screen('DrawTexture'.... but it's really slow and clearing the image (so it frees memory) every flip (loop iteration) just makes even slower affecting the frequency of all stimuli. Using the code below was the only way so far I've been able to displays the video, generate the stimuli at the right frequency at any time but I can't do any image processing to the video image.
Screen('GetCapturedImage', win, grabber, 0, [], 4, imgbuffer);
Screen('BeginOpenGL', win);
glClear(GL.DEPTH_BUFFER_BIT); % Clear z-buffer
PsychCV('ARRenderImage'); % Render current video image as backdrop
Screen('EndOpenGL', win);
Screen('DrawTexture', win, TextureCornerSq{1}, [], CornerPos);
if count >= 100 && count <= 400
if mod(count, 8) == 1
Screen('DrawTexture', win, TextureCornerSq{2}, [], CornerPos);
Screen('DrawTexture', win, TextureWhiteSq, [], position);
else
Screen('DrawTexture', win, TextureCornerSq{1}, [], CornerPos);
Screen('DrawTexture', win, TextureBlackSq, [], position);
end
end
Thanks in advance,
Alex
I am try to set an experiment where I have a real-time webcam (30fps) on screen and I would like to apply an image process (e.g., filter the blue channel or converting the image to grayscale) to this video and at the same time I want to present stimulus on screen that has to flicker at specific frequencies (e.g., an object flickering at 8 Hz).
I am using the piece of code (below) to capture the video and put it on screen. However, if I set 'waitforImage' to zero, the flip is not longer ~1/60 (i.e., monitor refresh rate) so it doesn't ensure my stimulus flickers at a desire frequency. On the other hand, if I set 'waitforImage' to 4 it displays the video just fine and presents the stimulus at the right frequencies but the pointer out from 'GetCaptureImage' doesn't return any image (it returns 0) thus I can't do any image processing on-line procedure to the video and display it in real time. How can I do image processing on the video, flick stimulus on the video (when necessary) and all that while ensuring the 'flip' goes at 1/60Hz?
Screen('HookFunction'..., maybe? Is there another fast command to capture and display video than using the little known PsychCV and it's ARRenderImage arguments? I have tried using Screen('DrawTexture'.... but it's really slow and clearing the image (so it frees memory) every flip (loop iteration) just makes even slower affecting the frequency of all stimuli. Using the code below was the only way so far I've been able to displays the video, generate the stimuli at the right frequency at any time but I can't do any image processing to the video image.
Screen('GetCapturedImage', win, grabber, 0, [], 4, imgbuffer);
Screen('BeginOpenGL', win);
glClear(GL.DEPTH_BUFFER_BIT); % Clear z-buffer
PsychCV('ARRenderImage'); % Render current video image as backdrop
Screen('EndOpenGL', win);
Screen('DrawTexture', win, TextureCornerSq{1}, [], CornerPos);
if count >= 100 && count <= 400
if mod(count, 8) == 1
Screen('DrawTexture', win, TextureCornerSq{2}, [], CornerPos);
Screen('DrawTexture', win, TextureWhiteSq, [], position);
else
Screen('DrawTexture', win, TextureCornerSq{1}, [], CornerPos);
Screen('DrawTexture', win, TextureBlackSq, [], position);
end
end
Thanks in advance,
Alex