-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvideostream.cpp
More file actions
58 lines (46 loc) · 1.27 KB
/
Copy pathvideostream.cpp
File metadata and controls
58 lines (46 loc) · 1.27 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
#include "videostream.h"
VideoStream::VideoStream(cv::VideoCapture &c, cv::VideoWriter &o, int send_fps):cap(c), out(o){
fps = send_fps;
}
void VideoStream::startStream(){
if(streamActive == false){
streamActive = true;
//Spawn thread to stream camera frames
streamThread=std::thread(&VideoStream::stream, this);
#ifdef DISPLAY_MESSAGES
cout<<"\n(VIDEOSTREAM) Spawning thread to start stream.";
#endif
}
else{
#ifdef DISPLAY_MESSAGES
cout<<"\n(VIDEOSTREAM) Stream already running.";
#endif
}
}
void VideoStream::stream(){
cv::Mat frame;
while (streamActive){
cap.read(frame);
if(frame.empty()){
//std::cout<<"\n(VIDEOSTREAM) ERROR: Frame not received from video source.";
continue;
}
cv::imshow("i",frame);
if(cv::waitKey(1) == 's')
break;
//out.write(frame);
}
}
void VideoStream::stopStream(){
if(streamActive){
streamActive = false;
#ifdef DISPLAY_MESSAGES
cout<<"\n(VIDEOSTREAM) Stopping stream.";
#endif
}
else{
#ifdef DISPLAY_MESSAGES
cout<<"\n(VIDEOSTREAM) Stream already stopped.";
#endif
}
}