the matlab code is used to detect red colored object, but i want to control a bot to move towards the detected object. just need a simple algorithm or idea, controlling the servo i will be able to do it.

Detailed Diagram

%get snapshot
data = imread('image.jpg');
% Now to track red objects in real time
% we have to subtract the red component 
% from the grayscale image to extract the red components in the image.
diff_im = imsubtract(data(:,:,1), rgb2gray(data));
%Use a median filter to filter out noise
diff_im = medfilt2(diff_im, [3 3]);
% Convert the resulting grayscale image into a binary image.
diff_im = im2bw(diff_im,0.18);

% Remove all those pixels less than 300px
diff_im = bwareaopen(diff_im,300);

% Label all the connected components in the image.
bw = bwlabel(diff_im, 8);

% Here we do the image blob analysis.
% We get a set of properties for each labeled region.
stats = regionprops(bw, 'BoundingBox', 'Centroid');

% Display the image

hold on

%This is a loop to bound the red objects in a rectangular box.
for object = 1:length(stats)
    bb = stats(object).BoundingBox;
    bc = stats(object).Centroid;
    plot(bc(1),bc(2), '-m+')
    a=text(bc(1)+15,bc(2), strcat('X: ', num2str(round(bc(1))), '    Y: ', num2str(round(bc(2)))));
    set(a, 'FontName', 'Arial', 'FontWeight', 'bold', 'FontSize', 12, 'Color', 'yellow');

hold off
  • $\begingroup$ would you please be more specific about the problem? Is it a computer vision problem or a mere geometric one? $\endgroup$ – CroCo Aug 5 '14 at 17:11
  • $\begingroup$ computer vision problem, i mean so far i am able to detect the objects and find the distances between the robot and the objects but i'm unable to move the robot to the target object(red block) as shown in the diagram. $\endgroup$ – Nabajyoti Das Aug 5 '14 at 17:27
  • $\begingroup$ actually i want to design an autonomous bot that uses image processing to locate the block of different colours and to put the block in respective color zone. I will be placing the camera above the center of the arena, such that the camera gets the top view of the arena, and then detects the different colored blocks and the bot. $\endgroup$ – Nabajyoti Das Aug 5 '14 at 17:45

Image X and Y will reflect x and Y coordinates on the floor. Lens has distortion. Use calibration (if opencv), if high accuracy needed (may not need in this case).

Original answer was mis-understood:

Height and Width is distance (far, smaller image) then PID to control speed, slow down when near

Left, Central, Right of the block is angle of block as reference to vehicle coordinate frame and calculate the motion angle

  • $\begingroup$ sorry i didn't get you, actually i want to move the robot to the detected object without using any sensor. Like giving a specific color to the robot and then moving the bot until robot color centroid and object color centroid comes together. $\endgroup$ – Nabajyoti Das Aug 2 '14 at 19:51
  • $\begingroup$ Sorry I mis-understood that camera is on robot (looking eye). see youtube.com/watch?v=bSeFrPrqZ2A Use distinct color for block and robot so that they can be 'far different' under HSV color space. Read image, convert to HSV space. Locate two color blocks. Calculate centroid of two color bloc as x0,y0 and x1,y1. use 2D trig to calculate distance and to-go direction. The example is opencv, believe there are similar functions in matlab $\endgroup$ – EEd Aug 2 '14 at 20:03
  • $\begingroup$ Each robot has color patch on top. Ceiling Camera look down and see the robot patches cs.cmu.edu/~robosoccer/small/#media $\endgroup$ – EEd Aug 2 '14 at 20:12
  • $\begingroup$ one more help needed, i am able to find out the distance between two centroids, but how to find the angles? Please help $\endgroup$ – Nabajyoti Das Aug 2 '14 at 20:51
  • $\begingroup$ If camera is 0 to 99 on xy dimension (replace with real resolution like 640 X 480). Says x0y0 is 0,0 (bottom left corner of camera) x1y1 is 99,99 (top right corner). the angle is 45 degrees. For very accurate result (may not needed) opencv has camera calibration to map out lens distortion error (straight line seen as slightly curved by camera) $\endgroup$ – EEd Aug 2 '14 at 21:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.