Using X and Y coordinate to control 2 servo motor using Arduino.

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

Could you provide more context to help us understand the problem? What is your physical setup?
at aliff,have u finally found the answer for ur question??i am too facing same prb.
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?

Sign in to comment.

Answers (0)

Communities

More Answers in the  Power Electronics Control

Categories

Asked:

on 19 Sep 2012

Commented:

on 25 Dec 2017

Community Treasure Hunt

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

Start Hunting!