void readRTSP(const std::string&& rtsp) {
cv::VideoCapture cap;
auto cvname = std::this_thread::get_id();
std::ostringstream oss;
oss << cvname;
auto strName = oss.str();
std::cout << "thread id " << strName << "read: " << rtsp << std::endl;
cap.open(rtsp);
if (!cap.isOpened()) {
std::cout << "open video failed";
cap.release();
}
cv::Mat frame;
for (;;) {
cap >> frame;
if (frame.empty())
{
std::cout << "thread-" << strName << " frame empty! " << std::endl;;
continue;
}
std::unique_lock<std::mutex> lock{ m_mutex };
while (frame_que->size() == MAXQUESIZE)
{
std::cout << "**********队列满*********" << std::endl;
my_cond.wait(lock);
}
std::cout << "+++++++压入队列+++++++" << std::endl;
frame_que->push(frame);
my_cond.notify_one();
std::cout << "生产者唤醒消费者" << std::endl;
}
}
- 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
for (;;)
{
std::unique_lock<std::mutex>lock{ m_mutex };
while (frame_que->empty())
{
std::cout << "**********队列空*********" << std::endl;
my_cond.wait(lock);
}
while (!frame_que->empty()) {
auto frame = frame_que->front();
auto res = detector.Run(frame, conf_thres, iou_thres);
Demo(frame, res, class_names);
frame_que->pop();
my_cond.notify_one();
std::cout << "消费者唤醒生产者" << std::endl;
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
void readRTSP(const std::string&& rtsp) {
cv::VideoCapture cap;
auto cvname = std::this_thread::get_id();
std::ostringstream oss;
oss << cvname;
auto strName = oss.str();
std::cout << "thread id " << strName << "read: " << rtsp << std::endl;
cap.open(rtsp);
if (!cap.isOpened()) {
std::cout << "open video failed";
cap.release();
}
cv::Mat frame;
while (cap.read(frame)) {
if (frame.empty())
{
std::cout << "thread-" << strName << " frame empty! " << std::endl;;
continue;
}
if (frame_que->size() < MAXQUESIZE) {
std::cout << "+++++++压入队列+++++++" << std::endl;
frame_que->push(frame);
}
else
{
std::cout << "**********队列满*********" << std::endl;
continue;
}
}
cap.release();
cv::destroyAllWindows();
}
fun2():
m_mutex.lock();
while (!frame_que->empty()) {
auto frame = frame_que->front();
auto res = detector.Run(frame, conf_thres, iou_thres);
Demo(frame, res, class_names);
frame_que->pop();
m_mutex.unlock();
}
std::cout << "-------队列空------" << std::endl;
m_mutex.unlock();
or fun2():
for (;;)
{
std::unique_lock<std::mutex>lock{ m_mutex };
m_mutex.lock();
if (!frame_que->empty()) {
auto frame = frame_que->front();
auto res = detector.Run(frame, conf_thres, iou_thres);
Demo(frame, res, class_names);
frame_que->pop();
}
else
{
std::cout << "-------队列空------" << std::endl;
m_mutex.unlock();
continue;
}
m_mutex.unlock();
}
- 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
- 84
- 85