Distance to an object

Hi. I have a kinect v1 camera. Will like ti know the steps to take to calculate the distance to an object. Also, I acquire a tyre wheel picture using the rgb camera. I used the imfindcircle to locate the centre of the wheel as well as the radius and I got some values (which I guess they are pixels). How do I convert this to metres or mm as the case maybe? Attached is the located circle. The centre and radius as returned on the command line is
center =
379.4851 377.5351
radius =
50.9897
phase_coding_method.jpg

4 comentarios

Julie
Julie el 4 de Jul. de 2019
What distance do you want? To an edge? To another object that you have already located?
To convert to m/mm you need to have a known distance in the image. Then you can come up with a conversion factor between pixels and real measuments.
Gideon Oladipupo
Gideon Oladipupo el 4 de Jul. de 2019
Many thanks for prompt reply. The distance I desire to get is from the kinect to the wheel hub (deteted red circle in the previous image). How do I extract the distance in the image? From the imfindcircle, I was able to get the circle centre and its radius as stated in the previous post. Lastly, do I need to calibrate the kinect camera? If yes, how do I go about it? Not sure the normal checker board will be ideal for its calibration.
Regards
Julie
Julie el 4 de Jul. de 2019
So, getting the distance to an object not shown in the image is very diffrent than getting the distance between 2 objects in an image. I have no idea how to do it, other than maybe taking pictures of the wheel at various known distances and using the sizes of the central hub to estimate distance. There is probably a better way, but it is not something I have worked with.
Gideon Oladipupo
Gideon Oladipupo el 4 de Jul. de 2019
Ok, many thanks for your time. Can you suggest a better ways to get this done? I will appreciate if you could suggest any link that would be helpful to me. Do I need to calibrate the kinect camera or I can go ahead to use it directly?

Iniciar sesión para comentar.

Respuestas (2)

Image Analyst
Image Analyst el 4 de Jul. de 2019

0 votos

I assume you have a distance image from the Kinect camera as well as the optical RGB image. So just use the centroid you got from the optical image to read the value from the distance image.
column = centers(1); % x
row = centers(2); % y
distanceToCenter = distanceImage(row, column) % Read distance from distance image (not optical RGB image)

6 comentarios

Gideon Oladipupo
Gideon Oladipupo el 4 de Jul. de 2019
Many thanks. What would this measurement give me? I guess in pixel. How do I get the real world measurement?
Image Analyst
Image Analyst el 4 de Jul. de 2019
I don't have a kinect so I don't know what units the pixels are in. For optical images, the units are pixels and gray levels, but for the distance image, I don't know what the values represent. I don't think they're intensity (gray levels) - the values will mean some real world distance, like in cm or meters or inches or whatever. Consult your Kinect manual for the answer. But you may just want to calibrate yourself by putting objects (like a book) at different, known distances and see what it (the distance image) reports the value as.
Can you attach both your optical image, and the distance image along with the MATLAB code to read the distance image (which I guess is some special format)?
Gideon Oladipupo
Gideon Oladipupo el 4 de Jul. de 2019
Ok, will send this later on. Many thanks for your time out. Regards
Gideon Oladipupo
Gideon Oladipupo el 5 de Jul. de 2019
rgb_wheel_1.jpg
% Scripts to detect circular objects in an image, tyre_web instance
wheel = imread('wheel_1.jpg'); % Load Image
figure
imshow(wheel)
%d = imdistline;
%delete(d)
%d = imdistline; %Determine Radius Range for Searching Circles
%delete(d)
gray_tyre = rgb2gray(wheel); % Initial Attempt to Find Circles
figure
imshow(gray_tyre)
%d = imdistline;
%BW3 = edge(gray_tyre,'Canny');
%figure
%imshow(BW3)
%BW4 = edge(gray_tyre,'approxcanny');
%figure
%imshow(BW4)
%d = imdistline;
%delete(d)
%[center,radius] = imfindcircles(tyre_model,[203 208],'ObjectPolarity','dark') % At the default sensitivity level , which is 0.85, the tyre could not be detected because imfindcircle has lower internal threshold.
%[center,radius] = imfindcircles(tyre_model,[203 208],'ObjectPolarity','dark', ...
% 'Sensitivity',1.0) % Increase Detection Sensitivity to 1.0
%figure
%imshow(tyre_model)
%h = viscircles(center,radius);
%[center,radius] = imfindcircles(BW4,[100 103],'ObjectPolarity','dark', ...
% 'Sensitivity',0.98)
%length(centers)
%delete(h) % Delete previously drawn circles
%h = viscircles(centers,radii);
% Repeat for the wheel diameter
%[center,radius] = imfindcircles(BW4,[50 51],'ObjectPolarity','dark', ...
% 'Sensitivity',0.98) % Increase Detection Sensitivity to 1.0
%figure
%imshow(BW4)
%h = viscircles(center,radius);
% Repeat for the hub hole radius - phase coding method
[center,radius] = imfindcircles(wheel,[48 53],'ObjectPolarity','dark', ...
'Sensitivity',0.984) % Increase Detection Sensitivity to 0.984
figure
imshow(wheel)
h_1 = viscircles(center,radius); % visualise the detected circle
a = imread ('phase_coding_method.jpg');
b = imread ('phase_coding_false_circle.jpg');
figure
imshowpair(a,b,'montage')
title('Correct Circle Detection False circle detection')
% Repeat for the hub hole radius - phase coding method
%[center,radius] = imfindcircles(BW3,[5 9],'ObjectPolarity','dark', ...
% 'Sensitivity',0.9) % Circle Detection guaranteed between 0.90 to 0.917
%figure
%imshow(BW3)
%h_2 = viscircles(center,radius);
% Load saved figures
%c=imread('false_cirlce_detection.jpg');
%k=imread('correct_circle_detection.jpg');
% Prepare subplots
%figure
%imshowpair(c,k, 'montage')
%title('False cirle detection Correct Circle detection')
%figure
%imshowpair(BW3,BW4, 'montage')
%title('False cirle detection Correct Circle detection')
%imshow(gray_tyre)
%Repeat for the hub hole radius - two stage method
[centers,radii] = imfindcircles(wheel,[48 53],'ObjectPolarity','dark', ...
'Sensitivity',0.971,'Method','twostage');
%delete(h)
figure
imshow(wheel)
h = viscircles(centers,radii);
c = imread ('two_stage_method.jpg');
d = imread ('two_stage_false_circle.jpg');
figure
imshowpair(c, d, 'montage')
title('Correct Circle Detection False circle detection')
% There is no good contrast between the tyre sample and the background
% gray_tyre, hence approach to find bright tyre is adpoted thus;
%[centersBright,radiiBright] = imfindcircles(tyre_model,[30 35], ...
% 'ObjectPolarity','bright','Sensitivity',1.0);
%figure
%imshow(tyre_model)
%hBright = viscircles(centersBright, radiiBright,'Color','b');
Gideon Oladipupo
Gideon Oladipupo el 5 de Jul. de 2019
Sent above is the optical image which was was saved as image tool and the matlab functions which I tweaked around. Am still learning on the job. Not sure if the code I sent is what you desire. Essentially, I used imfindcircle function to detect the red cycle in the first image. RGB camera parameter is 'BGR_1920x1080'. Hope the information I provided will be okay to help me further. Regards.
Image Analyst
Image Analyst el 5 de Jul. de 2019
Kinect gives you two images. You forgot to attach the distance image - the other image (NOT the optical RGB image) where the values are the distance from the Kinect camera to objects in the scene. Please attach it. But anyway, my original answer gave you the code for getting the distance.

Iniciar sesión para comentar.

Gideon Oladipupo
Gideon Oladipupo el 5 de Jul. de 2019

0 votos

So sorry for the omission, attached is the depth image in png format. The depth camera parameter is 'Depth_512x424'.depth_image.png

1 comentario

Gideon Oladipupo
Gideon Oladipupo el 5 de Jul. de 2019
I was able to get the point cloud of the wheel using the depth camera. Will like to confirm steps to take in getting the real distance of the wheel from the camera. Any link to understand how it works would be appreciated. Attached is my point cloud extractedpc_depth_light.jpg

Iniciar sesión para comentar.

Etiquetas

Preguntada:

el 4 de Jul. de 2019

Comentada:

el 5 de Jul. de 2019

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by