File: ImagingVideoCaptureDemo.m

package info (click to toggle)
psychtoolbox-3 3.0.19.14.dfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 86,796 kB
  • sloc: ansic: 176,245; cpp: 20,103; objc: 5,393; sh: 2,753; python: 1,397; php: 384; makefile: 193; java: 113
file content (103 lines) | stat: -rw-r--r-- 3,846 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
function ImagingVideoCaptureDemo

AssertOpenGL;
screen = max(Screen('Screens'));

try
    %Screen('Preference', 'Verbosity', 10);
    % Prepare pipeline for configuration. This marks the start of a list of
    % requirements/tasks to be met/executed in the pipeline:
    PsychImaging('PrepareConfiguration');

    % Ask pipeline to horizontally flip/mirror the output image, so user
    % doesn't get confused by orientation of its mirror image ;-)
    PsychImaging('AddTask', 'AllViews', 'FlipHorizontal');
    %PsychImaging('AddTask', 'General', 'UseRetinaResolution');
    %PsychImaging('AddTask', 'AllViews', 'InterleavedColumnStereo', 0);
    %PsychImaging('AddTask', 'AllViews', 'InterleavedLineStereo', 0);
    %PsychImaging('AddTask', 'AllViews', 'FlipVertical');
    %PsychImaging('AddTask', 'General', 'FloatingPoint16Bit');
    %PsychImaging('AddTask', 'General', 'EnableBits++Mono++Output');
    %PsychImaging('AddTask', 'AllViews', 'GeometryCorrection', '/Users/kleinerm/Library/Preferences/Psychtoolbox/GeometryCalibration/BVLCalibdata_0_1680_1050.mat');
    %PsychImaging('AddTask', 'AllViews', 'GeometryCorrection', '/home/kleinerm/.Psychtoolbox/GeometryCalibration/CSVCalibdata_0.mat');
    %Testblock for Radeon native 10bpc framebuffer support:
    %PsychImaging('AddTask', 'General', 'FloatingPoint16Bit');
    %PsychImaging('AddTask', 'General', 'EnableNative10BitFramebuffer');

    [win winRect]=PsychImaging('OpenWindow', screen, 0);

    % Initial flip to a blank screen:
    Screen('Flip',win);

    % Set mouse cursor shape to a cross-hair:
    ShowCursor('CrossHair');

    % Set text size for info text. 24 pixels is also good for Linux.
    Screen('TextSize', win, 24);

    % Setup shader for image blurring:
    blurshader = LoadGLSLProgramFromFiles('ParametricBoxBlurShader', 1);
    glUseProgram(blurshader);
    glUniform1i(glGetUniformLocation(blurshader, 'Image'), 0);
    glUniform1i(glGetUniformLocation(blurshader, 'FilterMap'), 1);
    glUseProgram(0);
    bluroperator = CreateGLOperator(win, [], blurshader, 'Parametric box blur operator.');

    grabber = Screen('OpenVideoCapture', win, 0);

    blurmaptex = Screen('OpenOffscreenWindow', win, 0, [0 0 640 480]);
    cr = CenterRect([0 0 640 480], winRect);

    Screen('StartVideoCapture', grabber, 30, 1);

    oldpts = 0;
    count = 0;
    ftex = 0;
    tex = 0;

    t=GetSecs;
    while ~KbCheck        
        [x y buttons] = GetMouse(win);
        [tex pts nrdropped]=Screen('GetCapturedImage', win, grabber, 1, tex);
        % fprintf('tex = %i  pts = %f nrdropped = %i\n', tex, pts, nrdropped);
        Screen('FillRect', win, [255 0 0], [1 1 1680 1050]);
        Screen('FillRect', win, [0 255 0], [0 0 10 10]);
        
        if (tex>0)
            %rect = Screen('Rect', tex)
            ftex = Screen('TransformTexture', tex, bluroperator, blurmaptex);
            
            % Draw new texture from framegrabber.
            Screen('DrawTexture', win, ftex); %, [], Screen('Rect', win));
            Screen('Close', ftex);

            Screen('DrawDots', win, [x ; y], 7, [255 255 0]);
            [xo, yo] = RemapMouse(win, 'AllViews', x, y);
            Screen('DrawDots', win, [xo ; yo], 5, [0 255 0]);

            % Show it.
            Screen('Flip', win);
        end

        count = count + 1;
        if any(buttons)
            x = xo - cr(RectLeft);
            y = yo - cr(RectTop);

            if buttons(1)
                blurlevel = 5;
            else
                blurlevel = 0;
            end
            Screen('FillRect', blurmaptex, blurlevel, CenterRectOnPoint([0 0 30 30], x, y));
        end
    end
    telapsed = GetSecs - t
    Screen('StopVideoCapture', grabber);
    Screen('CloseVideoCapture', grabber);
    sca;
    avgfps = count / telapsed
catch
   sca;
   psychrethrow(psychlasterror);
end