Undefined function or variable
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
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
2018년 1월 22일
1 개 추천
You did not call estimateCameraParameters to generate the stereo parameters.
댓글 수: 10
i added a loop i forgot
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]);
for x = 1:100
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);
end
imshowpair(I1, I2, 'montage');
the error changed
Index exceeds matrix dimensions.
center1 = face1(1:2) + face1(3:4)/2;
ahmed nasr
2018년 1월 22일
i loaded the calibration file isn't that the camera parameters ??
We have no idea what is stored in your callast.mat file.
Even if there is a variable named stereoParams in there, if this code is inside a function, the Just In Time compiler would not believe it exists. You should not "poof" variables into exists by using load() without an output: you should assign the results of load() to a variable and either access the resulting struct directly or pull out parts of it, like
filedata = load('callast.mat');
stereoParams = filedata.stereoParams;
Note by the way that your line
double faceDetector();
means exactly the same thing as
double('faceDetector()');
which computes [102 97 99 101 68 101 116 101 99 116 111 114 40 41] and then throws it away. MATLAB does not have type declarations.
Index exceeds matrix dimensions.
center1 = face1(1:2) + face1(3:4)/2;
Your code assumes that the face detector found exactly one face. You should not assume that. You should be testing the size of the output to determine whether it found anything, and you should assume it might have found multiple faces (in which case the information for any one face is a row in the results, whereas you assume you can use linear indexing, which will fail if multiple faces were returned.
ahmed nasr
2018년 1월 22일
thank you you have been so helpful... but still i can't understand
Delete the line
double faceDetector();
Change
load('callast.mat')
to
filedata = load('callast.mat');
stereoParams = filedata.stereoParams;
Change
center1 = face1(1:2) + face1(3:4)/2;
center2 = face2(1:2) + face2(3:4)/2;
followed by the rest of your code
to
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;
followed by the rest of your code and then
end
so that the rest of your code is not executed if no face was detected.
i did what u told me but the filedata part gave me an error but everything else ran smoothly with no errors but no output .
load('callast.mat');
vid = videoinput('macvideo', 1, 'YCbCr422_1280x960');%left
vid2 = videoinput('macvideo', 2, '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);
faceDetector = vision.CascadeObjectDetector;
face1 = faceDetector(I1);
face2 = faceDetector(I2);
if ~isempty(face1) & ~isempty(face2)
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');
end
ahmed nasr
2018년 1월 23일
but thats a nice breakthrough, thank you Walter. i don't know how i forgot this loop
Walter Roberson
2018년 1월 23일
I do not see any loop in your code.
ahmed nasr
2018년 1월 23일
The condition am sorry, ishould add a loop to take screenshots and analyze, right ?
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개)
카테고리
도움말 센터 및 File Exchange에서 Device Connection에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
