File: BoxBlurredVideoCaptureDemo.m

package info (click to toggle)
psychtoolbox-3 3.0.14.20170103%2Bgit6-g605ff5c.dfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 103,044 kB
  • ctags: 69,483
  • sloc: ansic: 167,371; cpp: 11,232; objc: 4,708; sh: 1,875; python: 383; php: 344; makefile: 207; java: 113
file content (121 lines) | stat: -rw-r--r-- 3,593 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
function ImagingVideoCaptureDemo(filtertype, kwidth)

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

if nargin < 1
    filtertype = 1;
end

if nargin < 2
    kwidth=11;
end;

try
    InitializeMatlabOpenGL;
    
    win=Screen('OpenWindow', screen, 0);

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

    % Set text size for info text. 24 pixels is also good for Linux.
    Screen('TextSize', win, 24);
        
    % Build a filter kernel:
    stddev = kwidth / 3;

    switch(filtertype)
        case 0
            kernel = [];
        case 1
            kernel = fspecial('gaussian', kwidth, stddev);
        case 2
            kernel = fspecial('prewitt');
        case 3
            kernel = fspecial('unsharp');
        case 4
            kernel = fspecial('sobel');
        case 5
            kernel = fspecial('log');
    end

    if filtertype > 0
        % Build shader from kernel:
        shader = EXPCreateStatic2DConvolutionShader(kernel, 3, 3, 0, 1);

        % Enable shader: It will apply to any further drawing operation:
        glUseProgram(shader);
    else
        % No filtering requested: Select fixed-function pipeline
        shader = 0;
    end
    
    grabber = Screen('OpenVideoCapture', win, 0, [0 0 640 480]);
    brightness = Screen('SetVideoCaptureParameter', grabber, 'Brightness',383)
    exposure = Screen('SetVideoCaptureParameter', grabber, 'Exposure',130)
    gain = Screen('SetVideoCaptureParameter', grabber, 'Gain')
    gamma = Screen('SetVideoCaptureParameter', grabber, 'Gamma')
    shutter = Screen('SetVideoCaptureParameter', grabber, 'Shutter',7)
    Screen('SetVideoCaptureParameter', grabber, 'PrintParameters')
    vendor = Screen('SetVideoCaptureParameter', grabber, 'GetVendorname')
    model  = Screen('SetVideoCaptureParameter', grabber, 'GetModelname')

    % Setup mirror transformation for horizontal flipping:

    % xc, yc is the geometric center of the text.
    [xc, yc] = RectCenter(Screen('Rect', win));

    % Translate origin into the geometric center of text:
    Screen('glTranslate', win, xc, 0, 0);
    % Apple a scaling transform which flips the direction of x-Axis,
    % thereby mirroring the drawn text horizontally:
    Screen('glScale', win, -1, 1, 1);
    % We need to undo the translations...
    Screen('glTranslate', win, -xc, 0, 0);
    % The transformation is ready for mirrored drawing:

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

    oldpts = 0;
    count = 0;
    t=GetSecs;
    while (GetSecs - t) < 600 
        if KbCheck
            break;
        end;
        
        [tex pts nrdropped]=Screen('GetCapturedImage', win, grabber, 1);
        % fprintf('tex = %i  pts = %f nrdropped = %i\n', tex, pts, nrdropped);
        
        if (tex>0)
            

            % Draw new texture from framegrabber.
            Screen('DrawTexture', win, tex, [], [], 0, 0); %Screen('Rect', win));
            
    
            % Print pts:
%            Screen('DrawText', win, sprintf('%.4f', pts - t), 0, 0, 255);
             if count>0
                % Compute delta:
                delta = (pts - oldpts) * 1000;
                oldpts = pts;
 %               Screen('DrawText', win, sprintf('%.4f', delta), 0, 20, 255);
            end;
            
            % Show it.
            Screen('Flip', win);
            Screen('Close', tex);
            tex=0;
        end;        
        count = count + 1;
    end;
    telapsed = GetSecs - t
    Screen('StopVideoCapture', grabber);
    Screen('CloseVideoCapture', grabber);
    sca;
    avgfps = count / telapsed
catch
   sca;
end;