@@ -33,6 +33,7 @@ ImageScheduler::~ImageScheduler() {
3333 delete &stopProcessing;
3434 delete &cameraLight;
3535 delete &prepareThread;
36+ scanIndex = 0 ;
3637}
3738
3839void *prepareMethod (void *arg) {
@@ -49,6 +50,7 @@ void ImageScheduler::start() {
4950 stopProcessing.store (false );
5051 isProcessing.store (false );
5152 frameQueue.setWork (1 );
53+ scanIndex = 0 ;
5254
5355 while (true ) {
5456 if (stopProcessing.load ()) {
@@ -74,6 +76,7 @@ void ImageScheduler::stop() {
7476 stopProcessing.store (true );
7577 frameQueue.setWork (0 );
7678 frameQueue.clear ();
79+ scanIndex = 0 ;
7780}
7881
7982void
@@ -109,7 +112,8 @@ ImageScheduler::process(jbyte *bytes, int left, int top, int cropWidth, int crop
109112 */
110113void ImageScheduler::preTreatMat (const FrameData &frameData) {
111114 try {
112- LOGE (" start preTreatMat..." );
115+ scanIndex++;
116+ LOGE (" start preTreatMat..., scanIndex = %d" , scanIndex);
113117
114118 Mat src (frameData.rowHeight + frameData.rowHeight / 2 ,
115119 frameData.rowWidth , CV_8UC1 ,
@@ -128,7 +132,12 @@ void ImageScheduler::preTreatMat(const FrameData &frameData) {
128132 if (cameraLight < 40 ) {
129133 return ;
130134 }
131- decodeGrayPixels (gray);
135+
136+ if (scanIndex % 2 == 0 ) {
137+ decodeGrayPixels (gray);
138+ } else {
139+ decodeZBar (gray);
140+ }
132141 } catch (const std::exception &e) {
133142 LOGE (" preTreatMat error..." );
134143 }
@@ -144,11 +153,38 @@ void ImageScheduler::decodeGrayPixels(const Mat &gray) {
144153
145154 if (result.isValid ()) {
146155 javaCallHelper->onResult (result);
147- }else {
156+ LOGE (" ZXing GrayPixels Success, scanIndex = %d" , scanIndex);
157+ } else {
148158 decodeThresholdPixels (gray);
149159 }
150160}
151161
162+ void ImageScheduler::decodeZBar (const Mat &gray) {
163+ auto width = static_cast <unsigned int >(gray.cols );
164+ auto height = static_cast <unsigned int >(gray.rows );
165+
166+ const void *raw = gray.data ;
167+ Image image (width, height, " Y800" , raw, width * height);
168+ int n = zbarScanner->scan (image);
169+
170+ if (n > 0 ) {
171+ Image::SymbolIterator symbol = image.symbol_begin ();
172+ LOGE (" zbar GrayPixels Success Data = %s scanIndex = %d" , symbol->get_data ().c_str (),
173+ scanIndex);
174+
175+ if (symbol->get_type () == zbar_symbol_type_e::ZBAR_QRCODE ) {
176+ Result result (DecodeStatus::NoError);
177+ result.setFormat (BarcodeFormat::QR_CODE );
178+ result.setText (ANSIToUnicode (symbol->get_data ()));
179+ javaCallHelper->onResult (result);
180+ image.set_data (nullptr , 0 );
181+ }
182+ } else {
183+ image.set_data (nullptr , 0 );
184+ decodeAdaptivePixels (gray);
185+ }
186+ }
187+
152188void ImageScheduler::decodeThresholdPixels (const Mat &gray) {
153189 LOGE (" start ThresholdPixels..." );
154190
@@ -164,13 +200,17 @@ void ImageScheduler::decodeThresholdPixels(const Mat &gray) {
164200
165201 Result result = decodePixels (mat);
166202 if (result.isValid ()) {
203+ LOGE (" ZXing Threshold Success, scanIndex = %d" , scanIndex);
167204 javaCallHelper->onResult (result);
168205 } else {
169- decodeAdaptivePixels (gray);
206+ recognizerQrCode (gray);
170207 }
171208}
172209
173210void ImageScheduler::decodeAdaptivePixels (const Mat &gray) {
211+ if (scanIndex % 3 != 0 ) {
212+ return ;
213+ }
174214 LOGE (" start AdaptivePixels..." );
175215
176216 Mat mat;
@@ -185,39 +225,22 @@ void ImageScheduler::decodeAdaptivePixels(const Mat &gray) {
185225
186226 Result result = decodePixels (lightMat);
187227 if (result.isValid ()) {
228+ LOGE (" ZXing Adaptive Success, scanIndex = %d" , scanIndex);
188229 javaCallHelper->onResult (result);
189230 } else {
190- decodeZBar (gray);
191- // recognizerQrCode(gray);
192- }
193- }
194-
195- void ImageScheduler::decodeZBar (const Mat &gray) {
196- auto width = static_cast <unsigned int >(gray.cols );
197- auto height = static_cast <unsigned int >(gray.rows );
198-
199- const void *raw = gray.data ;
200- Image image (width, height, " Y800" , raw, width * height);
201- int n = zbarScanner->scan (image);
202-
203- if (n > 0 ) {
204- Image::SymbolIterator symbol = image.symbol_begin ();
205- LOGE (" zbar Code Data = %s" , symbol->get_data ().c_str ());
206-
207- if (symbol->get_type () == zbar_symbol_type_e::ZBAR_QRCODE ) {
208- Result result (DecodeStatus::NoError);
209- result.setFormat (BarcodeFormat::QR_CODE );
210- result.setText (ANSIToUnicode (symbol->get_data ()));
211- javaCallHelper->onResult (result);
212- image.set_data (nullptr , 0 );
213- }
214- } else {
215- image.set_data (nullptr , 0 );
216231 recognizerQrCode (gray);
217232 }
218233}
219234
220235void ImageScheduler::recognizerQrCode (const Mat &mat) {
236+ if (scanIndex % 7 == 0 ) {
237+ javaCallHelper->onFocus ();
238+ return ;
239+ }
240+
241+ if (scanIndex % 3 != 0 ) {
242+ return ;
243+ }
221244 LOGE (" start recognizerQrCode..." );
222245
223246 cv::Rect rect;
@@ -240,7 +263,7 @@ void ImageScheduler::recognizerQrCode(const Mat &mat) {
240263
241264 javaCallHelper->onResult (result);
242265
243- LOGE (" end recognizerQrCode..." );
266+ LOGE (" end recognizerQrCode..., scanIndex = %d " , scanIndex );
244267}
245268
246269Result ImageScheduler::decodePixels (const Mat &mat) {
0 commit comments