Box Color Sorting- Printable Version +- RoboDK Forum (//www.sinclairbody.com/forum) +-- Forum: RoboDK (EN) (//www.sinclairbody.com/forum/Forum-RoboDK-EN) +--- Forum: RoboDK API (//www.sinclairbody.com/forum/Forum-RoboDK-API) +--- Thread: Box Color Sorting (/Thread-Box-Color-Sorting) |
Box Color Sorting-manisan-11-06-2021 Hi, I am developing a program for my master thesis and just recently started using RoboDK. I am a newbie in Python, actually programming in general. I develop an environment with 8 boxes using RoboDK, two of which are different colors. I want to be able to use the robotic arm to detect the color of the boxes using RGB values or whatever is simpler and make it able to pick the one that is out-of-spec and place it out of the line. For example, in a single straight line I have 6 green boxes, 1 red box and 1 blue box. I want to robotic arm with the camera to go over the boxes in a straight path and if it sees the red or blue box, to place it out of the line since it is not green. I also would like to do it with predominantly red boxes and in another case, predominantly blue boxes. I have attached the RoboDK environment with the targets and everything but have found it difficult to program into the robot this "color sorting" capacity. Thanks in advance, Manisan ColourSorting Project.rdk(Size: 524.77 KB / Downloads: 272) RE: Box Color Sorting-Sam-11-08-2021 Hi Manisan, We added some OpenCV examples in our Python documentation that you might find useful, see: //www.sinclairbody.com/doc/en/PythonAPI/examples.html#object-detection OpenCV has a nice tutorial on colour segmentation, that you can adapt for your needs: https://docs.opencv.org/4.x/df/d9d/tutorial_py_colorspaces.html RE: Box Color Sorting-manisan-11-24-2021 Hello Sam! Thank you for your response. I have been able to create a program to use with the colour sorting aspect of the project and have finishhed the RoboDK environment for the experiment. The colour code is written in python and I am struggling to add this code or integrate it with the RoboDK environment. My initial approach was to generate a code from the RoboDK software, edit it by adding my color processing code and then run it in the simulator. For some reason the code will not run. Ive attached en simulation environment. You can see that PP#, PL# etc are different trajectories. I also attahced the colour procesing code. I would like to integrate the two and do some sort of a "If block is X color, do PP1 or do PA12, etc" In summary, Im just trying to find a way to integrate the colour processing code of python with the RoboDK environment. RE: Box Color Sorting-Sam-11-26-2021 Nice job! You can save parameters to the station (or an item) and reuse them in other program calls, see://www.sinclairbody.com/doc/en/PythonAPI/robolink.html?highlight=setparam#robolink.Robolink.setParam For instance, you could run your ColorSorting script once at the beginning of your sequence to request the colour to the user. You can then have a second script that process the image using the recorded colour.
Code:
reject_color = 'RED'
Code:
PP1 = RDK.Item('PPI1')
You should take a look at our YouTube videos and our Python documentation! https://www.youtube.com/channel/UCDpDmeuYShxBYOgN2nIEtUw //www.sinclairbody.com/doc/en/PythonAPI/index.html RE: Box Color Sorting-manisan-12-01-2021 Hello Sam, Took a little different approach but I managed to do it. Your reply really took me on the right path and point me to the right resources. I have NO programming experience whatsoever and I have managed to do it. I dont know if you can tell but I am excited and RoboDK has just saved my Master degree haha. Here is the code and environment so people and play around and definitely improve it. Cheers, Armani Caban RE: Box Color Sorting-Sam-12-02-2021 I'm glad you were able to achieve your goals with no programming experience using RoboDK. This is what we aim for! I see you are using one pixel at the image centre to get the colour. In reality, the image will be affected by ambient lights, shadows, reflection, etc You can use colour segmentation to retrieve the dominating colour. Here's a sample code:
Code:
lower_b = [160, 100, 20] # red lower bound in HSV
|