%otevÞen’ souboru a=VideoReader('thermalVideo_1530955666725.mp4'); %nastaven’ tresholdu od 0,5 do 0,8 for VI = 50:80 video = VideoWriter([num2str(VI),'_merenivideo_VERZE4_1530955666725.avi']); %vytvoÞen’ video objektu open(video); %otevÞen’ video souboru pro z‡pis %na‹ten’ videa sn’mek po sn’mku for img = 1:a.NumberOfFrames %for img = 160:620 K=read(a, img); rg = rgb2gray(K); BW = imadjust(rg,[(VI/100) 1],[]); T = adaptthresh(BW,0.1,'Statistic','gaussian'); BW1 = imbinarize(BW,T); c = bwconncomp(BW1,8); num = c.NumObjects; L = labelmatrix(c); s = regionprops(c, 'Area'); BW2 = ismember(L, find([s.Area] > 200 & [s.Area] <= 14000)); %nastaveni min a max co = bwconncomp(BW2,8); nco = co.NumObjects; switch nco case 1 SE = strel('diamond', 1); case 2 SE = strel('diamond', 100); case 3 SE = strel('diamond', 30); case 4 SE = strel('diamond', 10); otherwise SE = strel('diamond', 1); end J = imclose(BW2,SE); %uzavøení objektu clearvars BW2; BW2 = J; Area255 = sum(BW2(:)==1); cc = bwconncomp(BW2,8); number = cc.NumObjects; S = regionprops(cc, 'Area'); position = [25 50]; switch number case 1 size1 = [S(1).Area].'; box_color = {'green'}; value = ['Frame: ' num2str(img),', N. of O.: ' num2str(number),', size: ' num2str(round(size1/4)),' px ']; case 2 box_color = {'yellow'}; size1 = [S(1).Area].'; size2 = [S(2).Area].'; value = ['Frame: ' num2str(img),', N. of O.: ' num2str(number),', 1.: ' num2str(round(size1/4)),' px ',', 2.: ' num2str(round(size2/4)),' px ']; case 3 box_color = {'blue'}; size1 = [S(1).Area].'; size2 = [S(2).Area].'; size3 = [S(3).Area].'; value = ['Frame: ' num2str(img),', N. of O.: ' num2str(number),', 1.: ' num2str(round(size1/4)),' px ',', 2.: ' num2str(round(size2/4)),' px ',', 3.: ' num2str(round(size3/4)),' px ']; case 4 box_color = {'magenta'}; case 5 box_color = {'red'}; otherwise box_color = {'white'}; end value = ['Frame: ' num2str(img), ', N. of O.: ' num2str(number),', max: ' num2str(round(max( [S.Area] )/4)), ' px',', min: ' num2str(round(min( [S.Area] )/4)), ' px']; if (number > 0) && (number <=5) O = edge(BW2,'Canny',([])); O(:,:,2:3) = 0 ; C = imfuse(rg,O,'blend'); zaznam =(['detekce_VERZE4_',num2str(img),'_',num2str(VI),'_',num2str(number),'.jpg']); imwrite(popisek,zaznam); end if (number > 6) C = rg; end popisek = insertText(C,position,value,'FontSize',20,'BoxColor',box_color); writeVideo(video,popisek); end close(video); %close the file end