MatLabscript lijndetectie: Difference between revisions

From Control Systems Technology Group
Jump to navigation Jump to search
No edit summary
No edit summary
 
(12 intermediate revisions by 3 users not shown)
Line 1: Line 1:
<code|18px>
<code style="font-size:14px">
clear all<br>
<br>
close all<br>
clear all<br>
clc<br>
close all<br>
<br>
clc<br>
%%Loading in the video<br>
<br>
videoPlayer = vision.VideoPlayer('Name','Original Image','Position', [100, 200, 400, 400]);<br>
%%Loading in the video<br>
outputPlayer = vision.VideoPlayer('Name','Threshold','Position',[600,200, 400, 400]);<br>
videoPlayer = vision.VideoPlayer('Name','Original Image','Position', [100, 200, 400, 400]);<br>
outputPlayer2 = vision.VideoPlayer('Name','Skeleton','Position',[1100,200, 400, 400]);<br>
outputPlayer = vision.VideoPlayer('Name','Threshold','Position',[600,200, 400, 400]);<br>
release(outputPlayer); release(videoPlayer);<br>
outputPlayer2 = vision.VideoPlayer('Name','Skeleton','Position',[1100,200, 400, 400]);<br>
nr=0;<br>
release(outputPlayer); release(videoPlayer);<br>
videoReader = vision.VideoFileReader('topcamvideo.avi');<br>
nr=0;<br>
% outputPlayer = vision.outputPlayer<br>
videoReader = vision.VideoFileReader('topcamvideo.avi');<br>
<br>
% outputPlayer = vision.outputPlayer
<br>
<br>
while isOpen(videoPlayer) || nr==0<br>
<br>
while isOpen(videoPlayer) || nr==0 <br>
     frame = step(videoReader);<br>
     frame = step(videoReader);<br>
     frame = rgb2gray(frame);    %Converting to black and white (single matrix)<br>
     frame = rgb2gray(frame);    %Converting to black and white (single matrix)<br>
     step(videoPlayer,frame)<br>
     step(videoPlayer,frame)<br>
     videoPlayer.step(frame)<br>
     videoPlayer.step(frame)<br>
<br>
<br>
%%Threshold    <br>
%%Threshold    <br>
% Filters the image, above a certain threshold will become 1 (white), below<br>
% Filters the image, above a certain threshold will become 1 (white), below<br>
% the threshold will become 0 (black).<br>
% the threshold will become 0 (black).<br>
     bin_img=im2bw(frame, 0.3);  %Creating a binary image [original, value]<br>
     bin_img=im2bw(frame, 0.3);  %Creating a binary image [original, value]<br>
     bin_img=imopen(bin_img,strel('square',3));    % image opening<br>
     bin_img=imopen(bin_img,strel('square',3));    % image opening<br>
Line 29: Line 30:
     step(outputPlayer,bin_img)<br>
     step(outputPlayer,bin_img)<br>
     <br>
     <br>
%%Skeleton function (was not used, but could be useful)<br>
%%Skeleton function (was not used, but could be useful)<br>
% Filters the image, creates an medial axis (hartlijn) at every point of<br>
% Filters the image, creates an medial axis (hartlijn) at every point of<br>
% the blob. The middle pixels of the thick lines remain white.<br>
% the blob. The middle pixels of the thick lines remain white.<br>
     skel_img=bwmorph(bin_img,'skel',15);<br>
     skel_img=bwmorph(bin_img,'skel',15); <br>
     hor_skel_img=imopen(skel_img,strel('line',5,0));        %Filtering out horizontal lines [minlength,angle]<br>
     hor_skel_img=imopen(skel_img,strel('line',5,0));        %Filtering out horizontal lines [minlength,angle]<br>
     hor_skel_img=imclose(hor_skel_img,strel('disk',5));  <br>
     hor_skel_img=imclose(hor_skel_img,strel('disk',5));  <br>
Line 38: Line 39:
     ver_skel_img=imclose(ver_skel_img,strel('disk',5));<br>
     ver_skel_img=imclose(ver_skel_img,strel('disk',5));<br>
     skel_img=hor_skel_img+ver_skel_img;                    %Adding horizontal + vertical<br>
     skel_img=hor_skel_img+ver_skel_img;                    %Adding horizontal + vertical<br>
%    skel_img=imdilate(skel_img,strel('disk',9));<br>
%    skel_img=imdilate(skel_img,strel('disk',9));<br>
%    skel_img=imerode(skel_img,strel('disk',5));<br>
%    skel_img=imerode(skel_img,strel('disk',5));<br>
       <br>
       <br>
     outputPlayer2.step(skel_img)<br>
     outputPlayer2.step(skel_img) <br>
     step(outputPlayer2,skel_img)<br>
     step(outputPlayer2,skel_img) <br>
     <br>
     <br>
     nr=nr+1;<br>
     nr=nr+1; <br>
end<br>
end<br>
videoPlayer.hide(); outputPlayer.hide(); outputPlayer2.hide();<br>
videoPlayer.hide(); outputPlayer.hide(); outputPlayer2.hide();<br>
close all;<br>
close all; <br>
</code>
</code>
 
----
 
Terug naar: [[PRE2015_2_Groep2]], [[Uitbal detectie]]

Latest revision as of 00:18, 15 January 2016



clear all
close all
clc

%%Loading in the video
videoPlayer = vision.VideoPlayer('Name','Original Image','Position', [100, 200, 400, 400]);
outputPlayer = vision.VideoPlayer('Name','Threshold','Position',[600,200, 400, 400]);
outputPlayer2 = vision.VideoPlayer('Name','Skeleton','Position',[1100,200, 400, 400]);
release(outputPlayer); release(videoPlayer);
nr=0;
videoReader = vision.VideoFileReader('topcamvideo.avi');
% outputPlayer = vision.outputPlayer

while isOpen(videoPlayer) || nr==0
frame = step(videoReader);
frame = rgb2gray(frame); %Converting to black and white (single matrix)
step(videoPlayer,frame)
videoPlayer.step(frame)

%%Threshold
% Filters the image, above a certain threshold will become 1 (white), below
% the threshold will become 0 (black).
bin_img=im2bw(frame, 0.3); %Creating a binary image [original, value]
bin_img=imopen(bin_img,strel('square',3));  % image opening
bin_img=imclose(bin_img,strel('square',5));  % image closing
outputPlayer.step(bin_img)
step(outputPlayer,bin_img)

%%Skeleton function (was not used, but could be useful)
% Filters the image, creates an medial axis (hartlijn) at every point of
% the blob. The middle pixels of the thick lines remain white.
skel_img=bwmorph(bin_img,'skel',15);
hor_skel_img=imopen(skel_img,strel('line',5,0)); %Filtering out horizontal lines [minlength,angle]
hor_skel_img=imclose(hor_skel_img,strel('disk',5));
ver_skel_img=imopen(skel_img,strel('line',5,90)); %Filtering out vertical lines [minlength,angle]
ver_skel_img=imclose(ver_skel_img,strel('disk',5));
skel_img=hor_skel_img+ver_skel_img; %Adding horizontal + vertical
% skel_img=imdilate(skel_img,strel('disk',9));
% skel_img=imerode(skel_img,strel('disk',5));

outputPlayer2.step(skel_img)
step(outputPlayer2,skel_img)

nr=nr+1;
end
videoPlayer.hide(); outputPlayer.hide(); outputPlayer2.hide();
close all;

Terug naar: PRE2015_2_Groep2, Uitbal detectie