There are a few of things you can try:
Definitely move
FaceDetect = vision.CascadeObjectDetector;
outside of the loop. You only need to create the face detector object once. Re-creating it for every frame is definitely your performance bottleneck.vision.VideoFileReader
returns a frame of class'single'
by default. If you change the output data type to'uint8'
, that should speed up the face detector. Useobj=vision.VideoFileReader('basu.avi', 'VideoOutputDataType', 'uint8');
vision.VideoFileReader
can also do the conversion to grayscale for you. Useobj=vision.VideoFileReader('basu.avi', 'VideoOutputDataType', 'uint8', 'ImageColorSpace', 'Intensity');
This may be faster than callingrgb2gray
.Try limiting the size of the faces being detected using
'MinSize'
and'MaxSize'
options ofvision.CascadeObjectDetector
and/or try downsampling the frame before detecting faces.