Figured I'd post my OpenCV facetracking project. Sorry for no github project (just me but I hate using github. Never found a convenient way to use it)
I'm using go to do it. You will need to go through these setup steps of installing go/gobot and gocv:
Getting Started - Gobot - Golang framework for robotics, physical computing, and the Internet of Things (IoT)
Getting Started :: GoCV - Golang Computer Vision Using OpenCV 3
I'm testing on a mac, so I don't know how will this program would work on other platforms.
Im using a playstation 4 controller to control the drone. You could replace the joystick controls with keyboard ones and it should still work, but the convenience of having the drone follow you with joystick in hand to take over control is a big feature.
Run the facetracking.go file with the included proto.txt and model files.
An openCV window should open up showing the video feed. I had to make the window that small because otherwise the ffmpeg video conversion speed caused unbearable stutter.
The tracking would work much better/from farther away if I could make the window bigger, but I've not yet found any way to do it and maintain a usable video feed.
To begin tracking your face:
As usual, I take no responsibility for what happens to you/your drone.
Although it hasn't happened to me (yet), there is the risk that your face will hit the drone. You could print out an image of a face or load one up on your phone and use that instead.
How it works:
Thanks to @deadprogram for all his work with gobot and gocv, and everyone else here on these forums for all the development work gone into this.
I'm using go to do it. You will need to go through these setup steps of installing go/gobot and gocv:
Getting Started - Gobot - Golang framework for robotics, physical computing, and the Internet of Things (IoT)
Getting Started :: GoCV - Golang Computer Vision Using OpenCV 3
I'm testing on a mac, so I don't know how will this program would work on other platforms.
Im using a playstation 4 controller to control the drone. You could replace the joystick controls with keyboard ones and it should still work, but the convenience of having the drone follow you with joystick in hand to take over control is a big feature.
Run the facetracking.go file with the included proto.txt and model files.
An openCV window should open up showing the video feed. I had to make the window that small because otherwise the ffmpeg video conversion speed caused unbearable stutter.
The tracking would work much better/from farther away if I could make the window bigger, but I've not yet found any way to do it and maintain a usable video feed.
To begin tracking your face:
- Put your face in view of the drone. You should see a green square drawn around it in the video window.
- Press circle on the controller. This will register the size of your face, so the drone knows to move forwards or backwards if your face gets closer or farther.
- Walk around and the drone should follow you, as long as your face remains in its view.
- Press circle again to cancel the tracking and fly normally. The tracking is a toggle, so you can turn it on/off as many times as you want. Main thing is to make sure you first get in view of the drone at the distance you want it to maintain, and then turn tracking on.
As usual, I take no responsibility for what happens to you/your drone.
Although it hasn't happened to me (yet), there is the risk that your face will hit the drone. You could print out an image of a face or load one up on your phone and use that instead.
How it works:
- ffmpeg execution is started with piped input and output to convert the drones video feed to something opencv can use
- video feed is received and written to ffmpeg stdin
- opencv image mat is created and displayed using the data from ffmpeg stdout
- Using the code at hybridgroup/gocv, face is detected in the image and green square drawn around it
- Once tracking begins, drone will rotate/move up and down to keep the face in the center of the screen.
- Drone will move forwards and backwards to try and maintain the initial distance to the face from when tracking was started.
Thanks to @deadprogram for all his work with gobot and gocv, and everyone else here on these forums for all the development work gone into this.