MATLAB Answers

0

distance between object moving

Mehul Sompura さんによって質問されました 2019 年 10 月 9 日
最新アクティビティ Prabhan Purwar さんによって 回答されました 2019 年 10 月 17 日
How do i find the distance between these two cars??
inout both image, see for the cahnge and then find the distance.
a= imread( 'car1.png')
b = imread('car2.png')
c = corr2(a,b); %finding the correlation btwn two images
if c==1
disp('The images are same')%output display
else
disp('the images are not same')
end;
k=2; for i=1:1:length(g)-1 x(i) = g(i).Centroid(1); y(i) = g(i).Centroid(2);
x(k)=g(k).Centroid(1); y(k)=g(k).Centroid(2);
distance=sqrt((x(i)-x(k))^2+(y(i)-y(k))^2);

  0 件のコメント

サインイン to comment.

1 件の回答

回答者: Prabhan Purwar 2019 年 10 月 17 日

The following code illustrates the working of regionprops()function to determine the boundary along with the connected components.
Assumption: It is assumed that the camera is fixed at a point and captures images.
clc
close all
clear
a= imread( 'car1.png'); %Read images
b = imread('car2.png');
a=rgb2gray(a);
b=rgb2gray(b);
d=a-b; %Background Substraction
BW=d;
BW=medfilt2(BW); %Median Filter
BW=edge(BW,'Canny',0.2); %Edge detection
se = strel('line',11,90); %Dilate Image
BW = imdilate(BW,se);
imshow(BW)
labeledImage = bwlabel(BW); %Labeling and Bounding Box around car
measurements = regionprops(labeledImage, 'BoundingBox', 'Area');
for k = 1 : length(measurements)
thisBB = measurements(k).BoundingBox;
rectangle('Position', [thisBB(1),thisBB(2),thisBB(3),thisBB(4)],...
'EdgeColor','r','LineWidth',2 )
end
b1=measurements(1).BoundingBox; %Measuring distance
b2=measurements(2).BoundingBox;
x1=b1(1,1)+b1(1,3)/2;
x2=b2(1,1)+b2(1,3)/2;
y1=b1(1,2)+b1(1,4)/2;
y2=b2(1,2)+b2(1,4)/2;
hold on
scatter(x1,y1);
scatter(x2,y2);
line([x1 x2], [y1 y2]);
distance=sqrt((x2-x1)^2 + (y2-y1)^2); %Distance
Output:
cardis1.jpg
cardis.jpg
Refer to the following link for further information:

  0 件のコメント

サインイン to comment.



Translated by