Tutorial: Find the yellow square! - PatrickPenguinTurtle/GRIPWiki GitHub Wiki
Here's an easy example usecase to help get you started!
In this tutorial we will try to find the yellow square in the image and display it's position. The setup is pretty simple, just a USB web camera connected to the computer looking down at some colorful objects. The yellow plastic square is the thing that we're interested in locating in the image.
Enable the image source
The first step is to acquire an image. For this tutorial, we used a webcam (to use a webcam, click on the "Add Webcam" button and select the camera number), but if you want to follow along, you can download the image displayed above and add it using the "Add Image" button. Then you can select the image preview button and the real-time display of the camera stream (or the static image you provided, if you're following along from home) will be shown in the preview area.
##Resize the image
In this case the camera resolution is too high for our purposes, and in fact the entire image cannot even be viewed in the preview window. The "Resize" operation is clicked from the Operation Palette to add it to the end of the pipeline. To help locate the Resize operation, type "Resize" into the search box at the top of the palette. The steps are:
- Type "Resize" into the search box on the palette
- Click the Resize operation from the palette. It will appear in the pipeline.
- Enter the x and y resize scale factor into the resize operation in the pipeline. In this case 0.25 was chosen for both.
- Drag from the Webcam image output mat socket to the Resize image source mat socket. A connection will be shown indicating that the camera output is being sent to the resize input.
- Click on the destination preview button on the "Resize" operation in the pipeline. The smaller image will be displayed alongside the larger original image. You might need to scroll horizontally to see both as shown.
- Lastly, click the Webcam source preview button (since there is no reason to look at both the large image and the smaller image at the same time!).
##Find only the yellow parts of the image
The next step is to remove everything from the image that doesn't match the yellow color of the piece of plastic that is the object being detected. To do that a HSV Threshold operation is chosen to set upper and lower limits of HSV values to indicate which pixels should be included in the resultant binary image. Notice that the target area is white while everything that wasn't within the threshold values are shown in black. Again, as before:
- Type HSV into the search box to find the HSV Threshold operation.
- Click on the operation in the palette and it will appear at the end of the pipeline.
- Connect the dst (output) socket on the resize operation to the input of the HSV Threshold.
- Enable the preview of the HSV Threshold operation so the result of the operation is displayed in the preview window.
- Adjust the Hue, Saturation, and Value parameters only the target object is shown in the preview window.
##Get rid of the noise and extraneous hits
This looks pretty good so far, but sometimes there is noise from other things that couldn't quite be filtered out. To illustrate one possible technique to reduce those occasional pixels that were detected, an Erosion operation is chosen. Erosion will remove small groups of pixels that are not part of the area of interest.
##Mask to just the yellow area from the original image
Here a new image is generated by taking the original image and masking it with the the results of the erosion. This leaves just the yellow card as seen in the original image with nothing else shown. And it makes it easy to visualize exactly what was being found through the series of filters.
##Find the yellow area (blob)
The last step is actually detecting the yellow card using a Blob Detector. This operation looks for a grouping of pixels that have some minimum area. In this case, the only non-black pixels are from the yellow card after the filtering is done. You can see that a circle is drawn around the detected portion of the image.