Undefined function or variable

2 ビュー (過去 30 日間)
ahmed nasr
ahmed nasr 2018 年 1 月 22 日
コメント済み: Walter Roberson 2018 年 1 月 23 日
that is the whole code which should get face detection with distance
load('callast.mat');
double faceDetector();
vid = videoinput('macvideo', 1, 'YCbCr422_1280x960');%left
vid2 = videoinput('macvideo', 3, 'YCbCr422_1280x960');%right
triggerconfig([vid vid2],'manual');
vid2.FramesPerTrigger = 10;
vid.FramesPerTrigger = 10;
start([vid vid2]);
pause(1)
trigger([vid vid2]);
I1 = getsnapshot(vid);
I2 = getsnapshot(vid2);
% I1 = undistortImage(T1,stereoParams.CameraParameters1);
%I2 = undistortImage(T2,stereoParams.CameraParameters2);
faceDetector = vision.CascadeObjectDetector;
face1 = faceDetector(I1);
face2 = 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 meters', 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');
the error
Undefined function or variable 'stereoParams'.
point3d = triangulate(center1, center2, stereoParams);

採用された回答

Walter Roberson
Walter Roberson 2018 年 1 月 22 日
You did not call estimateCameraParameters to generate the stereo parameters.
  10 件のコメント
ahmed nasr
ahmed nasr 2018 年 1 月 23 日
The condition am sorry, ishould add a loop to take screenshots and analyze, right ?
Walter Roberson
Walter Roberson 2018 年 1 月 23 日
You have two choices:
First possibility:
maxframe = 10;
vid = videoinput('macvideo', 1, 'YCbCr422_1280x960');%left
vid2 = videoinput('macvideo', 3, 'YCbCr422_1280x960');%right
faceDetector = vision.CascadeObjectDetector;
for frame = 1 : maxframe
I1 = getsnapshot(vid);
I2 = getsnapshot(vid2);
face1 = faceDetector(I1);
face2 = faceDetector(I2);
if ~isempty(face1) & ~isempty(face2)
center1 = face1(1, 1:2) + face1(1, 3:4)/2;
center2 = face2(1, 1:2) + face2(1, 3:4)/2;
point3d = triangulate(center1, center2, stereoParams);
distanceInMeters = norm(point3d)/1000;
distanceAsString = sprintf('%0.2f meters', 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');
drawnow();
end
end
Second possibility:
maxframe = 10;
vid = videoinput('macvideo', 1, 'YCbCr422_1280x960');%left
vid2 = videoinput('macvideo', 3, 'YCbCr422_1280x960');%right
faceDetector = vision.CascadeObjectDetector;
vid2.FramesPerTrigger = maxframe;
vid.FramesPerTrigger = maxframe;
start([vid vid2]);
pause(1)
trigger([vid vid2]);
frames1 = getdata(vid);
frames2 = getdata(vid);
for frame = 1 : size(frames1, 4)
I1 = frames1(:,:,:,frame);
I2 = frames1(:,:,:,frame);
face1 = faceDetector(I1);
face2 = faceDetector(I2);
if ~isempty(face1) & ~isempty(face2)
center1 = face1(1, 1:2) + face1(1, 3:4)/2;
center2 = face2(1, 1:2) + face2(1, 3:4)/2;
point3d = triangulate(center1, center2, stereoParams);
distanceInMeters = norm(point3d)/1000;
distanceAsString = sprintf('%0.2f meters', 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');
drawnow();
end
end

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by