MCPcopy Create free account
hub / github.com/MaaXYZ/MaaFramework / predict_batch_rec

Method predict_batch_rec

source/MaaFramework/Vision/OCRer.cpp:250–297  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

248}
249
250OCRer::ResultsVec OCRer::predict_batch_rec(const std::vector<cv::Rect>& rois) const
251{
252 LogFunc << VAR(rois);
253
254 if (!recer_) {
255 LogError << "recer_ is null";
256 return { };
257 }
258 if (rois.empty()) {
259 LogError << "rois is empty";
260 return { };
261 }
262
263 std::vector<cv::Mat> imgs;
264 for (const cv::Rect& r : rois) {
265 imgs.emplace_back(image_(r));
266 }
267
268 fastdeploy::vision::OCRResult ocr_result;
269
270 bool ret = false;
271 {
272 std::unique_lock lock(s_predict_mutex_);
273 ret = recer_->BatchPredict(imgs, &ocr_result);
274 }
275 if (!ret) {
276 LogWarn << "recer_ BatchPredict return false" << VAR(recer_) << VAR(rois) << VAR(imgs);
277 return { };
278 }
279 if (ocr_result.text.size() != rois.size() || ocr_result.rec_scores.size() != rois.size()) {
280 LogError << "Bad ocr result size" << VAR(rois) << VAR(ocr_result.boxes) << VAR(ocr_result.text) << VAR(ocr_result.rec_scores);
281 return { };
282 }
283
284 ResultsVec results;
285
286 for (size_t i = 0; i != ocr_result.text.size(); ++i) {
287 auto text = to_u16(ocr_result.text.at(i));
288 cv::Rect my_box = rois.at(i);
289 auto score = ocr_result.rec_scores.at(i);
290
291 results.emplace_back(Result { .text = std::move(text), .box = my_box, .score = score });
292 }
293
294 LogInfo << VAR(results);
295
296 return results;
297}
298
299cv::Mat OCRer::draw_result(const ResultsVec& results) const
300{

Callers

nothing calls this directly

Calls 4

moveFunction · 0.85
atMethod · 0.80
emptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected