-
Notifications
You must be signed in to change notification settings - Fork 1
Design
One of the largest components of our code is our utilization of OpenCV. Because none of us have worked with OpenCV before, we had several structural decisions to make. We felt that OpenCV worked on an singular integrated model-view-controller script rather than separate scripts for each. We acknowledge that MVC format is very simple and clear to understand and that it is easily integratable. However, due to the simplicity of our code and the nature of how we are implementing OpenCV, we feel that containing most of the code in one script was more ideal than using MVC format.
Our code is laid out as one giant function, test_main(). Within this there are several key elements: the generate function, the rectangle class, the webcam video, and the fruit mover.
The generate function is fairly simple. It randomly chooses where to launch the fruit from given three different areas along the bottom of the screen (right, middle, and left). Within each of these areas, the fruit can actually launch from any point -- the fruit can technically launch from anywhere along the bottom. The reason it is split in three is because we would like to avoid fruit generated along the far edges of the screen launching away from the middle.
Regarding the webcam video, it is all very by-the-book OpenCV. We take in a video, covert BGR to HSV, determine a filter to only the object(s) we would like to track, then display the original video.
Finally, the fruit mover is the true meat of the code. It has two main purposes: if there are no rectangles, it generates a random number (1-4) of rectangles. Otherwise, it simply moves the rectangles already present.
Beyond this test_main() function, there are several GUIs for a welcome screen, teaching you how to play, and an end screen.
If we were to continue this work in the future, there are several goal aspects that we would like to work on. Sound effects ended up being very difficult to work with, mostly due to the way we structured our code. We did get to a point where we could play a lovely "sword slashing" sound effect, but the video would pause for a second until the sound effect finished. This was because our code runs in one giant while loop, so the loop would not continue until our sound effect finished. We know that we need to run the sound in parallel, but could not manage to finish this in time for our final deliverable. In addition, we would like to implement turning the rectangles into actual fruit-shaped objects. We did not get to this point because we were very focused on making sound work, which sadly did not. This would not be too difficult a feature to implement, and we recommend anyone who would like to continue this work to feel free to do so.