how to get started with training image labeler?

Hi everyone,
I'm a newbie to Matlab and I need to use "computer vision" for "trainCascadeObjectDetector". I have two options, either to use Cascade trainer or  training image labeler app, which one is better? I tried to use training image labeler and I got .mat file exported after but I don't know what is the next step. any help will be appreciated!
When I clicked generate Matlab code I got the following code:
        
function importfile(fileToRead1)
    %IMPORTFILE(FILETOREAD1)
    %  Imports data from the specified file
    %  FILETOREAD1:  file to read
    
    %  Auto-generated by MATLAB on 29-Oct-2015 19:09:24
    
    % Import the file
    newData1 = load('appleSession-mat', fileToRead1);
    
    % Create new variables in the base workspace from those fields.
    vars = fieldnames(newData1);
    for i = 1:length(vars)
        assignin('base', vars{i}, newData1.(vars{i}));
    end
When I run it I got the following error:
       
 >> importfile
    Not enough input arguments.
    
    Error in importfile (line 9)
    newData1 = load('appleSession-mat', fileToRead1);

 Accepted Answer

Hi Shahad,
If you use the Training Image Labeler app, once you are done labeling the objects, you have to click the "Export ROIs" button. The one with the "checkmark" icon. This will create a variable in your workspace called positiveInstances, which contains the image file names and the bounding boxes that you have labeled. This is one of the inputs into trainCascadeObjectDetector function.

8 Comments

Thanks Dima for your reply. Yes I got positiveInstances and I already read these two tutorial before but I can't understand the following:
1) How can I generate stopSignImages, which they are using in this line of code?
mDir = fullfile(matlabroot,'toolbox','vision','visiondata','stopSignImages');
2) Also, how can I get the path so that I can write fullfile similar to the above line of code? (I'm a mac user)
3) what should I do to get stopSignDetector.xml? and what is data in the following line of code?
trainCascadeObjectDetector('stopSignDetector.xml',data,negativeFolder,'FalseAlarmRate',0.2,'NumCascadeStages',5);
I'm waiting for you reply :)
Thanks.
Hi Shahad,
What kind of objects are you trying to detect?
1,2) The stop sign images are sample images supplied with the Computer Vision System Toolbox to illustrate how to use trainCascadeObjectDetector. The output of
fullfile(matlabroot,'toolbox','vision','visiondata','stopSignImages');
is the directory where those images are stored.
3) stopSignDetector.xml is the name of the xml file that trainCascadeObjectDetector creates in the example. When you train your own object detector you would need to tell it what to name the output file.
data is the array of structures containing the positive instances. It is stored in stopSigns.mat.
By the way, here is another tutorial.
Thanks Eng.Dima for your fast and helpful reply :)
I need to detect apple, banana, orange and Kiwi. Any advices? I will be glad to gain from you experience.
I'm really happy the following code work perfectly:
load('stopSigns.mat');
imDir = fullfile(matlabroot,'toolbox','vision','visiondata','stopSignImages');
addpath(imDir);
negativeFolder = fullfile(matlabroot,'toolbox','vision','visiondata','nonStopSigns');
trainCascadeObjectDetector('stopSignDetector.xml',data,negativeFolder,'FalseAlarmRate',0.2,'NumCascadeStages',5);
%%Use the newly trained classifier to detect a stop sign in an image
detector = vision.CascadeObjectDetector('stopSignDetector.xml');
img = imread('stopSignTest.jpg'); % read the test image
bbox = step(detector, img); % detect a stop sign
% Insert bounding box rectangles and return marked image
detectedImg = insertObjectAnnotation(img, 'rectangle', bbox, 'stop sign You did it :)');
figure; imshow(detectedImg); % display the detected stop sign
rmpath(imDir); % remove the image directory from the path
For bananas, oranges, and kiwis, I would start with color segmentation. Try the Color Thresholder App in the Image Processing Toolbox.
As a starting step we will start with simple objects to detect then recognize. Then we will extend our system to detect and recognize more food types like: rice, corns , and many more food types. So do you think color segmentation will work well with a lot of food types? or it's better to develop our system using computer vision?
Thanks Dima.
Hi Shahad,
I am a newbie in mat;ab too...still trying to create my own object detector....in the code above, I noticed that you are using a variable named data in:
trainCascadeObjectDetector('stopSignDetector.xml', data*,negativeFolder,'FalseAlarmRate',0.2,'NumCascadeStages',5);
But I can't see any assignment value for the data....and hence, I got error when I tried the code.....How to solve it?
Thank you
NR
data in the example comes from the .mat file, which the example loads. It must be a struct array containing image file names and bounding boxes. You can create it using Training Image Labeler app.
Hi Dima, I am also trying to do trainCascadeObjectDetector to detect blood capillaries ( 15 capillaries) , and use image processing to compare one by one with the same capilar (example: capilar one with capilar 1 centrifuged). Is this viable? any advice? thanks for helping and for this and future advice.

Sign in to comment.

More Answers (0)

Asked:

on 29 Oct 2015

Commented:

on 2 Dec 2016

Community Treasure Hunt

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

Start Hunting!