# distance between object moving

6 ビュー (過去 30 日間)
Mehul Sompura 2019 年 10 月 9 日

How do i find the distance between these two cars??
inout both image, see for the cahnge and then find the distance.
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=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:  Refer to the following link for further information:

#### 0 件のコメント

サインイン to comment.

サインイン してこの質問に回答します。