Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5

Box Color Sorting

#1
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.

我开发一个环境与使用RoboDK 8箱, 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


.rdk ColourSorting Project.rdk(Size: 524.77 KB / Downloads: 260)
#2
Hi Manisan,

We added some OpenCV examples in our Python documentation that you might find useful, see:
//www.sinclairbody.com/doc/en/PythonAPI/exam...-detection

OpenCV has a nice tutorial on colour segmentation, that you can adapt for your needs:
https://docs.opencv.org/4.x/df/d9d/tutor...paces.html
Please read theForum Guidelinesbefore posting!
Find useful information about RoboDK by visiting our2022世界杯32强赛程表时间 .
#3
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.


Attached Files
.rdk ColourSorting Project.rdk(Size: 526.83 KB / Downloads: 191)
.py ColorSorting.py(Size: 1.43 KB / Downloads: 197)
#4
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/robo...k.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'
RDK.setParam('MyColor', reject_color)

Code:
PP1 = RDK.Item('PPI1')
PP12 = RDK.Item('PPI12')

detected_color = detectColor(img)
reject_color = RDK.getParam('MyColor')
if detected_color !- reject_color:
PP1.RunCode()
PP12.RunCode()

You should take a look at our YouTube videos and our Python documentation!
https://www.youtube.com/channel/UCDpDmeu...OgN2nIEtUw
//www.sinclairbody.com/doc/en/PythonAPI/index.html
Please read theForum Guidelinesbefore posting!
Find useful information about RoboDK by visiting our2022世界杯32强赛程表时间 .
#5
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


Attached Files
.py Untitled-1.py(Size: 4.89 KB / Downloads: 199)
.rdk ColourSorting Project.rdk(Size: 527.84 KB / Downloads: 264)
#6
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
upper_b = [179, 255, 255] # red upper bound in HSV
red_mask = cv.inRange(self.img, np.array(lower_b), np.array(upper_b))
red_pixels = red_mask[red_mask > 0].size
print(red_pixels)
Please read theForum Guidelinesbefore posting!
Find useful information about RoboDK by visiting our2022世界杯32强赛程表时间 .




Users browsing this thread:
1 Guest(s)