Using X and Y coordinate to control 2 servo motor using Arduino.
11 views (last 30 days)
Show older comments
This is the code that detects a specific object and show's the centre coordinate of the targeted object.
close all;clear all;clc;
vid=videoinput('winvideo',1,'YUY2_160X120');
set(vid,'TriggerRepeat',Inf);
vid.returnedcolorspace='rgb';
vid.FrameGrabInterval=2;
start(vid)
while(vid.FramesAcquired<=200)
data1=getdata(vid,1);
data=imcomplement(data1);
diff_im = imsubtract(data(:,:,3), rgb2gray(data));
diff_im=medfilt2(diff_im,[1 2]);
diff_im=im2bw(diff_im,0.28);
diff_im=bwareaopen(diff_im,50);
bw=bwlabel(diff_im,8);
stats=regionprops(bw,'BoundingBox','Centroid');
imshow(data1)
hold on
for object=1:length(stats)
bb=stats(object).BoundingBox;
bc=stats(object).Centroid;
rectangle('Position',bb,'EdgeColor','Y','LineWidth',2);
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');
end
hold off
end
stop(vid)
flushdata(vid);
clear all
As from above code:
plot(bc(1),bc(2),'-m+');
a=text(bc(1)+15,bc(2), strcat('X:', num2str(round(bc(1))), 'Y:', num2str(round(bc(2)))));
so bc (1) is the X coordinate and bc (2) is the Y coordinate. How do I use these 2 coordinate to control the 2 servo motor using Arduino?
3 Comments
vishnu andavar
on 7 Apr 2013
at aliff,have u finally found the answer for ur question??i am too facing same prb.
sidra
on 25 Dec 2017
so bc (1) is the X coordinate and bc (2) is the Y coordinate. How do I use these 2 coordinate to control the 2 servo motor using matlab and arduino support package to track an object... any update on this query please?
Answers (0)
Communities
More Answers in the Power Electronics Control
See Also
Categories
Find more on Arduino Hardware 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!