@@ -144,32 +144,7 @@ void ImageScheduler::decodeGrayPixels(const Mat &gray) {
144144
145145 if (result.isValid ()) {
146146 javaCallHelper->onResult (result);
147- }
148- // else if (result.isNeedScale()) {
149- // LOGE("is need scale image...");
150- // std::vector<ResultPoint> points = result.resultPoints();
151- // ResultPoint topLeft = points[1];
152- // ResultPoint topRight = points[2];
153- // ResultPoint bottomLeft = points[0];
154- //
155- // int left = static_cast<int>(topLeft.x()) - 3 * 20;
156- // int top = static_cast<int>(topLeft.y()) - 3 * 20;
157- // int width = static_cast<int>(topRight.x() - topLeft.x()) + 3 * 25;
158- // int height = static_cast<int>(bottomLeft.y() - topLeft.y()) + 3 * 25;
159- //
160- // LOGE("left = %d, top = %d, width = %d, height = %d", left, top, width, height);
161- //
162- // mat = mat(Rect(left, top, width, height));
163- // imwrite("/storage/emulated/0/scan/scale.jpg", mat);
164- // Result result1 = decodePixels(mat);
165- //
166- // if (result.isValid()) {
167- // javaCallHelper->onResult(result);
168- // } else {
169- // decodeThresholdPixels(gray);
170- // }
171- // }
172- else {
147+ }else {
173148 decodeThresholdPixels (gray);
174149 }
175150}
@@ -225,7 +200,6 @@ void ImageScheduler::decodeZBar(const Mat &gray) {
225200 Image image (width, height, " Y800" , raw, width * height);
226201 int n = zbarScanner->scan (image);
227202
228- // extract results
229203 if (n > 0 ) {
230204 Image::SymbolIterator symbol = image.symbol_begin ();
231205 LOGE (" zbar Code Data = %s" , symbol->get_data ().c_str ());
@@ -267,7 +241,6 @@ void ImageScheduler::recognizerQrCode(const Mat &mat) {
267241 javaCallHelper->onResult (result);
268242
269243 LOGE (" end recognizerQrCode..." );
270-
271244}
272245
273246Result ImageScheduler::decodePixels (const Mat &mat) {
@@ -308,47 +281,36 @@ Result *ImageScheduler::analyzeResult() {
308281 return result;
309282}
310283
311- void ImageScheduler::decodeZBar (const jobject &gray) {
312- // auto width = static_cast<unsigned int>(gray.cols);
313- // auto height = static_cast<unsigned int>(gray.rows);
314- //
315- // const void *raw = gray.data;
316- // Image image(width, height, "Y800", raw, width * height);
317- // ImageScanner scanner;
318- // int n = scanner.scan(image);
319- //
320- // // extract results
321- // if (image.symbol_begin() == image.symbol_end()) {
322- // image.set_data(nullptr, 0);
323- // recognizerQrCode(gray);
324- // return;
325- // }
326- //
327- // Image::SymbolIterator symbol = image.symbol_begin();
328- // for (; symbol != image.symbol_end(); ++symbol) {
329- // LOGE("zbar Code Type = %s , Data = %s", symbol->get_type_name().c_str(),
330- // symbol->get_data().c_str());
331- //
332- // if (symbol->get_type() == zbar_symbol_type_e::ZBAR_QRCODE){
333- // Result result(DecodeStatus::NoError);
334- // result.setFormat(BarcodeFormat::QR_CODE);
335- // result.setText(ANSIToUnicode(symbol->get_data()));
336- // javaCallHelper->onResult(result);
337- // }
338- // }
339- // image.set_data(nullptr, 0);
340- }
341-
342284Result ImageScheduler::readBitmap (jobject bitmap, int left, int top, int width, int height) {
285+
286+ Mat src;
287+ BitmapToMat (env, bitmap, src);
288+
289+ Mat gray;
290+ cvtColor (src, gray, COLOR_RGB2GRAY );
291+
292+ const void *raw = gray.data ;
293+ Image image (gray.cols , gray.rows , " Y800" , raw, gray.cols * gray.rows );
294+ if (zbarScanner->scan (image) > 0 ) {
295+ Image::SymbolIterator symbol = image.symbol_begin ();
296+ LOGE (" zbar Code Data = %s" , symbol->get_data ().c_str ());
297+ if (symbol->get_type () == zbar_symbol_type_e::ZBAR_QRCODE ) {
298+ Result resultBar (DecodeStatus::NoError);
299+ resultBar.setFormat (BarcodeFormat::QR_CODE );
300+ resultBar.setText (ANSIToUnicode (symbol->get_data ()));
301+ image.set_data (nullptr , 0 );
302+ return resultBar;
303+ }
304+ } else {
305+ image.set_data (nullptr , 0 );
306+ }
307+
343308 auto binImage = BinaryBitmapFromJavaBitmap (env, bitmap, left, top, width, height);
344309 if (!binImage) {
345310 LOGE (" create binary bitmap fail" );
346311 return Result (DecodeStatus::NotFound);
347312 }
348- // Result result = reader->read(*binImage);
349- // if (!result.isValid()){
350- //
351- // }
313+
352314 return reader->read (*binImage);
353315}
354316
0 commit comments