-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_fast.cpp
More file actions
83 lines (66 loc) · 2.09 KB
/
main_fast.cpp
File metadata and controls
83 lines (66 loc) · 2.09 KB
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
73
74
75
76
77
78
79
80
81
82
83
#include <fstream>
#include <sstream>
#include <iostream>
#include <thread>
// Required for dnn modules.
#include <opencv2/dnn.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
using namespace dnn;
#include "pipert/Scheduler.h"
#include "pipert/Profiler.h"
using namespace std;
class FrameTranslator
{
private:
pipert::PolledChannel<Mat> *ch_to_write_;
public:
FrameTranslator(pipert::PolledChannel<Mat> *ch_to_write) : ch_to_write_(ch_to_write) {}
void Translator(pipert::PacketToProcess<Mat> p)
{
// pipert::Timer::Time time = pipert::Timer::time();
// float sec = (time - p.timestamp());
// cout << sec << endl;
ch_to_write_->Acquire(p.timestamp() + 5, p.data());
}
};
int main(int argc, char **argv)
{
// pipert::Scheduler sch(0, pipert::Profiler("file:fast_profilerlog.txt"));
pipert::Scheduler sch(0, pipert::Profiler("udp:127.0.0.1:8000"));
int channel_capacity = 10;
pipert::PolledChannel<Mat> pc =
sch.CreatePolledChannel<Mat>("OutChannel", channel_capacity);
FrameTranslator ft(&pc);
pipert::ScheduledChannel<Mat> sc =
sch.CreateScheduledChannel<Mat>("TranslatorChannel", channel_capacity, nullptr, bind(&FrameTranslator::Translator, &ft, placeholders::_1));
sch.Start();
pipert::Timer::Time time = pipert::Timer::time();
Mat frame;
cv::VideoCapture cap;
cap.open(argv[1]);
while (true)
{
cap.read(frame);
if (frame.empty())
break;
// time = pipert::Timer::time();
pipert::PacketToFill<Mat> packet_to_fill =
sc.Acquire(time, frame.clone());
packet_to_fill.Push();
pipert::PacketToProcess<Mat> packet_to_process = pc.Poll();
while (packet_to_process.IsEmpty())
{
packet_to_process = pc.Poll();
}
sch.GetProfiler().GatherNSend();
cv::imshow("Display", packet_to_process.data());
char c = (char)cv::waitKey(25);
if (c == 27)
break;
}
sch.Stop();
}