-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstone_detect.cpp
More file actions
119 lines (98 loc) · 3.36 KB
/
stone_detect.cpp
File metadata and controls
119 lines (98 loc) · 3.36 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include "stone.h"
#include"GxCamera/GxCamera.h"
#include<X11/Xlib.h>
using namespace cv;
using namespace std;
pthread_t thread1;
pthread_t thread2;
void* imageUpdatingThread(void* PARAM);
void* detectingThread(void* PARAM);
Mat srcFrame = Mat::zeros(480,640,CV_8UC3);
pthread_mutex_t Globalmutex;
pthread_cond_t GlobalCondCV;
bool imageReadable = false;
bool newFrame=true;
void* param;
//import Galaxy Camera
GxCamera camera;
int main(int argc, char** argv)
{
//For MutiTHread
//XInitThreads();
//Init mutex
pthread_mutex_init(&Globalmutex,NULL);
//Init cond
pthread_cond_init(&GlobalCondCV,NULL);
//Create thread 1 -- image acquisition thread
pthread_create(&thread1,NULL,imageUpdatingThread,NULL);
//Create thread 2 -- armor Detection thread
pthread_create(&thread2,NULL,detectingThread,NULL);
//Wait for children thread
pthread_join(thread1,NULL);
pthread_join(thread2,NULL);
pthread_mutex_destroy(&Globalmutex);
return 0;
}
void* imageUpdatingThread(void* PARAM)
{
//init camrea lib
camera.initLib();
// open device SN号
camera.openDevice("KJ0190120006");
//camera.openDevice("KE0200010113");
//Attention: (Width-64)%2=0; (Height-64)%2=0; X%16=0; Y%2=0;
// ROI Width Height X Y
camera.setRoiParam( 640, 480, 80, 120);
// ExposureGain autoExposure autoGain ExposureTime AutoExposureMin AutoExposureMax Gain(<=16) AutoGainMin AutoGainMax GrayValue
camera.setExposureGainParam( false, true, 5500, 1000, 2000, 16, 15, 16, 127);
// WhiteBalance Applied? light source type
camera.setWhiteBalanceParam( true, GX_AWB_LAMP_HOUSE_ADAPTIVE);
// Acquisition Start!
camera.acquisitionStart(&srcFrame);
}
void* detectingThread(void* PARAM)
{
char chKey;
bool bRun = true;
int s_type = 1;
Stone stone;
do
{
double t;
double fps;
t = (double)cv::getTickCount();
Mat myFrame;
//consumer gets image
pthread_mutex_lock(&Globalmutex);
while (!imageReadable) {
pthread_cond_wait(&GlobalCondCV,&Globalmutex);
}
if(newFrame)
srcFrame.copyTo(myFrame);
imageReadable = false;
pthread_mutex_unlock(&Globalmutex);
stone.detect_stone(myFrame,s_type);//检测入口
// from here you can use mat image as the name 'myFrame'
//imshow("Frame",myFrame);
t = ((double)cv::getTickCount() - t) / cv::getTickFrequency();
fps = 1.0 / t;
cv::Mat dst = cv::Mat::zeros(myFrame.size(),myFrame.type());
cv::putText(dst, "FPS : " + stone.converttostring(fps), cv::Point(myFrame.rows / 6, myFrame.cols / 6), 3, 1, cv::Scalar(0, 255, 255));
cv::imshow("fps",dst);
chKey = waitKey(1);//手动切换识别模式
switch (chKey) {
case 'w':
s_type = 1;
break;
case 'y':
s_type = 0;
break;
case 27:
bRun = false;
break;
default:
break;
}
cout << "fps = " << fps << endl;
} while (bRun);
}