This code detects red objects. I have create a robotic arm and I want via a camera to detect red objects and move the arm in these. So how can I modify the code so I have communication with the servo ???Any help with the code??

3 次查看(过去 30 天)
vid=videoinput('winvideo',1,'YUY2_320x240');
set(vid,'FramesPerTrigger',inf);
set(vid,'ReturnedColorspace','rgb')
vid.FrameGrabInterval=5;
a=arduino('COM3');
a.servoAttach(9);
a.servoAttach(10);
a.servoAttach(11);
start(vid);
while(vid.FramesAcquired<=100)
data=getsnapshot(vid);
diff_im=imsubtract(data(:,:,1),rgb2gray(data));
diff_im=medfilt2(diff_im,[3,3]);
diff_im=im2bw(diff_im,0.18);
diff_im=bwareaopen(diff_im,300);
bw=bwlabel(diff_im,8);
stats=regionprops(bw,'BoundingBox','Centroid');
imshow(data);
hold on
for(object=1:length (stats))
bb=stats(object).BoundingBox;
bc=stats(object).Centroid;
rectangle('Position',bb,'EdgeColor','r','LineWidth',2)
plot(bc(1),bc(2),'-m+')
end
hold off
end
stop(vid);
flushdata(vid);
clear all;
  2 个评论
Image Analyst
Image Analyst 2015-5-16
Forgetting about the red color detection for the moment, are you able to talk to your servo at all yet? Figuring out how to do that, and how to move the arm to a specific location, is something that needs to be done first, or in parallel with your red object detection code.
kwstis xoustoulakis
yes im able to talk to all servos via matlab with a simple m-file code that i giving angles and my arm moves ,but im looking how to modify my code so my arm moves in red objects!!thanks

请先登录,再进行评论。

回答(1 个)

Image Analyst
Image Analyst 2015-5-16
The camera calibration routines in the Computer Vision System Toolbox will make this easier for you. http://www.mathworks.com/help/vision/camera-calibration-and-3-d-vision.html You can hopefully be able to convert from a location in your image to a point in 3D real world space and then tell your servo to move the arm there. I don't have code for that. I'm sure it won't be some simple 100 line long chunk of code - it will be somewhat complicated.
  3 个评论
sidra
sidra 2017-12-25
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?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 C4ISR 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by