Index exceeds matrix dimensions

clear all;
C = webcamlist;
if length(C)>2
fprintf('All three WebCam is Working' );
else
fprintf('Not All three WebCam is Working' );
end
load('webcamsSceneReconstruction.mat');
vid1 = videoinput('macvideo', 1);
vid2 = videoinput('macvideo', 2);
start([vid1 vid2]);
img1 = getsnapshot(vid1);
img2 = getsnapshot(vid2);
imwrite(img1,'sceneReconstructionLeft.jpg');
imwrite(img2,'sceneReconstructionRight.jpg');
I1 = imread('sceneReconstructionLeft.jpg');
I2 = imread('sceneReconstructionRight.jpg');
I1 = undistortImage(I1,stereoParams.CameraParameters1);
I2 = undistortImage(I2,stereoParams.CameraParameters2);
faceDetector = vision.CascadeObjectDetector;
face1 = step(faceDetector,I1);
face2 = step(faceDetector,I2);
center1 = face1(1:2) + face1(3:4)/2;
center2 = face2(1:2) + face2(3:4)/2;
point3d = triangulate(center1, center2, stereoParams);
distanceInMeters = norm(point3d)/1000;
distanceAsString = sprintf('%0.2f', distanceInMeters);
I1 = insertObjectAnnotation(I1,'rectangle',face1,distanceAsString,'FontSize',18);
I2 = insertObjectAnnotation(I2,'rectangle',face2, distanceAsString,'FontSize',18);
I1 = insertShape(I1,'FilledRectangle',face1);
I2 = insertShape(I2,'FilledRectangle',face2);
%imshowpair(I1, I2, 'montage');
Why [am] i getting this error in both center1 and center2 and any way to prevent this error i have to represent this to my external

Answers (1)

Azzi Abdelmalek
Azzi Abdelmalek on 6 May 2016
Check the sizes of the variables face1 and face2

13 Comments

both 0x4 double
What I expected. So, the object detector logic returned nothing recognizable. Your mission, should you choose to accept, is to investigate "why"....we've no way to know from the info posted.
No face detected so I guess there is either no one in the picture, or, my guess, he's wearing his ninja outfit.
Any way to prevent this again and Again getting this mostly face recognition code like this
center1 = face1(1:2) + face1(3:4)/2;
center2 = face2(1:2) + face2(3:4)/2;
if the person wearing specs then this object detector will work and the person is sitting in front of webcam i mean face is towards camera, not tilted then why it is showing error
Index exceeds matrix dimensions.
Error in Depth (line 22) center1 = face1(1:2) + face1(3:4)/2;
Error in EyeClassifier (line 4) Depth;
>> who face1
Your variables are:
face1
whos face1 Name Size Bytes Class Attributes
face1 0x4 0 double
I think, I'm accessing face(1:2) 1st row and 2nd column but face1 doesn't have 1st row after checking the size because
faceDetector = vision.CascadeObjectDetector;
face1 = step(faceDetector,I1);
face2 = step(faceDetector,I2);
step(faceDetector,I1) not detected face
Any solution this error, how to prevent this error
hello i have the same error for months nw .. what did you come up with ??
@ahmed nars: The question is almost 2 years old. Prefer to open you own thread and post the details. What is "months nw"?
@Jan Simon: A few months from our present time. Ahmed Nasr* @Torsten: nOOOOOOw
Yes, I know. Why do you shout ?
Jan
Jan on 23 Jan 2018
Edited: Jan on 23 Jan 2018
@ahmed nasr: I thought "months nw" is the failing variable... You are working on some code for months now and it has still errors? As said already: Please open a new thread and post the relevant part of the code and some example inputs (e.g. created by rand).
Cascade object detection relies on patterns that are not certain to be present even if there is s face in the input images, and there is no certainty that the input has a face at all. The code is wrong for not testing to be sure that a face was detected. The code is also wrong for the case where more than one face is detected.

This question is closed.

Asked:

on 6 May 2016

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!