Skip to content

Commit

Permalink
Add Hand Gesture Detection Example (#295)
Browse files Browse the repository at this point in the history
* Add Hand Gesture Detection Example

* Update NNGestureDetection cpp

* Update OSD API

* Update NNModelSelection.h

* Update OSD.update API
  • Loading branch information
kev0077 authored Feb 5, 2025
1 parent 0960fbc commit f0936a2
Show file tree
Hide file tree
Showing 9 changed files with 844 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,8 @@ void VideoStreamOverlay::update(int ch, int idx)
{
canvas_update(ch, idx, 1);
}

void VideoStreamOverlay::update(int ch, int idx, int ready_to_update)
{
canvas_update(ch, idx, ready_to_update);
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class VideoStreamOverlay {
void drawRect(int ch, int xmin, int ymin, int xmax, int ymax, int line_width, uint32_t color, int idx = 0);
void drawText(int ch, int xmin, int ymin, const char *text_string, uint32_t color, int idx = 0);
void update(int ch, int idx = 0);
void update(int ch, int idx, int ready_to_update);

private:
int ch_enable[3] = {0};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#include "WiFi.h"
#include "StreamIO.h"
#include "VideoStream.h"
#include "RTSP.h"
#include "NNGestureDetection.h"
#include "VideoStreamOverlay.h"

#define CHANNEL 0
#define CHANNELNN 3

// Customised resolution for NN
#define NNWIDTH 192
#define NNHEIGHT 192

VideoSetting config(VIDEO_FHD, 30, VIDEO_H264, 0);
VideoSetting configNN(NNWIDTH, NNHEIGHT, 10, VIDEO_RGB, 0);
NNGestureDetection gesturedetect;
RTSP rtsp;
StreamIO videoStreamer(1, 1);
StreamIO videoStreamerRGBGD(1, 1);

char ssid[] = "Network_SSID5"; // your network SSID (name)
char pass[] = "Password"; // your network password
int status = WL_IDLE_STATUS;

IPAddress ip;
int rtsp_portnum;

void setup()
{
Serial.begin(115200);

// Attempt to connect to Wifi network:
while (status != WL_CONNECTED) {
Serial.print("Attempting to connect to WPA SSID: ");
Serial.println(ssid);
status = WiFi.begin(ssid, pass);

// wait 2 seconds for connection:
delay(2000);
}

ip = WiFi.localIP();

// Configure camera video channels with video format information
// Adjust the bitrate based on your WiFi network quality
config.setBitrate(2 * 1024 * 1024); // Recommend to use 2Mbps for RTSP streaming to prevent network congestion
Camera.configVideoChannel(CHANNEL, config);
Camera.configVideoChannel(CHANNELNN, configNN);
Camera.videoInit();

// Configure RTSP with corresponding video format information
rtsp.configVideo(config);
rtsp.begin();
rtsp_portnum = rtsp.getPort();

// Configure Gesture Detection model
// Select Neural Network(NN) task and models
gesturedetect.configVideo(configNN);
gesturedetect.modelSelect(GESTURE_DETECTION, NA_MODEL, NA_MODEL, NA_MODEL, NA_MODEL, NA_MODEL, DEFAULT_PALMDETECT, DEFAULT_HANDLANDMARK);
gesturedetect.begin();

// Configure StreamIO object to stream data from video channel to RTSP
videoStreamer.registerInput(Camera.getStream(CHANNEL));
videoStreamer.registerOutput(rtsp);
if (videoStreamer.begin() != 0) {
Serial.println("StreamIO link start failed");
}
// Start data stream from video channel
Camera.channelBegin(CHANNEL);

// Configure StreamIO object to stream data from RGB video channel to gesture detection
videoStreamerRGBGD.registerInput(Camera.getStream(CHANNELNN));
videoStreamerRGBGD.setStackSize();
videoStreamerRGBGD.setTaskPriority();
videoStreamerRGBGD.registerOutput(gesturedetect);
if (videoStreamerRGBGD.begin() != 0) {
Serial.println("StreamIO link start failed");
}

// Start video channel for NN
Camera.channelBegin(CHANNELNN);

// Start OSD drawing on RTSP video channel
OSD.configVideo(CHANNEL, config);
OSD.configTextSize(CHANNEL, 16, 32);
OSD.begin();
gesturedetect.drawHandRegion();
}

void loop()
{
// Do nothing
}
Loading

0 comments on commit f0936a2

Please sign in to comment.