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??
Mostra commenti meno recenti
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 Commenti
Image Analyst
il 16 Mag 2015
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
il 16 Mag 2015
Risposte (1)
Image Analyst
il 16 Mag 2015
0 voti
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 Commenti
kwstis xoustoulakis
il 17 Mag 2015
sidra
il 25 Dic 2017
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
il 25 Dic 2017
I have no idea how to talk to your servo. Sorry.
Categorie
Scopri di più su MATLAB Support Package for USB Webcams in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!