what is wrong with this code??
조회 수: 2 (최근 30일)
이전 댓글 표시
this is my code....I'm trying to detect the person and than measure the distance from my stereoCamera...
leftcam= imaq.VideoDevice('winvideo', 2 ,'YUY2_640x480');
rightcam= imaq.VideoDevice('winvideo', 3, 'YUY2_640x480' );
if ~exist('stereoParams','var')
load ('calibrationSession.mat');
end
ax = axes;
maxDepth = 5;
while true
I1 = step(leftcam);
I2 = step(rightcam);
[J1,J2] = rectifyStereoImages(I1, I2, stereoParams);
%figure;
%imshow(stereoAnaglyph(J1, J2));
%title('Rectified Video Frames');
frameLeftGray = rgb2gray(J1);
frameRightGray = rgb2gray(J2);
%disparity map
disp = disparity(frameLeftGray, frameRightGray, 'DisparityRange', [0 ,64] );
%reconstruct 3d scene
pointCloud = reconstructScene(disp, stereoParams) ./1000;
z = pointCloud(:, :, 3);
z(z<0) = NaN;
z(z>maxDepth) = NaN;
pointCloud(:,:,3) = z;
if ~ishandle(ax)
break;
else
pcshow(pointCloud, J1, 'VerticalAxis', 'Y', 'VerticalAxisDir','Down','parent',ax);
%setting for visualization below..
xlabel('X (m)');
ylabel('Y (m)');
zlabel('Z (m)');
xlim(ax, [-.8, .8]);
ylim(ax, [-.8, .8]);
zlim(ax, [0, maxDepth]);
daspect(ax, 'manual');
pbaspect(ax, 'manual')
drawnow;
% view(pcshow,pointCloud);
end
%People Detetion
peopledetector= vision.PeopleDetector('MinSize',[166,83]);
bboxes= peopledetector.step(frameLeftGray);
centroids = [round(bboxes(:,1) + bboxes(:, 3) /2), round(bboxes(:, 2) + bboxes(:, 4)/2)];
centroidsIdx = sub2ind(size(disp), centroids(:, 2), centroids(:, 1));
X = pointCloud(:, :, 1);
Y = pointCloud(:, :, 2);
Z = pointCloud(:, :, 3);
centroids3D = [X(centroidsIdx), Y(centroidsIdx), Z(centroidsIdx)];
dists = sqrt(sum(centroids3D .^2, 2));
labels = cell(1, numel(dists));
for i= 1:numel(dists)
labels{i} = sprintf('%0.2f meters',dists(i));
end
% dispFrame = insertObjectAnnotation(J1, 'rectangle', bboxes, labels);
%dispFrame = J1;
figure
imshow(insertObjectAnnotation(J1, 'rectangle', bboxes, labels));
end
release(leftcam);
release(rightcam);
this is the error i got....
Error using insertObjectAnnotation
Expected LABEL to be nonempty.
Error in insertObjectAnnotation
Error in insertObjectAnnotation
Error in insertObjectAnnotation
Error in Untitled4 (line 81)
imshow(insertObjectAnnotation(J1, 'rectangle', bboxes, labels));
.... i'm new to matlab and i have very short time . this is my fyp work.. please help me to solve this problem as soon as possible
댓글 수: 0
답변 (1개)
Florian Morsch
2018년 6월 25일
imshow(insertObjectAnnotation(J1, 'rectangle', bboxes, labels));
You use "labels"-variable and the compiler tells you, that this variable is empty. Its expected to be nonempty, meaning you should check your code (break points help) why there is no value in the variable.
My guess is: You dont detect anything with the PeopleDetector, and so your variable is empty.
댓글 수: 4
Florian Morsch
2018년 6월 27일
Did you find your error?
If so and if my answer helped would you mind marking it as correct answer?
참고 항목
카테고리
Help Center 및 File Exchange에서 Point Cloud Processing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!