Saturday, 19 March 2016

Sprint 2 - Shape Detect. William



For this sprint I was assigned the task of creating a shape detect program using openCV. For the start of this sprint there was quite a struggle to get the shape detect working correctly as the functions used were pretty new to me and each function had more than 1 result meaning there were 2-3 variables being output from each. This is when I decided to get the program working to recognise the shapes using JPG files which had been created in paint. I found this to be one of the more challenging sides to the sprint as I had not used any of the functions before. It was from here that I learned that I had to ensure that the image was in grayscale and also that the colour thresholds had to be applied to reduce the shades of grey used in the image while converting to grayscale.
                It was next that I was introduced to the function of findContours. This is a function that will identify all of the contours on the image, in this case it is a change from the shape sides to the white background. This function has 3 outputs, the first one is the source image, second is the contour retrieval mode and third is the contour approximation method. It is the second that I needed to pay attention to as this was the array created with the contour information. The contour information is then passed to a function named ApproxPolyDP. This function manipulated the information from findContours and returned an approximate value for the amount of edges of the shape. An If-Else-If ladder then linked the corresponding side number to the shape.

From here the next step was to implement the camera into the program. I began by using PiCamera and was using this until I found a problem that the camera was trying to re-enable itself on every iteration of the loop. This caused the program to crash continuously so I had to change to using PiRGBArray for image capture. Once this was done it was then possible to test the program.
The program clearly detects the shape from the image as can be seen in the video, however it is also clear that it tends to be detecting a square or pentagn also. The program would also work differently depending on the ambient lighting. Thetwo videos below demonstrate the shape detect operation. There is a lot of false detection and after some reearch I am presuming that this may be down to noise. Noise can be introduced into the picture with the simple shake of a hand. The other issue that I noted it the sharpness of the image that the program is counting the contours on. The PiCamera module is fully focused at 60cm away from the camera. At this distance it would be impossible to display a shape on a page and also display a clear background. To improve this I hope to implement a masking area into the capture frame so I am only reading whats inside the smaller area
By William Ryan #3

No comments:

Post a Comment