Hello everyone, I need help. I am working on a robot arm project using MATLAB and a webcam to detect colors. Do you have any lessons or tutorials for me?
7 views (last 30 days)
Show older comments
Hello everyone, I’m working on a robot arm project using MATLAB and Arduino. I use my phone as a webcam to detect colors (like red or green). If the system detects a red object, the robot arm moves and picks it up, then puts it in the red storage area.
Now, I want to improve the project. Instead of the robot always picking red automatically, I want to click on an object in the camera video (GUI in MATLAB) to choose which color to pick — for example, if I click on a red object, it will pick up red. If I click on green, it will pick up green.
I find it hard to research or find tutorials. Can someone help me or guide me with examples or lessons?
0 Comments
Accepted Answer
Image Analyst
on 24 Jun 2025
Sounds like you have a very controlled environment with known and fixed colors. What you could do with the image is to first mask the image to find all the red objects, and find all the green objects. You can get masks for those colors using the Color Thresholder on the Apps tab of the tool ribbon. Export one function for red, then find green and export the green function. Remember to change their names since they both can't use the same function name which the Export button exports.
Once you have the masks you might have to clean up the mask with functions like bwareafilt or bwareaopen to specify the size range you expect the colored regions to be in.
14 Comments
Image Analyst
on 30 Jun 2025
Yes but the webcam snaps an image. You can then call imwrite right after you snap it to save it to a file and upload it here. Otherwise, I gave you a demo where I track a green marker pen from a webcam so you can modify that.
More Answers (1)
Jacob Mathew
on 23 Jun 2025
Hi Chan,
Given that you already have a model to detect objects based on color, you can modify the code to return the various objects of color as a list. You can either select the object from the list of detected objects but if you want to use a GUI, then you can follow the below MATLAB Answers post where the author gets the coordinates from the clicked image:
You can then check whether the clicked coordinates is within the bounding box of the objects and if so, the corresponding object information can be passed onto the robotic arm to be picked up.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!