> For the complete documentation index, see [llms.txt](https://campus-rover.gitbook.io/lab-notebook/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://campus-rover.gitbook.io/lab-notebook/fiiva/reports/2020/gesture-recognition/local-camera.md).

# local-camera.md

s### Hand Gesture Recognition After reaching the dead-end in the previous approach and being inspired by several successful projects (on Github and other personal tech blogs), I implemented an explict-feature-driven hand recognition algorithm. It relies on background extraction to "extract" hands (giving gray scale images), and based on which compute features to recognize the number of fingers. It worked pretty well if the camera and the background are ABSOLUTELY stationary but it isn't the case in our project: as the camera is mounted on the robot and the robot keeps moving (meaning the background keeps changing). Code can be founded [here](https://github.com/campusrover/count_fingers)

## References

[Opencv python hand gesture recognition](http://creat-tabu.blogspot.com/2013/08/opencv-python-hand-gesture-recognition.html)

[Hand Tracking And Gesture Detection](https://s-ln.in/2013/04/18/hand-tracking-and-gesture-detection-opencv/)

### Dependencies Overview

* OpenCV
* ROS Kinetic (Python 2.7 is required)
* A Camera connected to your device

### How to Run

1. Copy this package into your workspace and run `catkin_make`.
2. Simply Run `roslaunch gesture_teleop teleop.launch`. A window showing real time video from your laptop webcam will be activated. Place your hand into the region of interest (the green box) and your robot will take actions based on the number of fingers you show. 1. Two fingers: Drive forward 2. Three fingers: Turn left 3. Four fingers: Turn right 4. Other: Stop

![f5](https://github.com/campusrover/labnotebook/blob/master/reports/2020/.gitbook/assets/1.png)

![f4](https://github.com/campusrover/labnotebook/blob/master/reports/2020/.gitbook/assets/2.png)

![f3](https://github.com/campusrover/labnotebook/blob/master/reports/2020/.gitbook/assets/3.png)

![f2](https://github.com/campusrover/labnotebook/blob/master/reports/2020/.gitbook/assets/4.png)

### Brief Explaination towards the package

This package contains two nodes.

1. `detect.py`: Recognize the number of fingers from webcam and publish a topic of type `String` stating the number of fingers. I won't get into details of the hand-gesture recognition algorithm. Basically, it extracts the hand in the region of insteret by background substraction and compute features to recognize the number of fingers.
2. `teleop.py`: Subscribe to `detect.py` and take actions based on the number of fingers seen.

   ```python
   while not rospy.is_shutdown():
    twist = Twist()
    if fingers == '2':
        twist.linear.x = 0.6
        rospy.loginfo("driving forward")
    elif fingers == '3':
        twist.angular.z = 1
        rospy.loginfo("turning left")
    elif fingers =='4':
        twist.angular.z = 1
        rospy.loginfo("turning right")
    else:
        rospy.loginfo("stoped")
    cmd_vel_pub.publish(twist)
    rate.sleep()
   ```

### Later Plan

1. Using Kinect on mutant instead of local webcam.
2. Furthermore, use depth camera to extract hand to get better quality images
3. Incorporate **Skeleton tracking** into this package to better localize hands (I am using **region of insterests** to localize hands, which is a bit dumb).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://campus-rover.gitbook.io/lab-notebook/fiiva/reports/2020/gesture-recognition/local-camera.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
