フィルターのクリア

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
kwstis xoustoulakis 2015 年 5 月 16 日
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?
Image Analyst
Image Analyst 2017 年 12 月 25 日
I have no idea how to talk to your servo. Sorry.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMATLAB Support Package for USB Webcams についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by