Home > data-import > supporting_functions > lib > main_detect_objects_3.m

main_detect_objects_3

PURPOSE ^

SYNOPSIS ^

function [blob_size_all, blob_center_all, blob_dyn_all, time] = main_detect_objects_3(jpg_folder, output_folder, agent_type, obj_num, obj_params, img_step, overwrite_flag)

DESCRIPTION ^

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [blob_size_all, blob_center_all, blob_dyn_all, time] = main_detect_objects_3(jpg_folder, output_folder, agent_type, obj_num, obj_params, img_step, overwrite_flag)
0002 
0003 if obj_num > 3
0004     error('This script is for processing experiments with 3 objects only');
0005 end
0006 
0007 if ~exist('img_step', 'var')
0008     img_step = 1;
0009 end
0010 
0011 if ~exist('overwrite_flag', 'var')
0012     overwrite_flag = true;
0013 end
0014 
0015 ratio = 0.5;    % resize the images before object detection to increase processing speed.
0016 
0017 if ~exist(output_folder, 'dir')
0018     mkdir(output_folder);
0019 end
0020 
0021 jpg_list = dir(fullfile(jpg_folder, 'img_*.jpg'));  % hard coding
0022 
0023 img_seq_pos = -1;
0024 jpg_list = sort_file_name_by_seq(jpg_list, img_seq_pos);  
0025 [jpg_list, seq_no] = extract_img_name_list(jpg_list, img_step, img_seq_pos);
0026 time = frame_num2time(seq_no, sub_id);
0027 
0028 N = length(jpg_list);
0029 
0030 blob_size_all = nan(N,(obj_num+1));
0031 blob_center_all = nan(N,(obj_num+1)*2);
0032 blob_dyn_all = nan(N,(obj_num+1));
0033 
0034 fprintf('frame       ');
0035 
0036 for j=1:N        
0037     fprintf('\b\b\b\b\b\b%5d:', seq_no(j));
0038     if overwrite_flag
0039         jpg = jpg_list(j).name;       
0040         img = imread(fullfile(jpg_folder, jpg));
0041         img = imresize(img, ratio);
0042         
0043         [img_h, img_w] = size(img(:,:,1));
0044         total_pix = img_h*img_w;
0045 
0046         [blob_size, blob_center, blob_cells] = ...
0047             detect_color_object(img, agent_type, obj_num, obj_params);
0048         
0049         % combine four binary images into one.
0050         seg_img = combine_obj_detection_results(blob_cells, img_h, img_w);
0051         if j == 1
0052             blob_dyn = nan(1,obj_num+1);
0053         else
0054             blob_dyn = cal_dyn_obj_size(obj_num, total_pix, prev_blob_cells, blob_cells);
0055         end
0056         prev_blob_cells = blob_cells;
0057 
0058         blob_size_all(j,:) = blob_size;
0059         blob_center_all(j,:) = blob_center;
0060         blob_dyn_all(j,:) = blob_dyn;
0061 
0062         output_file_name = fullfile(output_folder, sprintf('img_%g_seg.jpg', seq_no(j)));
0063         imwrite(seg_img, output_file_name);
0064     end
0065 end
0066 
0067 end
0068

Generated on Tue 23-May-2017 03:00:58 by m2html © 2005