oZone Server Framework
Enabling Innovation in Video Applications
starter_example.cpp
1 #include "../base/ozApp.h"
2 #include "../base/ozListener.h"
3 #include "../providers/ozAVInput.h"
4 #include "../processors/ozMotionDetector.h"
5 #include "../processors/ozFaceDetector.h"
6 #include "../processors/ozShapeDetector.h"
7 #include "../processors/ozRateLimiter.h"
8 #include "../processors/ozImageScale.h"
9 #include "../processors/ozAVFilter.h"
10 #include "../processors/ozMatrixVideo.h"
11 #include "../protocols/ozHttpController.h"
12 
13 #include "../libgen/libgenDebug.h"
14 
15 #include <iostream>
16 
17 //
18 //
19 int main( int argc, const char *argv[] )
20 {
21  debugInitialise( "starter-example", "", 0 );
22 
23  std::cout << " ---------------------- Starter Example ------------------\n"
24  " do a export DBG_PRINT=0/1 to turn off/on logs\n"
25  " once running, load up starter-example.html in your browser\n"
26  " You should see a traffic cam window as well as motion detection frames in another\n"
27  " in real-time\n";
28 
29  Info( "Starting" );
30 
31  avInit();
32 
33  Application app;
34 
35  // Two RTSP sources
36  AVInput traffic( "traffic", "rtsp://170.93.143.139:1935/rtplive/0b01b57900060075004d823633235daa" );
37  Options peopleOptions;
38  peopleOptions.add( "realtime", true );
39  peopleOptions.add( "loop", true );
40  AVInput people( "people", "face-input.mp4", peopleOptions );
41  app.addThread( &traffic );
42  app.addThread( &people );
43 
44  // motion detect for traffic
45  Options motionOptions;
46  motionOptions.load( "OZ_OPT_MOTION_" );
47  motionOptions.dump();
48  MotionDetector trafficDetector( traffic, motionOptions );
49  app.addThread( &trafficDetector );
50 
51  // rate limiter for people detector
52  RateLimiter peopleLimiter( 5, true, people );
53  app.addThread( &peopleLimiter );
54 
55  // Scale video up
56  //ImageScale peopleScalePre( Rational( 1, 2 ), peopleLimiter );
57  //app.addThread( &peopleScalePre );
58 
59  // people detect for people
60  //ShapeDetector peopleDetector( "dlib_pedestrian_detector.svm", ShapeDetector::OZ_SHAPE_MARKUP_OUTLINE, peopleLimiter );
61  Options faceOptions;
62  faceOptions.set( "method", "hog" );
63  faceOptions.set( "dataFile", "shape_predictor_68_face_landmarks.dat" );
64  faceOptions.set( "markup", FaceDetector::OZ_FACE_MARKUP_ALL );
65  FaceDetector peopleDetector( peopleLimiter, faceOptions );
66  app.addThread( &peopleDetector );
67 
68  // Scale video down
69  //ImageScale peopleScalePost( Rational( 1, 2 ), peopleDetector );
70  //app.addThread( &peopleScalePost );
71 
72  // Turn black and white
73  //VideoFilter peopleFilter( "hue=s=0, scale=iw/2:-1", people );
74  //VideoFilter peopleFilter( "people-filter", "scale=iw/2:-1" );
75  //peopleFilter.registerProvider( people );
76  //app.addThread( &peopleFilter );
77 
78  // Let's make a mux/stitched handler for traffic and people and its debugs
79  MatrixVideo trafficMatrix( "traffic-matrix", PIX_FMT_YUV420P, 640, 480, FrameRate( 1, 10 ), 2, 2 );
80  trafficMatrix.registerProvider( *trafficDetector.compImageSlave() );
81  trafficMatrix.registerProvider( *trafficDetector.refImageSlave() );
82  trafficMatrix.registerProvider( *trafficDetector.varImageSlave() );
83  trafficMatrix.registerProvider( *trafficDetector.deltaImageSlave() );
84  app.addThread( &trafficMatrix );
85 
86  Listener listener;
87  app.addThread( &listener );
88 
89  HttpController httpController( "watch", 9292 );
90  httpController.addStream( "watch",traffic );
91  httpController.addStream( "watch", people );
92 
93  httpController.addStream( "detect", trafficDetector );
94  httpController.addStream( "detect", peopleDetector );
95  //httpController.addStream( "filter", peopleFilter );
96 
97  httpController.addStream( "debug", trafficMatrix );
98 
99  listener.addController( &httpController );
100  app.run();
101 }
void addController(Controller *controller)
Add a controller to permit new connections using specific protocol.
Definition: ozListener.cpp:31
void addStream(const std::string &streamName, const std::string &streamClass)
void addThread(Thread *)
Definition: ozApp.cpp:25