This implementation aims to measure the elbow angle from a webcam and write it to the serial port.
Please see this video to get a rough idea of what my program does: https://photos.app.goo.gl/Ha8mX6wqMgksg8gQ8
This is how my programs operates:
- Extract everything which matches the skin color to a bipolar image.
- Find the biggest contours (if the number of contours in the frame is > 3, then it will only use the 3 biggest).
- Extract the left most or the right most contour depending on whether the user last pressed 'l' or 'r'.
- Then find the topmost point of that countour.
- Measure the angle between the highest point and the centroid and the x-axis on that contour.
A lot of inspiration was taken from this project: https://github.com/PierfrancescoSoffritti/Handy
The code for measuring the angle between given points was extracted from here: https://medium.com/@manivannan_data/find-the-angle-between-three-points-from-2d-using-python-348c513e2cd
If you are new to OpenCV and need to learn more about the frame work, please refer to this website: https://docs.opencv.org/3.0-beta/doc/py_tutorials/py_tutorials.html
- This code has only been tested on a linux OS. There might be some issues with serial port connectivity on other OS etc.
- Make sure you have a white background, that you are wearing a shirt and nothing in the frame (not even you shirt) matches your skin color.
- Make sure that the arm that you use doesn't go out of the image frame. It needs to stay inside the frame all of time for elbow angles to be measured.
- The program can only handle 1 arm or 1 face and 1 arm or 1 face 2 arms. Anything else will you issues.
- Connect an FTDI to your computer and into the cat.
- Run the program by typing into the terminal: python3 vision_commander.py (You might need to resolve some issues with serial port connectivity at this stage).
- Now you will see 2 different screens on your window. Make sure your skin color stands out in them, that it is significantly different.
- Decide which arm you want to give instructions by (left or right). Flex and unflex the elbow, making sure that your arm doesn't go out of the image frame.
- Bring your elbow into the box on the image. Make sure that the color tone of the skin has the greatest resemblance to the majority of your arm. Press "r" or "l" depending on which arm you chose.
- The bottom-left of the image shows you the angle. Try to get a 0, -70, and 70 onto it without going out of the frame. Adjust your elbow's position if it does.
- Press "r" or "l" to switch between the arms.
- Press "q" to close the program.
-
Serial port issues: Please read through the code of Py_commander.py. It is very self-explanatory and you should be able to figure it out.
-
Comptuter vision related: If the program is having a hard time differentiating your skin from the surroundings, then you could play around with the following in the vision_commander.py file:
-> skin_col_range(frame,coordinates): Play around with the variables Color_wavelength_range, Saturation_brightness. You might need to understand how an HSV system operates. Please go here and play around with the HSV color scheme: http://colorizer.org/.
-> angle_writer(cap,key,skin_range,port): You could also also increase or decrease the kernels for gaussian blurring or the morphological transformations. If the area of contours is too thick or thin, then alter the number of iterations for dilations.