77#include < src/BinaryBitmap.h>
88#include " ImageScheduler.h"
99#include " JNIUtils.h"
10- #include < thread>
11- #include < chrono>
1210
1311#define DEFAULT_MIN_LIGHT 70 ;
1412
@@ -40,12 +38,7 @@ void *prepareMethod(void *arg) {
4038 return nullptr ;
4139}
4240
43- void releaseFrameData (FrameData &frameData) {
44- delete &frameData;
45- }
46-
4741void ImageScheduler::prepare () {
48- frameQueue.setReleaseHandle (releaseFrameData);
4942 pthread_create (&prepareThread, nullptr , prepareMethod, this );
5043}
5144
@@ -60,7 +53,6 @@ void ImageScheduler::start() {
6053 }
6154
6255 if (isProcessing.load ()) {
63- std::this_thread::sleep_for (chrono::milliseconds (100 ));
6456 continue ;
6557 }
6658
@@ -113,29 +105,30 @@ ImageScheduler::process(jbyte *bytes, int left, int top, int cropWidth, int crop
113105 * 预处理二进制数据
114106 */
115107void ImageScheduler::preTreatMat (const FrameData &frameData) {
116- if (&frameData == nullptr ) {
117- return ;
118- }
119-
120- LOGE (" start preTreatMat..." );
108+ try {
109+ LOGE (" start preTreatMat..." );
121110
122- Mat src (frameData.rowHeight + frameData.rowHeight / 2 ,
123- frameData.rowWidth , CV_8UC1 ,
124- frameData.bytes );
111+ Mat src (frameData.rowHeight + frameData.rowHeight / 2 ,
112+ frameData.rowWidth , CV_8UC1 ,
113+ frameData.bytes );
125114
126- Mat gray;
127- cvtColor (src, gray, COLOR_YUV2GRAY_NV21 );
115+ Mat gray;
116+ cvtColor (src, gray, COLOR_YUV2GRAY_NV21 );
128117
129- if (frameData.left != 0 ) {
130- gray = gray (Rect (frameData.left , frameData.top , frameData.cropWidth , frameData.cropHeight ));
131- }
118+ if (frameData.left != 0 ) {
119+ gray = gray (
120+ Rect (frameData.left , frameData.top , frameData.cropWidth , frameData.cropHeight ));
121+ }
132122
133- // 分析亮度,如果亮度过低,不进行处理
134- analysisBrightness (gray);
135- if (cameraLight < 40 ) {
136- return ;
123+ // 分析亮度,如果亮度过低,不进行处理
124+ analysisBrightness (gray);
125+ if (cameraLight < 40 ) {
126+ return ;
127+ }
128+ decodeGrayPixels (gray);
129+ } catch (const std::exception &e) {
130+ LOGE (" preTreatMat error..." );
137131 }
138- decodeGrayPixels (gray);
139132}
140133
141134void ImageScheduler::decodeGrayPixels (const Mat &gray) {
@@ -280,7 +273,7 @@ Result ImageScheduler::decodePixels(Mat mat) {
280273 return Result (DecodeStatus::NotFound);
281274}
282275
283- bool ImageScheduler::analysisBrightness (const Mat& gray) {
276+ bool ImageScheduler::analysisBrightness (const Mat & gray) {
284277 LOGE (" start analysisBrightness..." );
285278
286279 // 平均亮度
0 commit comments