www.gusucode.com > IPCV_Eval_Kit_R2019a_0ce6858工具箱matlab程序源码 > IPCV_Eval_Kit_R2019a_0ce6858/code/demo_files/I3_11_1_bfilter_movie.m

    %% GPU Coder 僨儌 : Bilateral Filter偺崅懍壔
% Bilateral Filter偼僄僢僕僉乕僾宆偺僼傿儖僞偲偟偰傕椙偔抦傜傟偰偍傝丄
% 堛梡夋憸張棟側偳條乆側暘栰偱梡偄傜傟偰偄傑偡丅
% 婸搙嵎偵墳偠偰廳傒晅偗寁嶼傪峴偆昁梫偑偁傞偨傔丄
% 儖乕僾暥偱嬊強椞堟傪拪弌 > 廳傒寁嶼 > 僼傿儖僞儕儞僌丄偲偄偭偨棳傟偵側傝傑偡丅
%
% 張棟帺懱偼偄傢備傞僗僥儞僔儖寁嶼偺堦庬偲側傝傑偡偑丄偙傟傪GPU Coder傪巊偭偰
% 崅懍壔傪峴偄傑偡丅
%
% 杮僨儌傪幚峴偡傞偨傔偵偼丄GPU偑搵嵹偝傟偰偄傞儅僔儞偑昁梫偲側傝傑偡丅
% 幚峴偵昁梫側僨僶僀僗丄僣乕儖摍偺弨旛偵偮偒傑偟偰偼丄壓婰僪僉儏儊儞僩傪偛棗偔偩偝偄.
% <https://www.mathworks.com/help/releases/R2017b/gpucoder/getting-started-with-gpu-coder.html>
% 

clear; close all; clc;
%% 價僨僆撉傒庢傝梡&價儏乕儚乕僆僽僕僃僋僩偺掕媊
videoFReader = vision.VideoFileReader('potholes2.avi');
videoPlayer = vision.VideoPlayer;

%% 僼儗乕儉儗乕僩寁應梡曄悢掕媊
t = tic();
cnt = 1;
fps = single(0.0);

%% Stop 儃僞儞昞帵
a=true;
sz = get(0,'ScreenSize');
figure('MenuBar','none','Toolbar','none','Position',[20 sz(4)-100 100 70])
uicontrol('Style', 'pushbutton', 'String', 'Stop',...
        'Position', [20 20 80 40],...
        'Callback', 'a=false;');

%% 儖乕僾嵞惗
reset(videoFReader)
while ~isDone(videoFReader) && a
    videoFrame = videoFReader(); %1僼儗乕儉撉傒崬傒
    bimg = bfilter2cGPC(videoFrame); %Bilateral Filter張棟
    bimg = insertText(bimg, [20 20], ['Running at ' num2str(round(fps,2)) 'fps'],...
        'Font', 'Calibri', 'FontSize', 14, 'BoxOpacity',0.6,'TextColor','black');
    
    videoPlayer([videoFrame bimg]);
    
   % 帪娫寁應
   % 5僼儗乕儉偺強梫帪娫偐傜僼儗乕儉儗乕僩傪寁應
   cnt = cnt + 1;
   if (mod(cnt,5) == 0)
       t = toc(t);
       fps = single(5/t);
       t = tic();
   end

end

%% GPU Coder傪棙梡偟偰MEX惗惉
cfg = coder.gpuConfig('mex');
codegen -args {videoFrame} -config cfg bfilter2cGPC -o bfilter2cGPC_mex

%% 儖乕僾嵞惗
t = tic();
cnt = 1;
a = true;
fps2 = single(0.0);
reset(videoFReader)
reset(videoPlayer)
while ~isDone(videoFReader)
    videoFrame = videoFReader(); %1僼儗乕儉撉傒崬傒
    bimg = bfilter2cGPC_mex(videoFrame); %Bilateral Filter張棟(MEX)
    bimg = insertText(bimg, [20 20], ['Running at ' num2str(round(fps2,2)) 'fps'],...
        'Font', 'Calibri', 'FontSize', 14, 'BoxOpacity',0.6,'TextColor','black');
    
    videoPlayer([videoFrame bimg]);
    
   % 帪娫寁應
   % 5僼儗乕儉偺強梫帪娫偐傜僼儗乕儉儗乕僩傪寁應
   cnt = cnt + 1;
   if (mod(cnt,5) == 0)
       t = toc(t);
       fps2 = single(5/t);
       t = tic();
   end

end

%% MEX壔偵傛傞崅懍壔偺妱崌
fps2 / fps

%%
release(videoFReader)
release(videoPlayer)

%% 
% Copyright 2018 The MathWorks, Inc.