@@ -190,14 +190,15 @@ Utility::GetRotateCropImage(const cv::Mat &srcimage,
190
190
}
191
191
}
192
192
193
- std::vector<int > Utility::argsort (const std::vector<float > &array) noexcept {
194
- std::vector<int > array_index (array.size (), 0 );
195
- for (int i = 0 ; i < array.size (); ++i)
193
+ std::vector<size_t > Utility::argsort (const std::vector<float > &array) noexcept {
194
+ std::vector<size_t > array_index (array.size (), 0 );
195
+ for (size_t i = 0 ; i < array.size (); ++i)
196
196
array_index[i] = i;
197
197
198
- std::sort (
199
- array_index.begin (), array_index.end (),
200
- [&array](int pos1, int pos2) { return (array[pos1] < array[pos2]); });
198
+ std::sort (array_index.begin (), array_index.end (),
199
+ [&array](size_t pos1, size_t pos2) {
200
+ return (array[pos1] < array[pos2]);
201
+ });
201
202
202
203
return array_index;
203
204
}
@@ -237,23 +238,23 @@ std::string Utility::basename(const std::string &filename) noexcept {
237
238
return filename.substr (index + 1 , len - index);
238
239
}
239
240
240
- bool Utility::PathExists (const std::string & path) noexcept {
241
+ bool Utility::PathExists (const char * path) noexcept {
241
242
#ifdef _WIN32
242
243
struct _stat buffer;
243
- return (_stat (path. c_str () , &buffer) == 0 );
244
+ return (_stat (path, &buffer) == 0 );
244
245
#else
245
246
struct stat buffer;
246
- return (stat (path. c_str () , &buffer) == 0 );
247
+ return (stat (path, &buffer) == 0 );
247
248
#endif // !_WIN32
248
249
}
249
250
250
- void Utility::CreateDir (const std::string & path) noexcept {
251
+ void Utility::CreateDir (const char * path) noexcept {
251
252
#ifdef _MSC_VER
252
- _mkdir (path. c_str () );
253
+ _mkdir (path);
253
254
#elif defined __MINGW32__
254
- mkdir (path. c_str () );
255
+ mkdir (path);
255
256
#else
256
- mkdir (path. c_str () , 0777 );
257
+ mkdir (path, 0777 );
257
258
#endif // !_WIN32
258
259
}
259
260
@@ -288,7 +289,7 @@ void Utility::print_result(
288
289
}
289
290
}
290
291
291
- cv::Mat Utility::crop_image (cv::Mat &img,
292
+ cv::Mat Utility::crop_image (const cv::Mat &img,
292
293
const std::vector<int > &box) noexcept {
293
294
cv::Mat crop_im = cv::Mat::zeros (box[3 ] - box[1 ], box[2 ] - box[0 ], 16 );
294
295
int crop_x1 = std::max (0 , box[0 ]);
@@ -305,14 +306,14 @@ cv::Mat Utility::crop_image(cv::Mat &img,
305
306
return crop_im;
306
307
}
307
308
308
- cv::Mat Utility::crop_image (cv::Mat &img,
309
+ cv::Mat Utility::crop_image (const cv::Mat &img,
309
310
const std::vector<float > &box) noexcept {
310
311
std::vector<int > box_int = {(int )box[0 ], (int )box[1 ], (int )box[2 ],
311
312
(int )box[3 ]};
312
313
return crop_image (img, box_int);
313
314
}
314
315
315
- void Utility::sorted_boxes (std::vector<OCRPredictResult> &ocr_result) noexcept {
316
+ void Utility::sort_boxes (std::vector<OCRPredictResult> &ocr_result) noexcept {
316
317
std::sort (ocr_result.begin (), ocr_result.end (), Utility::comparison_box);
317
318
if (ocr_result.size () > 1 ) {
318
319
for (size_t i = 0 ; i < ocr_result.size () - 1 ; ++i) {
@@ -367,7 +368,7 @@ float Utility::fast_exp(float x) noexcept {
367
368
}
368
369
369
370
std::vector<float >
370
- Utility::activation_function_softmax (std::vector<float > &src) noexcept {
371
+ Utility::activation_function_softmax (const std::vector<float > &src) noexcept {
371
372
size_t length = src.size ();
372
373
std::vector<float > dst;
373
374
dst.resize (length);
@@ -385,7 +386,8 @@ Utility::activation_function_softmax(std::vector<float> &src) noexcept {
385
386
return dst;
386
387
}
387
388
388
- float Utility::iou (std::vector<int > &box1, std::vector<int > &box2) noexcept {
389
+ float Utility::iou (const std::vector<int > &box1,
390
+ const std::vector<int > &box2) noexcept {
389
391
int area1 = std::max (0 , box1[2 ] - box1[0 ]) * std::max (0 , box1[3 ] - box1[1 ]);
390
392
int area2 = std::max (0 , box2[2 ] - box2[0 ]) * std::max (0 , box2[3 ] - box2[1 ]);
391
393
@@ -407,8 +409,8 @@ float Utility::iou(std::vector<int> &box1, std::vector<int> &box2) noexcept {
407
409
}
408
410
}
409
411
410
- float Utility::iou (std::vector<float > &box1,
411
- std::vector<float > &box2) noexcept {
412
+ float Utility::iou (const std::vector<float > &box1,
413
+ const std::vector<float > &box2) noexcept {
412
414
float area1 = std::max ((float )0.0 , box1[2 ] - box1[0 ]) *
413
415
std::max ((float )0.0 , box1[3 ] - box1[1 ]);
414
416
float area2 = std::max ((float )0.0 , box2[2 ] - box2[0 ]) *
0 commit comments