Code covered by the MathWorks Limited License

Highlights from
Cascade Trainer: Specify Ground Truth, Train a Detector


5.0 | 14 ratings Rate this file 287 Downloads (last 30 days) File Size: 2.02 MB File ID: #39627
image thumbnail

Cascade Trainer: Specify Ground Truth, Train a Detector



08 Mar 2013 (Updated )

Interactively specify rectangular ROIs in a list of images and build new cascade classifiers.

| Watch this File

File Information

Cascade Trainer app:
Interactive app for managing the selection and positioning of rectangular ROIs in a list of images, for specifying ground truth for training algorithms, and for creating new cascade classifiers.

   * Add/remove/rotate/sort images
   * Add/remove/reposition/ delete/copy/paste ROIs
   * NEW: Paste ROIs from a specified image through a range of images
   * Generate/export structure of image names and ROI positions
   * Save/restore sessions
   * Keyboard shortcuts designed to facilitate the process
If you plan on training a detector, or have other uses for multiple-ROI selection and management, this tool is for you!
Note that the zip file includes an mlappinstall file. You can use this GUI in the standard fashion, or double-click the mlappinstall file to install CascadeTrainGUI as an App on your App Toolbar.

Comments, suggestions welcome!

SEE ALSO: SegmentTool, MorphTool, ImadjustGUI, FindCirclesGUI


Create Button Label(String,Varargin) inspired this file.

This file inspired How To Apply Image Processing And Computer Vision Wih Matlab : Japanese Matlab Expo 2013 and Train Cascade Object Detector.

Required Products Image Processing Toolbox
Computer Vision System Toolbox
MATLAB release MATLAB 8.0 (R2012b)
MATLAB Search Path
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (89)
03 Nov 2014 Brett Shoelson

Also, generally speaking, the more positives (and useful negatives) you have for training, the better the performance of the detector. This document should be helpful in understanding the trade-offs between more/fewer images:


03 Nov 2014 Brett Shoelson

Thanks for the rating, Justin. Much appreciated!
I've been asked many times about extending this to work with video, but I haven't had the bandwidth to do so. However, the existing tools do facilitate a relatively easy interaction with video:

First, convert the video file to individual frames (images) and populate the image panel on the first tab of the CascadeTrainGui. Draw and copy (CTRL-1) the ROI(s) in the first frame of the video, scan to the next frame (RIGHT-CLICK or CTRL-N), and past (CTRL-2). Repeat until the scene changes. Then go back and tweak the positions frame-by-frame as necessary.

I know that 3500 frames is a lot to do this for--training is tedious! With that in mind, I just added a new "PasteROIsThrough" function to CascadeTrainGUI. With it, you can define and copy ROIs in one image, and specify the image number through which you want to paste them.

If you're interested in trying it out, please drop me an email directly and I will share it with you. I'd appreciate your comments/suggestions before I share the new version on the File Exchange.


03 Nov 2014 Justin H.

Greetings Brett,

I'm involved in a design project utilizing live object tracking via computer vision. My peers and I came across the cascading technique and your GUI recently and had a few questions on the process.

When using the GUI, is it necessary to manually create ROI's for every frame? A short test video of ours (simulated two-lane traffic driving from the horizon out the bottom of the frame) is roughly 3500 frames, which seems a lengthy task given how convenient this GUI seems to be. If that is not the case, then how should we go about placing ROI's?

Also, is there a good way to estimate exactly how many frames would be required in order to begin proper training? This goes hand-in-hand with the previous question, as we're currently under the impression that we wouldn't need every frame to get a well-trained detector for this single case. Thanks for any assistance, and nicely done on this GUI. As far as our knowledge tells us, it's an extremely useful alternative to standard training methods

02 Nov 2014 Justin H.  
31 Oct 2014 Brett Shoelson

Permission to write=denied suggests that you are trying to write to a location to which you don't have privileges. You might try putting a breakpoint on the save line (1269) and verifying that fullfile(pwd,fname) returns the value that you expect, and that you have write privileges for that location. Please let me know either way if this addresses the issue.

31 Oct 2014 Mark Angelo Purio

hi, i am still having problems with my implementation:

Error using save
Unable to write file C:\Program Files\MATLAB\R2014a\bin\Coral Detection.mat: permission denied.

Error in CascadeTrainGUI/saveSession (line 1269)

Error in CascadeTrainGUI/trainDetector (line 1876)

Error while evaluating uicontrol Callback

Can you help me with this???

28 Oct 2014 Brett Shoelson

@Hassan: Training--especially with a large training set--is memory-intensive. Two things you might consider: 1) upgrade to a 64-bit machine/MATLAB; and 2) if you were using Haar features (which are memory hogs), try LBP or HOG features instead.

Hope that helps!

27 Oct 2014 Hassan

getting the following errors during training:

Error using ocvTrainCascade
Error in c:\temp\a3p0_3607_2384\win32\opencv\modules\core\src\alloc.cpp: Insufficient

Error in trainCascadeObjectDetector (line 265)
ocvTrainCascade(filenameParams, trainerParams, cascadeParams, boostParams, ...

Error in CascadeTrainGUI/trainDetector (line 1965)
trainCascadeObjectDetector([CTS.SessionName '.xml'], ...

Error while evaluating uicontrol Callback
(Kindly help I m in urgent need)

11 Aug 2014 Mark Angelo Purio

@brett: oh.I apologize.
I wasn't able to read that post. Thank you very much.

07 Aug 2014 Brett Shoelson

You can get the version numbers of your particular tools by typing 'ver' at the Command Line. But again...please seem my comment dated March 8, 2013b below. You can use the Cascade Training GUI to specify ground truth in R2012b, or to use pre-trained detectors--but you'll need to update to R2013a (or later) to train new detectors.

07 Aug 2014 Mark Angelo Purio

Please see my comment dated Mar 8, 2013, below. What version of the Computer Vision System Toolbox do you have?

@brett: I am using MatLab R2012b but I don't know the version of my computer vision system toolbox.

27 Jul 2014 Brett Shoelson

The background images you sent me do not appear to be corrupt. I don't know if there are others that are corrupt downstream that are triggering these errors, or if something else is going on. You'll have to go into debug mode (try: >> dbstop if warning) and see if you can narrow down the offending image or command. If you see, for example, that you have successfully processed several negative images before the warnings are triggered, that would give you additional information.

24 Jul 2014 Sorath Asnani

Dear Sir, I have sent you images via email. Please have a look on that.

24 Jul 2014 Brett Shoelson

It appears that your negative images may be corrupt. Would you please send me ONE (small one)?

23 Jul 2014 Sorath Asnani

Dear Sir, when I am specifying the negative folder and starting training the detector, then I am getting lots of warnings like these specified below:

Warning: Did not recognize tag format 271.
Warning: Did not recognize tag format 272.
Warning: Did not recognize tag format 274.
Warning: Did not recognize tag format 282.
Warning: Did not recognize tag format 283.
Warning: Did not recognize tag format 296.
Warning: Did not recognize tag format 306.
Warning: Did not recognize tag format 529.
Warning: Did not recognize tag format 531.
Warning: Did not recognize tag format 532.
Warning: Did not recognize tag format 33432.
Warning: Did not recognize tag format 34665.
Warning: Did not recognize tag format 12601.
Warning: Did not recognize tag format 17197.
Warning: Did not recognize tag format 14646.
Warning: JPEG library error (8 bit), "Corrupt JPEG data: 10147 extraneous bytes before
marker 0xd9"."
Warning: Did not recognize tag format 271.
Warning: Did not recognize tag format 272.
Warning: Did not recognize tag format 274.
Warning: Did not recognize tag format 282.
Warning: Did not recognize tag format 283.
Warning: Did not recognize tag format 296.
Warning: Did not recognize tag format 306.
Warning: Did not recognize tag format 529.
Warning: Did not recognize tag format 531.
Warning: Did not recognize tag format 532.
Warning: Did not recognize tag format 33432.
Warning: Did not recognize tag format 34665.
Warning: Did not recognize tag format 12848.
Warning: Did not recognize tag format 17197.
Warning: Did not recognize tag format 14646.
Warning: JPEG library error (8 bit), "Corrupt JPEG data: 9715 extraneous bytes before
marker 0xd9"."

Every second lots of warnings are coming and training time is increased significantly.

I don't understand the reason behind that. Please help me to resolve this problem.

23 Jul 2014 Sorath Asnani

Dear Sir Brett! Thank you very much for your humble response. Regarding pixels, fortunately I have managed to solve the problem.
Regarding guns, for example I am training 2 different detectors, one for lets say "AK-47" and other for say "Beretta pistol". Is it possible to train a single detector which can detect both types of guns? Is there any technique through which both the detectors can be combined into one?

19 Jul 2014 Zainb

Hey Brette

wow your fix is truely working.
I'v reply you an email, please have a look over there
Remaining you fix is ready for next updation
thank you very much

18 Jul 2014 Brett Shoelson

Seems I have a bug in my code that is encountered if 'Auto-include ROI-deleted positives as negatives' is checked but no other negative images are specified. I sent you a fix (I think) via email; would you kindly try it out and let me know if it solves the issue? If it works, I will incorporate it in the next update.

In the meantime, if anyone else is running into this, specifying at least one non-automatic negative should fix the problem.


17 Jul 2014 Zainb

thank you for immediate reply. I just used ROI positive images by selecting the option "Auto-included ROI-deleted positives as negatives"
thank you
waiting for your reply

16 Jul 2014 Brett Shoelson

Thanks for the comments. I have a hard time knowing what is going on--can't reproduce the error. How did you define your negative images? Did you use "ROI-masked positives" or did you add negative images, or both?

I suppose that gun detection should work in this regard, though "gun" is pretty generic, and looks very different from different perspectives. You may need to create several different detectors for different types and views. I'm not sure I understand your question about about pixel size, nor what's going on. Are your ROIs too small, perhaps?


16 Jul 2014 Zainb

hey Brett!
I really appreciate your app. It makes life very easy.
I am actually facing an error when i click on 'Train Detector'.
Here error goes
"Error using trainCascadeObjectDetector>parseInputs (line 305)
The value of 'NEGATIVE_IMAGES' is invalid. Cannot open image '' numbered 1 in

Error in trainCascadeObjectDetector (line 160)
parser = parseInputs(varargin{:});

Error in CascadeTrainGUI/trainDetector (line 1965)
trainCascadeObjectDetector([CTS.SessionName '.xml'], ...

Error while evaluating uicontrol Callback"

Please help me resolving this, I'm really needing an urgent fix for this to complete my work
Thank you in anticipation.

09 Jul 2014 Sorath Asnani

Hello Dear Sir Brett!
I need your help in using this GUI. Actually I am making my own detector for detecting the guns.
My first question is, can you tell me based on your experience that will it be useful to train the cascade classifier for gun detection?
Next, when I used this GUI, the training images which are loaded in the window, are very much zoomed in. The pixels are just out of control. Is there any option to set the image to its original size?
Sir, I will be very much thankful to you if you guide me. Thanks.

20 Jun 2014 Brett Shoelson

Sorry, I don't have enough information to go on; not sure how to help you. If you would like to send me reproduction steps, I will try to help.


.Error using ocvTrainCascade
Error in generating samples for training. No samples could be generated for training the
first cascade stage.

please give me solution

17 Jun 2014 Brett Shoelson

Please see my comment dated Mar 8, 2013, below. What version of the Computer Vision System Toolbox do you have?

17 Jun 2014 Mark Angelo Purio

I am experiencing a problem with my training using the cascade training GUI.
This is the error I encountered:

Error in CascadeTrainGUI/trainDetector (line 1965)
trainCascadeObjectDetector([CTS.SessionName '.xml'], ...

Error while evaluating uicontrol Callback

Error using imread (line 368)
File "posStopSigns.png" does not exist.

Error in CascadeTrainGUI/explainUsePosAsNeg (line 841)
tmp = imread('posStopSigns.png');

Error while evaluating uicontrol Callback

Undefined function 'trainCascadeObjectDetector' for input arguments of
type 'struct'.

Error in CascadeTrainGUI/trainDetector (line 1965)
trainCascadeObjectDetector([CTS.SessionName '.xml'], ...

Error while evaluating uicontrol Callback

I hope you can help me

21 May 2014 Brett Shoelson

My UI shouldn't change any paths; if you called it 'Untitled', you should have a file called Untitled.xml in the working directory you were in when you pushed the "Train Detector" button. If you're not sure where you were and you lost the xml file, you may need to search for that with MS Explorer or some other file searching tool. (Even MATLAB!)

21 May 2014 bharath


Hey i ran a classifier for detecting bibs and the training was done for 13 of 20 stages. I saved the training session as Untitled. I dunno where it is saved. Do u know what the default folder is? Also by what name is the trained classifier now exist as as?

15 Apr 2014 Brett Shoelson

I sometimes show a version of the example that's in the vision.CascadeObjectDetector doc. After finding faces in the visionteam image, I crop a single face, rotate it incrementally, and re-run the detector. It's easy to show that the detector works well (on that particular image) with rotations up to about 20 degrees. Beyond that, this method will likely require an additional detector trained for tilted faces. (There are other approaches that might be more robust to rotations....).
And no, it doesn't matter if the training positives are the zame size. But it does matter that they are the same aspect ratio.
a demo that uses a cascade detector to find faces in a particular image. After finding al

15 Apr 2014 James

One more thing I forgot, sorry -- does it matter if your training/positive images are different sizes/resolutions after being cropped/selected for region of interest?

14 Apr 2014 James


Thanks a lot for making this. One question: how does the trained cascade deal with in-plane rotations? Not necessarily large rotations -- plus minus 30 degrees let's say. Furthermore, would providing the trainer with in-plane rotated images in the training set make it more robust to rotation in the detection stage? Thanks again for making this wonderful app!

11 Apr 2014 Brett Shoelson

Once you've trained the detector, you're pretty much done with this App. (You can apply the detector to single frames, but you'll probably want to create a script to do this on the individual video frames.)

Note that detection is relatively expensive; tracking is less so. You might consider detecting the object with your newly trained detector in the first frame, and tracking it through subsequent frames until you lose the track. Then retrain. Or maybe tracking through 10 frames, then retrain...

I've toyed with the idea of implementing a video tracking environment, but haven't had the bandwidth to do that just yet.


11 Apr 2014 Hetu Patel

@Brett :thank you sir.

Now i have made one detector which can detect tiger from image by using this thank you once again.Now my questions are :

->I can run detector for particular image but how could i apply it for video ??

I am using first a moving object detector for detect any animal out of the video which moves.
SO how can i apply THIS GUI for particular that detected (moving) animal whether it is tiger or not.

Thank you :)

19 Mar 2014 Kevin

Hi Brett,

I'm trying to install your app on Matlab 2013b, but I keep getting this error message:

com.mathworks.jmi.MatlabException: Failed to extract Matlab app file '/Users/kchai/Downloads/CascadeTrainGUI (1)/CascadeTrainGUI.mlappinstall' to '/Users/kchai/Documents/MATLAB/Apps/CascadeTrainGUI - 1' with internal errors
at com.mathworks.jmi.NativeMatlab.SendMatlabMessage(Native Method)
at com.mathworks.jmi.NativeMatlab.sendMatlabMessage(
at com.mathworks.jmi.MatlabLooper.sendMatlabMessage(
at com.mathworks.jmi.Matlab.mtFeval(
at com.mathworks.jmi.MatlabWorker.feval(
at com.mathworks.appmanagement.InstallAppMatlabWorker.doOnMatlabThread(
at com.mathworks.appmanagement.InstallAppMatlabWorker.doOnMatlabThread(
at com.mathworks.appmanagement.AbstractAppManagementMatlabWorker.runOnMatlabThread(
at com.mathworks.jmi.MatlabWorker$
at com.mathworks.jmi.NativeMatlab.dispatchMTRequests(

Do you have any idea what is going on? Thanks!

17 Mar 2014 Brett Shoelson

Yes, I think the changing aspect ratio (horizontal/vertical nature) of your problem is significant. I have a demo in which I show that a face detector works until a face is rotated to about 20 degrees; then it fails. That indicates that one would need a vertical face detector and a tilted face detector to recognize both upright and tilted faces. I think the same is likely true in your case: you will need an upright-cone detector and a horizontal cone detector. Alternatively, you could do some image processing to find "blobs," and use REGIONPROPS/IMROTATE to reorient those blobs to always be "vertical" before running the detector. But yes, you'll likely have to do something different.

02 Mar 2014 Maddie

I am working with your GUI attempting to recognize regular orange traffic cones. I have yet to be able to get it to successfully recognize a cone though so I have a few questions I'm hoping you might be able to answer. First, the pictures I'm using to train the detector are being taken with a different camera (of much higher quality) than the camera I am using to attempt to detect the cones. Do know if camera/image quality could cause issues with detection? Second, some of my pictures are rotated in the GUI so the cone is displayed horizontally rather than vertically thus my ROI's are not of a consistent aspect ratio. Is this something I should take the time to fix? (as in do you believe this could be a large contributor to my issue?) Third, I currently have 200+ positives and 400+ negatives. What would you recommend as a good number of positives and negatives?

Thank you in advance for your help!

17 Feb 2014 Brett Shoelson

Training a cascade detector is memory intensive regardless of the environment you're working in. I strongly encourage you to find a way to do this on a 64-bit computer with a 64-bit OS and 64-bit MATLAB. Whether or not that is possible, it's also worth considering that Haar features take a lot of memory. So the other recommendation would be to try HoG or LBP. HoG takes the least memory of the three feature types.

16 Feb 2014 Brett Shoelson

It appears that your step PRIOR to using CTG to call the training function was improper. Take a look at the variable 'me' in your call, and take a look at the documentation for trainCascadeObjectDetector. You might also want to train a very small test detector using CTG, and study the nature of the (save-able, recall-able) file that it generates for input to the training function.
Cheers, Brett

15 Feb 2014 Jorge

That's was with my own code. After that I used the CascadeTrainGUI and I have these two files: Data_50.xml and Data_50.mat. I apply these simple code
detector = >>vision.CascadeObjectDetector('Data_50.xml');
>>img = imread('to.jpg');
>>bbox = step(detector, img); but at this point the program doesn't respond anymore

14 Feb 2014 Brett Shoelson

Did you get that error when you were trying to train using CascadeTrainGUI? Or did you write your own call to trainCascadeObjectDetector? The second input argument (in your call, me) must be an array of structs with your ROI-specified positive images. What is 'me' in your workflow? How did you generate it?

14 Feb 2014 Jorge

I have this problem:
>> jorge
Error using trainCascadeObjectDetector>parseInputs (line 305)
The value of 'POSITIVE_INSTANCES' is invalid. Expected input number 2, POSITIVE_INSTANCES, to be one of these types:

struct, char

Instead its type was uint8.

Error in trainCascadeObjectDetector (line 160)
parser = parseInputs(varargin{:});

Error in jorge (line 14)
trainCascadeObjectDetector('jorge_dectector.xml', me, negativeFolder, 'FalseAlarmRate', 0.2, 'NumCascadeStages', 5);

can someone help me?

13 Feb 2014 Hassan Javaid

I'm using r2013b on 32 bit windows 7 with 2GB ram and intel dual core processor.
I'm using 57 positive images and 50 negative images.
FAR is 0.50 and TPR is 0.995 and stages are 10.

12 Feb 2014 Brett Shoelson

Can you provide any more details? What is your computer architecture? How many positive images are you using? How many negative? How many stages, what FAR, what TPR,...?

12 Feb 2014 Brett Shoelson

The more difficult the detection—and the more similar positives are to negatives--the more training images (both positive and negative) you will need. To differentiate different types of cats, I would guess that you will need a lot of images. (Exactly how many is "a lot," I don't know. It will also depend on your target FAR and TPR.) I think it will make sense to use a bunch of lion and tiger images as negatives for training a leopard detector, and so on.

As for the live video can acquire video directly with our image acquisition tools, and apply the training ROI positioning frame by frame. There are some Computer Vision System Toolbox capabilities that could facilitate tracking to establish ROIs. I will have to leave incorporating them to you for the moment. But I did code for he ability to copy and paste ROIs. You could modify the code to programmatically copy/paste as you step through the frames.

12 Feb 2014 Hassan Javaid

I'm working on a hand detection project. I'm having problem using the Haar features, because whenever i use it it gives the error for insufficient memory. The error is as follows:

Error using ocvTrainCascade
Error in c:\temp\a3p1_2964_3232\win32\opencv\modules\core\src\alloc.cpp: Insufficient memory.

Error in trainCascadeObjectDetector (line 264)
ocvTrainCascade(filenameParams, trainerParams, cascadeParams, boostParams, ...

Error in CascadeTrainGUI/trainDetector (line 1965)
trainCascadeObjectDetector([CTS.SessionName '.xml'], ...

Error while evaluating uicontrol Callback

Please help me with this, thnx.

01 Feb 2014 Hetu Patel

hello sir ,
I have download R2013a. And also able to open this GUI app. Actually i am trying to make a detector to detect tigers and other animals from live input video stream.I am confuse actually because i tried so many times but can u give one example pls ??
And how can i join this with live video cam ?
kindly thank you.

30 Jan 2014 Brett Shoelson

Mostafa, if you don't know who your account manager is, please contact MathWorks at 508-4-647-7000. Tell them that you need to add a product to your license, and they can steer you in the right direction.

30 Jan 2014 Mostafa

Hello Mr. Shoelson,

I realized that my error appears because I do not have the Computer Vision System Toolbox installed on my Matlab version. I have the last version of Matlab (R2013b) but the trial one. Is there any way to install this missing toolbox?



27 Jan 2014 Brett Shoelson

Mostafa, This appears to be a path issue. If you excute >> which CascadeTrainGUI, what do you get? MATLAB has to have access to the app at runtime. Is the parent directory on MATLAB's path?


27 Jan 2014 Mostafa

I ran it from the Command Line.

25 Jan 2014 Brett Shoelson

Right, Mostafa. I know what a man-made object is. But I don't know what characteristic neccesarily differetntiates a "man-made object" from a natural one--in a computer vision senses. Or is it some aspect of color, or linearity that characterizes "man-made"? If you can't define that, I'm afraid you'll have little success creating a detector to find "man-made objects."

Regarding your second question: are you using CascadeTrainingGUI as an App, installed in--and run from--the App Toolbar? Or are you running from the Command Line? I'd like to understand better the nature of the error message you're getting. Sounds like a path issue to me, but I'm not sure (yet) why you're experiencing it.

24 Jan 2014 Mostafa

Hello Mr. Shoelson,

Thanks for your quick respond. What I meant by man made objects are the objects in natural scene like those images who were taken in the parks. Which have some objects like: a telecommunications cabinet, a bench, a chair, fence, etc. This is a one issue.

The other issue is how can I use the .mat file which is produced by training object tool (your tool)? I got this error when I trained the detector:

??? Undefined function or method 'trainCascadeObjectDetector' for input arguments of
type 'struct'.

Error in ==> CascadeTrainGUI>trainDetector at 1965
trainCascadeObjectDetector([CTS.SessionName '.xml'], ...

??? Error while evaluating uicontrol Callback

end of error.

Any suggestions!?

Thank you again for your patient!

24 Jan 2014 Brett Shoelson

Thanks for the rating. Unfortunately, I don't really have enough information from your description to steer you. What differentiates (in the image processing sense) a "man-made object" from a natural one? Sharp corners? Right angles? What kind of information do you have a priori about the objects that you're trying to detect?

24 Jan 2014 Mostafa

Hello Mr. Shoelson,

Thank you for sharing this great work! I'm working on detecting man made objects in the natural scene images such as (pavilion, pinch, cabinet, etc.) I should locate those objects and draw boxes around them. My question is: how to train the detector to make it ables to detect positive objects?

Also, as an expert in MATLAB, would you tell me if there is any other method can I use or modify to do this man made object detection?

Thank you in advance! I really appreciate any help from any expert person.

22 Jan 2014 Nelson Leon  
21 Jan 2014 diptimayee  
04 Dec 2013 Brett Shoelson

@zaafran: For face detection, you can use a pre-trained detector that ships with the vision.CascadeObjectDetector. (In fact, it's the default detector.) So no need to train your own. If that detector is inadequate for your needs, then there's no way around manual training, if you're working from a series of images. If there were, you wouldn't need to train anything. (And that's why I created this App; imagine how much _more_ tedious it would be without an app like this one!)

However, if you are working with a video stream, you may be able to implement some combination of detection and tracking to train the cascade detector. Read the doc for "Face Detection and Tracking Using the KLT Algorithm."

Good luck!

04 Dec 2013 zaafran

Hi Sir, I am working on face detection.. I have installed the app. Now i have to detect the trainer but it is very tedious to select the ROI for thousands of training images. can you plz tell me how to train the detector using coding... Thank you

03 Dec 2013 Niall  
28 Nov 2013 Mesis  
23 Nov 2013 Oscar  
05 Nov 2013 mustafa  
24 Oct 2013 Brett Shoelson

Hi Niall,
I added an "auto-ROI" button (with a CTRL-4 hotkey); please send me your address and I will send it to you directly. (You can CTRL-4 to add a full-frame ROI, then CTRL-N to go to the next image.) After you try it, if it meets your needs I will upload the new version to the File Exchange.

24 Oct 2013 Niall

Hi Brett,
Thanks for your reply.
Yes, in my case that would be extremely useful as I have a large database of images which are ROI's cropped out of larger images.(esp if you could select multiple images and apply that function simultaneously)
I used the term "crop' as, visually, the ROI selection is like a cropping act in photoshop, the question is basically though, is there a way to input a database/csv file which has ROI data for an array of images.
Many Thanks,

23 Oct 2013 Brett Shoelson

Hi Niall,
Yes, currently (at least), you have to manually specify each ROI. (Hence the need for this app! :) )

Based on your use case, I'm thinking of adding a single-button "Add full-frame-ROI" function. Do you think that would be useful?

Could you clarify your question about cropping ROIs for me? I'm not sure what you mean; there's no cropping whatsoever implemented in this app. (Though internal to the trainer, images are cropped to the bounding boxes of your ROIs. Is that what you mean?)


23 Oct 2013 Niall

Hi Brett,
I'm wondering about the ROI part, do I have to manually frame the ROI on each image I want to use in training?
I have hundreds of images that are actually entirely a ROI.
Also can ROI data be added any other way than using the "crop" function?
Thanks for the wonderful app, it will help me in my thesis.

22 Oct 2013 Brett Shoelson

Jonathan, that makes more sense. You shouldn't have to re-create your ROIs. However, I am unable to reproduce the error you're getting. I can load a session, add new images, specify new ROIs, and re-train. If you will send me your email address so I can reply directly, I will send you my current version of CascadeTrainGUI--so you can it and see if you're still getting an error.

22 Oct 2013 Jonathan

Hey Brett,

I understand that it would require retraining, but I would rather not have to go through a couple hundred images creating ROI's again when I am only trying to add a few more. The steps I take are:

1. Launch the CascadeTrainGUI
2. File->Load Session...
3. I select my previous session file and it loads the list of images and corresponding ROI's
4. Click "Add Images" button
5. Select Picture(s) that I want added to the existing list
6. Click the "Open" button on the dialog box
7. Receive Error

21 Oct 2013 Brett Shoelson

Hi Jonathan,
Thanks for the rating. I'm trying to understand and recreate what you're seeing, but I am unable to do so. Currently, there is no way to recommence training. Once a detector has been trained, there is no way to tweak it. If you add new images to improve detections, you have to retrain the detector from the beginning.
If you can give me reproduction steps, I'd like to try to figure this out.

21 Oct 2013 Jonathan

Hi Brett, thanks for creating this, I think its going to work for what I am trying to accomplish. I am getting an error though, I have a detector trained, but to make it more robust I am trying to add more positive images. When I go to the "Select Images/ROIs" tab and try to add a new image I am getting this error message in my command window:

Warning: The 'rows' input is not supported for cell array inputs.
> In cell.intersect>cellintersectR2012a at 246
In cell.intersect at 137
In CascadeTrainGUI>promptForImages at 1080
Error using char
Inputs must be character arrays.

Error in CascadeTrainGUI/promptForImages (line 1094)
tmpImageList = char(currList,newList);

Error while evaluating uicontrol Callback

This happens after I click "add Images", select an image file in the open file dialog box, and click the "open" button. Any suggestions?

21 Oct 2013 Brett Shoelson

Thanks for the rating, Valerio. You might try re-training with a lower per-stage false alarm rate, or a higher per-stage true positive rate (second tab). Otherwise, it's really hard to tell why your results aren't as good as you'd like them to be.

Generally, it's probably a good idea to have all ROIs within the training set have a fairly consistent aspect ratio. (So if you have some images of traffic lights that appear skewed, for instance, because they were captured from the side, it might be better to include those in a separate training session.

Also, 300 positive photos may not be too few to yield a really robust detector.


07 Oct 2013 valerio

hi brett your work is great, it semplifies the part of my work.
but i've a problem with detector.
I'm designig, for a university exam, traffic light detector, so i've took 200 traffic control photo, and about 300 photo of non traffic light(street with car, country roads etc etc...) so i use your app following the next 3 step 1)select the positive image, 2)negative image and 3)run training... to check the detector, i chooose an image test and run detector, but now i've some problem.... are detected many other areas that do not coincide with the traffic light.

i'm woorking with 16megapixel image... what is the problem in detector?

PS:sorry for my english

22 Aug 2013 Usman

Hi Brett,
Thank you for your response.
It turns out that I didn't place a bounding box around one of my positives. I think that threw the entire program off. It's working beautifully now, though.

To answer your questions:
1) These errors usually pop up right when training is supposed to commence.
2)The training information saves each time

Cheers; the GUI is fantastic,


15 Aug 2013 Brett Shoelson

Usman, thanks for sharing this. Can you provide additional information? At what point does this happen? When you first press the "Train" button? Or some time after training has begun? Do you have reproduction steps? Can you reproduce it with a small subset of your images?

BTW, you should have the training information saved, and you should be able to reload the session, right?


15 Aug 2013 Usman

Hello, I'm trying to run an HOG trainer using ~1500 positives and ~5000 negatives with the standard parameters. The following errors pop up:

Error using trainCascadeObjectDetector > getTotalNumInstances

Error in trainCascadeObjectDetector>populateTrainCascadeParams

Error while evaluating uicontrol Callback

The trainer is unable to progress once these errors pop up. I would thoroughly appreciate it if someone could assist me in solving these errors and training my cascade classifier.


30 Jul 2013 Ali M

Thank you.

29 Jul 2013 Brett Shoelson

Ali, there are actually 3 features with which you can train the detector: HOG, HAAR, or LBP. I don't have enough experience creating detectors to tell you which will work best, and under what conditions. We chose HOG as the default, thinking that it would be a general-purpose feature, but I would recommend reading the references in the doc for trainCascadeObjectDetector for more insight.

"False positive rate" is an indication of the likelihood of falsely detecting an object; "false negative rate" indicates the likelihood of missing an object that really does exist.

In the training session, the OVERALL target true positive rate of the resulting detector is TPR^NumCascadeStages, where TPR is the per-stage true positive rate. Increasing this value may increase the number of correct detections, at the cost of increased training time. (Default: 0.995).


The overall target false alarm rate of the resulting detector is FAR^NumCascadeStages, where FAR is the per-stage False Alarm Rate. Lower value
of FalseAlarmRate may result in fewer false detections, but in longer training and detection times. (Default: 0.5).

Once you've selected a detector--one you created, or one we supplied--you can tally the number of positives by querying the number of bounding boxes returned:

detector = vision.CascadeObjectDetector(detectorRequested);
bbox = step(detector, img); %detect object
nDetected = size(bbox,1);

This is done for you within CascadeTrainGUI!


25 Jun 2013 Ali M

@Brett Shoelson
Sir, the detection is good now, but incrementing the false positive and decrementing the false negative, i have 3 question for you:
1) in each stage how many haar feature we use, and which best generally haar or hog?
2) what is really the false positive value and the false negative (i don't have a big experience in object detection and i am still learning)?
3) how i make a count function that return to me the number of object detected?
Thank You.

24 Jun 2013 Brett Shoelson

I'm sorry, Ali. I don't really know what your question is. Are you concerned because your results aren't as good as you'd like unless your images are similar in size to the negative images you used? (One thing that occurs to me immediately is that 60 positive images might be too few to expect or get really good results.)

21 Jun 2013 Ali M  
21 Jun 2013 Ali M

Hi all, i made a train of 60 positives images for pedestrian detection and 1000 negatives samples, the positive ones have variables width and height but the negatives have 64x128, and when i test an image, a good result is when i resize the tested image into 64x128
Number of stage: 5.
Negative sample factor: 2.
Per stage true positive value: 0.995.
Any help ?
Thank you

19 Apr 2013 Brett Shoelson

Rana, can you tell me a bit about what you tried? Were you able to establish ROIs in all of the 15 face images? Did you get any helpful messages inside of CascadeTrainGUI when you pressed the 'Train Detector!' button? (BTW, that's an exceptionally small number of images--I wouldn't be too optimistic about the quality of the detector.)

18 Apr 2013 rana

while executing the gui and after loading 15 face images and 20 nonface images to train the system i obtained this error : 'Error using ocvTrainCascade
Error in generating samples for training. No samples could be generated for training
the first cascade stage.'

13 Mar 2013 Nicola Franzoso

Brett, all is fine and works !!
I'm a little bit tired but after a strong coffee all working fine.

13 Mar 2013 Brett Shoelson

Thanks, Nicola. I had hoped that using this would be pretty self-explanatory. Can you tell me a bit about what you're having trouble with? (If it's actually training a detector [second tab], note that you'll need to download and install R2013a, and have a license for Computer Vision System Toolbox, to do so.)

13 Mar 2013 Nicola Franzoso

Brett, this is good, but can you explain me how i have to use this tools from train cascade object ?
Very nice the pictures of baby

10 Mar 2013 Brett Shoelson

I appreciate your comment, Harsh. (Especially the "superb work" part :) ). I call your attention to my note below; MATLAB R13a is live, and ready for download. I waited until that was true before posting this file.

And if your "how?" refers to "how did I get access to R13a" before it was officially released--I should point out that I work for MathWorks!

Download R13a and start training!

10 Mar 2013 Harsh Singh

getting errors while trying to train in can i modify code to get it running.....btw superb work.....but it was unfair to make it for R13a one month advance(how?)......disapointing!

08 Mar 2013 Brett Shoelson

PLEASE NOTE: Training a cascade detector in MATLAB requires R2013a (which is live today, and ready for download!). You can use this GUI in previous versions to specify ground truth and to apply pre-trained detectors...but you'll need R13a to train new ones!

08 Mar 2013


08 Mar 2013

Includes interface to train the detector, and to apply a trained detector to a set of images!

08 Mar 2013

Includes interface to train a detector, and to apply a trained detector to a series of images!

06 Nov 2014

Added new PasteROIsThrough... function, fixed some bugs, and verified R14b readiness.
PLEASE NOTE: This app is a replacement for the previously-named CascadeTrainGUI.

Contact us