@@ -25,25 +25,44 @@ ImageScheduler::~ImageScheduler() {
2525 delete &frameData;
2626 delete &isProcessing;
2727 delete &cameraLight;
28- delete &pretreatmentThread ;
28+ delete &prepareThread ;
2929}
3030
31- void *pretreatmentMethod (void *arg) {
31+ void *prepareMethod (void *arg) {
3232 auto scheduler = static_cast <ImageScheduler *>(arg);
33- scheduler->readyMat ();
33+ scheduler->start ();
3434 return nullptr ;
3535}
3636
37+ void ImageScheduler::prepare () {
38+ pthread_create (&prepareThread, nullptr , prepareMethod, this );
39+ }
40+
41+ void ImageScheduler::start () {
42+ stopProcessing = false ;
43+
44+ while (true ) {
45+ if (stopProcessing) {
46+ break ;
47+ }
48+ if (isProcessing) {
49+ continue ;
50+ }
51+ preTreatMat ();
52+ }
53+ }
54+
55+ void ImageScheduler::stop () {
56+ stopProcessing = true ;
57+ }
58+
3759void
3860ImageScheduler::process (jbyte *bytes, int left, int top, int cropWidth, int cropHeight,
3961 int rowWidth,
4062 int rowHeight) {
4163 if (isProcessing) {
4264 return ;
4365 }
44- isProcessing = true ;
45-
46- // LOGE("process begin...");
4766
4867 frameData.bytes = bytes;
4968 frameData.left = left;
@@ -60,16 +79,32 @@ ImageScheduler::process(jbyte *bytes, int left, int top, int cropWidth, int crop
6079 frameData.rowWidth = rowWidth;
6180 frameData.rowHeight = rowHeight;
6281
63- pthread_create (&pretreatmentThread, nullptr , pretreatmentMethod, this );
6482}
6583
66- void ImageScheduler::readyMat () {
84+ /* *
85+ * 预处理二进制数据
86+ */
87+ void ImageScheduler::preTreatMat () {
88+ if (isProcessing) {
89+ return ;
90+ }
91+ isProcessing = true ;
92+
93+ if (frameData.bytes == nullptr ) {
94+ isProcessing = false ;
95+ return ;
96+ }
97+
6798 // 分析亮度,如果亮度过低,不进行处理
99+ LOGE (" 111111111111111" );
68100 analysisBrightness (frameData);
101+ LOGE (" 222222222222222" );
102+
69103 if (cameraLight < 150 ) {
70104 isProcessing = false ;
71105 return ;
72106 }
107+ LOGE (" 33333333333333333" );
73108
74109 Mat src (frameData.rowHeight + frameData.rowHeight / 2 ,
75110 frameData.rowWidth , CV_8UC1 ,
@@ -84,11 +119,11 @@ void ImageScheduler::readyMat() {
84119 Mat gray;
85120 cvtColor (src, gray, COLOR_RGBA2GRAY );
86121
87- // LOGE("start decode...");
122+ LOGE (" start decode..." );
88123 decodeGrayPixels (gray);
89124}
90125
91- void ImageScheduler::decodeGrayPixels (const Mat& gray) {
126+ void ImageScheduler::decodeGrayPixels (const Mat & gray) {
92127 Mat mat;
93128 rotate (gray, mat, ROTATE_90_CLOCKWISE );
94129
@@ -128,7 +163,7 @@ void ImageScheduler::decodeGrayPixels(const Mat& gray) {
128163 }
129164}
130165
131- void ImageScheduler::decodeThresholdPixels (const Mat& gray) {
166+ void ImageScheduler::decodeThresholdPixels (const Mat & gray) {
132167 Mat mat;
133168 rotate (gray, mat, ROTATE_180 );
134169
@@ -148,7 +183,7 @@ void ImageScheduler::decodeThresholdPixels(const Mat& gray) {
148183 }
149184}
150185
151- void ImageScheduler::decodeAdaptivePixels (const Mat& gray) {
186+ void ImageScheduler::decodeAdaptivePixels (const Mat & gray) {
152187 Mat mat;
153188 rotate (gray, mat, ROTATE_90_COUNTERCLOCKWISE );
154189
@@ -168,7 +203,7 @@ void ImageScheduler::decodeAdaptivePixels(const Mat& gray) {
168203 }
169204}
170205
171- void ImageScheduler::recognizerQrCode (const Mat& mat) {
206+ void ImageScheduler::recognizerQrCode (const Mat & mat) {
172207 cv::Rect rect;
173208 qrCodeRecognizer->processData (mat, &rect);
174209 if (rect.empty ()) {
@@ -271,3 +306,4 @@ Result ImageScheduler::readBitmap(jobject bitmap, int left, int top, int width,
271306 }
272307 return reader->read (*binImage);
273308}
309+
0 commit comments