This repository was archived by the owner on Apr 14, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvideo_dispatch.cpp
More file actions
67 lines (58 loc) · 1.43 KB
/
video_dispatch.cpp
File metadata and controls
67 lines (58 loc) · 1.43 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
#include "video_dispatch.h"
#include <vector>
#include <algorithm>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
VideoDispatcher::VideoDispatcher(){
camera = Camera::getInstance();
preprocessor=NULL;
}
VideoDispatcher::~VideoDispatcher(){
camera->close();
}
void VideoDispatcher::attach(VideoReceiver *obs){
dispatchGuard.lock();
observers.push_back(obs);
dispatchGuard.unlock();
}
void VideoDispatcher::remove(VideoReceiver *obs){
dispatchGuard.lock();
observers.erase(std::remove(observers.begin(),observers.end(),obs),observers.end());
dispatchGuard.unlock();
}
void VideoDispatcher::removeAll()
{
dispatchGuard.lock();
observers.clear();
dispatchGuard.unlock();
}
void VideoDispatcher::setPreprocessor(ImageProcessor &preproc)
{
dispatchGuard.lock();
preprocessor = &preproc;
dispatchGuard.unlock();
}
void VideoDispatcher::dispatchFrame(){
dispatchGuard.lock();
cv::Mat* frame;
if(observers.empty()){
goto finalize;
}
frame = camera->read();
if(frame==NULL){
goto finalize;
}else if(frame->empty()){
delete frame;
goto finalize;
}
if(preprocessor!=NULL)
preprocessor->process(*frame);
cv::Mat* copy;
for(unsigned int i=0;i<observers.size();i++){
copy = new Mat(*frame);
observers[i]->update(copy);
}
delete frame;
finalize:
dispatchGuard.unlock();
}