-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtwo_thread.cpp
81 lines (71 loc) · 1.59 KB
/
two_thread.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
73
74
75
76
77
78
79
80
81
#include <iostream>
#include <thread>
#include <unistd.h>
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
using namespace std;
using namespace cv;
pthread_mutex_t mutex;
Mat frame0,frame1;
int totalNum = 1;
void thread01()
{
pthread_mutex_lock(&mutex);
VideoCapture capture0(0);
if (!capture0.isOpened())
{ printf("err_a");
//return -1;
}
else
{printf("aa");}
pthread_mutex_unlock(&mutex);
while(1)
{
capture0>>frame0;
imshow("frame0",frame0);
//pthread_mutex_lock(&mutex);
//cout <<"aaaaaa"<< totalNum << endl;
//pthread_mutex_unlock(&mutex);
//usleep(3000);
waitKey(1);
}
}
void thread02()
{
pthread_mutex_lock(&mutex);
VideoCapture capture1(2);
if (!capture1.isOpened())
{ printf("err_b");
//return -1;
}
else
{printf("bb");}
pthread_mutex_unlock(&mutex);
while(1)
{
capture1>>frame1;
imshow("frame1",frame1);
//pthread_mutex_lock(&mutex);
//cout <<"bbbbbb"<< totalNum << endl;
//pthread_mutex_unlock(&mutex);
//usleep(3000);
waitKey(1);
}
}
int main()
{
thread task01(thread01);
thread task02(thread02);
task01.detach();
task02.detach();
while(1)
{
pthread_mutex_lock(&mutex);
if(totalNum>=20) totalNum=0;
totalNum++;
cout <<"mainmainmain"<< totalNum << endl;
pthread_mutex_unlock(&mutex);
sleep(1);
}
return(0);
}