what is wrong with this code??
2 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Florian Morsch
on 25 Jun 2018
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 Comments
Florian Morsch
on 27 Jun 2018
Did you find your error?
If so and if my answer helped would you mind marking it as correct answer?
See Also
Categories
Find more on Point Cloud Processing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!