-
Notifications
You must be signed in to change notification settings - Fork 0
/
test2.cpp
72 lines (69 loc) · 1.84 KB
/
test2.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <vlcpp/vlc.hpp>
#include <opencv2/opencv.hpp>
#include <iostream>
#include <string>
#include <thread>
#include <dlib/opencv.h>
#include "NeuralNetworkSettings.hpp"
#include <unistd.h>
#include <stdlib.h>
#include <fstream>
int main()
{
//std::string filename = "/home/rohan/Downloads/videoplayback.avi";
system("python3 realtime.py");
std::ifstream in; in.open("test.txt");
std::string filename;
std::getline(in, filename);
std::cout<<filename<<'\n';
in.close();
cv::VideoCapture cap(filename);
int duration = cap.get(cv::CAP_PROP_FRAME_COUNT) / cap.get(cv::CAP_PROP_FPS);
std::cout << "Duration " << duration << "s\n";
cap.release();
auto instance = VLC::Instance(0, nullptr);
auto media = VLC::Media(instance, filename, VLC::Media::FromPath);
auto mp = VLC::MediaPlayer(media);
cap = cv::VideoCapture("/dev/video0");
net_type net;
dlib::deserialize("mmod_human_face_detector.dat") >> net;
cv::Mat temp;
mp.play();
std::this_thread::sleep_for(std::chrono::seconds(1));
//sleep(1);
int current_time = 1;
bool ctrl = true;
while(ctrl)
{
cap >> temp;
dlib::matrix<dlib::rgb_pixel> img;
dlib::assign_image(img, dlib::cv_image<dlib::bgr_pixel>(temp));
auto dets = net(img);
int faces = dets.size();
std::cout<<faces<<'\n';
std::cout<<"Status = " << mp.state() << '\n';
/*
3 - Playing
4 - Paused
6 - Stopped
*/
if(faces > 0)
{
if(mp.state() == 4)
mp.play();
if(mp.state() == 6)
{
mp.stop();
ctrl = false;
}
}
else
{
if(mp.state() == 3)
{
mp.pause();
}
}
}
cap.release();
}