フィルターのクリア

readFrame() too slow. How to switch too VideoFileReader and VideoPlayer?

5 ビュー (過去 30 日間)
Sam
Sam 2020 年 8 月 4 日
コメント済み: Walter Roberson 2020 年 8 月 4 日
Hello,
I've written a code in which a user has to click on the video while it is being played. Unfortunately, the readFrame() method is too slow. I came across the VideoFileReader and VideoPlayer method, but I can't seem to figure out how to put a figure handle to the VideoPlayer window... In my code, I created a handle using image(temp,'Parent',curr_axes), but I can't seem to do the same for videoPlayer. Can anybody help?
%Load file
clear all, close all, clc;
fileList = dir('*.mp4');
video_name = fileList.name;
vid = VideoReader(video_name);
curr_axes = axes;
hfig = figure(1);
%Use callback function to register any mouse clicks on the figure
set(hfig,'WindowButtonDownFcn',@countclicks)
%Play video
framecount = 0;
while vid.hasFrame() %Play video
temp = vid.readFrame();
count = framecount + 1;
image(temp,'Parent',curr_axes);
if framecount == 1
figure(hfig);
p2 = imellipse;
vert_p2 = getVertices(p2);
wait(p2);
end
pause(0.05/25);
end

採用された回答

Walter Roberson
Walter Roberson 2020 年 8 月 4 日
%Load file
fileList = dir('*.mp4');
video_name = fileList(1).name;
vid = vision.VideoFileReader(video_name);
hfig = figure(1);
curr_axes = axes('Parent', hfig);
box(curr_axes, 'off');
imh = image(curr_axes, []); %establish the handle
%Use callback function to register any mouse clicks on the figure
set(hfig,'WindowButtonDownFcn',@countclicks)
%Play video
framecount = 0;
while ~isdone(vid) %read and play video
temp = step(vid);
count = framecount + 1;
set(imh, 'CData', temp);
if framecount == 1
p2 = imellipse(curr_axes);
vert_p2 = getVertices(p2);
wait(p2);
end
pause(0.05/25);
end
  2 件のコメント
Sam
Sam 2020 年 8 月 4 日
Thank you! But unfortunately, this videoreader is even slower in my case...
Walter Roberson
Walter Roberson 2020 年 8 月 4 日
How are you measuring the speed? Did you comment out the pause() and put in a tic and toc at appropriate places?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAudio and Video Data についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by