フィルターのクリア

readFrame to slow, is there a faster way?

8 ビュー (過去 30 日間)
david csernay
david csernay 2017 年 11 月 18 日
コメント済み: david csernay 2017 年 11 月 20 日
Hello
I want to "cut out" objects that are placed in front of a green screen in real time, and replace the background with a video.
The object extraction itself works fine (tested with a simple image as background).
Then i tried to implement a background video with 'readFrame', but the background video runs in slow motion (see files attached), plus the live stream gets laggy too.
Is there a faster way to acquire single video frames and process them?
Thanks for any help!
function example1
% webcam
cam = videoinput('winvideo',1);
% get background image
img1 = getsnapshot(cam);
% video objekt
vidobj1 = VideoReader('Testvideo.mp4');
% background
background = readFrame(vidobj1,'native');
background = imresize(background, [size(img1, 1), size(img1, 2)]);
img = imshow(background,'InitialMagnification','fit');
% Set a custom preview function
setappdata(img,'UpdatePreviewWindowFcn',@mypreview_fcn);
% Call preview with the custom image
preview(cam,img);
function mypreview_fcn(obj,event,himage)
% receive the image in event.Data
foreground = event.Data;
background = readFrame(vidobj1,'native');
[overlayed,a] = greenScreen(foreground, background);
% Display
set(img, 'CData', overlayed);
end
end

採用された回答

Walter Roberson
Walter Roberson 2017 年 11 月 18 日
  5 件のコメント
Walter Roberson
Walter Roberson 2017 年 11 月 20 日
There is im2double instead of im2single() . Without testing it is difficult to say which would lead to faster code.
david csernay
david csernay 2017 年 11 月 20 日
Ok, with im2double the extraction works, but the video is still slow.
How would you approach the problem? Is there another way for object extraction? Actually, i would like to keep the green screen method, because of its good extraction results.

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

その他の回答 (1 件)

Image Analyst
Image Analyst 2017 年 11 月 19 日
You could store the video on a solid state drive instead of a hard drive.
  1 件のコメント
david csernay
david csernay 2017 年 11 月 19 日
The Laptop i use has an SSD only. Or did i missunderstand your answer?

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

Community Treasure Hunt

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

Start Hunting!

Translated by