作者WasiTerry (小眼)
看板MATLAB
标题[问题]储存特定图片卡住
时间Mon Dec 9 14:16:04 2013
我想要撷取画面中有任何变动的图片
但是在倒数第4行储存的步骤会卡住
saveas( h , [ 'n' , num2str( n ) , '.jpg' ] )
是我的指令用错吗?还是我少了哪个步骤?
以下是我目程式
%% 纯粹RGB影像入侵侦测
tic %计时开始
close all %关闭所有(图)视窗
clear all
clc
vr = VideoReader('0041.wmv'); %读取影片
Yrgb_g = read(vr,1);
Nfrm_movie = floor(vr.Duration * vr.FrameRate); %影片frame数
area_total=vr.Width*vr.Height; %画面总面积
start_frame=10; %起始frame
sample_rate=10; %采样频率
end_frame=300; %停止frame
for k = start_frame:sample_rate:end_frame
Yrgb1 = read(vr, k); % 读取当前影像
Yrgb2= read(vr,k-1); %读取前一张影像
Yrgb_abs =abs( Yrgb2-Yrgb1); %连续影像相减後取绝对值
% Yrgb_abs =abs( Yrgb_g-Yrgb1); %背景影像相减後取绝对值
Ybw= im2bw(Yrgb_abs,0.1); %二值化处理
subplot(2,3,1); imshow(Yrgb1);
title('当前影像');
subplot(2,3,2); imshow(Ybw);
title('RGB二值化');
se=strel('square',60); %设定形态学处理用遮罩
hh=imclose(Ybw,se); %闭合
% hh=imopen(hh,se); %断开
subplot(2,3,3); imshow(hh);
title('去小团块前');
area_th=round(area_total*0.004);%依照画面解析度设定阀值
hh=bwareaopen(hh,area_th); %依照阀值去除小团块
subplot(2,3,4); imshow(hh);
title('去小团块後');
mth=nonzeros(hh); %读取影像中所有非0的值
mth=sum(mth); %加总所有值
if mth>= (area_th) %判断是否大於阀值
subplot(2,3,5); imshow(hh);
saveas( h , [ 'n' , num2str( n ) , '.jpg' ] );
title('有东西瞬间');
end
end
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 120.107.168.104