| 1 |
/* |
| 2 |
* Copyright 2024 KylinSoft Co., Ltd. |
| 3 |
* |
| 4 |
* This program is free software: you can redistribute it and/or modify it under |
| 5 |
* the terms of the GNU General Public License as published by the Free Software |
| 6 |
* Foundation, either version 3 of the License, or (at your option) any later |
| 7 |
* version. |
| 8 |
* |
| 9 |
* This program is distributed in the hope that it will be useful, but WITHOUT |
| 10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 11 |
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
| 12 |
* details. |
| 13 |
* |
| 14 |
* You should have received a copy of the GNU General Public License along with |
| 15 |
* this program. If not, see <https://www.gnu.org/licenses/>. |
| 16 |
*/ |
| 17 |
#include "ondeviceengine.h" |
| 18 |
#include "../ondevicevisioncapabilityengine.h" |
| 19 |
#include <opencv2/opencv.hpp> |
| 20 |
#include "base64_transformer.h" |
| 21 |
#include <iostream> |
| 22 |
#include <chrono> |
| 23 |
#include <thread> |
| 24 |
void ocrPrintResult(const ai_engine::core_ai::vision::TextRecognitionResult &result) { |
| 25 |
printf("result.allText:%s\n",result.allText.c_str()); |
| 26 |
|
| 27 |
printf("-----printResult:result.lines.size():%ld\n",result.lines.size()); |
| 28 |
for(auto line : result.lines) { |
| 29 |
std::cout << line.text << std::endl; |
| 30 |
|
| 31 |
} |
| 32 |
} |
| 33 |
|
| 34 |
void mattingPrintResult(const ai_engine::core_ai::vision::ImageResult result) { |
| 35 |
base64_to_file(result.imageBase64Data, "../test_data/matting_out.png"); |
| 36 |
} |
| 37 |
|
| 38 |
|
| 39 |
void imgBinPrintResult(const ai_engine::core_ai::vision::ImageResult result) { |
| 40 |
base64_to_file(result.imageBase64Data, "../test_data/bin_out.png"); |
| 41 |
} |
| 42 |
|
| 43 |
int main(int argc, char **argv) { |
| 44 |
ai_engine::core_ai::vision::OndeviceVisionImageProcessEngine *vision_ImageProcess_ = new ai_engine::core_ai::vision::OndeviceVisionImageProcessEngine(); |
| 45 |
ai_engine::core_ai::vision::OndeviceVisionTextRecognitionEngine *vision_TextRecognition_ = new ai_engine::core_ai::vision::OndeviceVisionTextRecognitionEngine(); |
| 46 |
|
| 47 |
std::string img_path_ocr = "../test_data/ocr.jpg"; |
| 48 |
std::string img_path_matting = "../test_data/matting.jpeg"; |
| 49 |
std::string img_path_ddcp = "../test_data/ddcp.jpg"; |
| 50 |
std::string img_bin_ddcp = "../test_data/bin.jpg"; |
| 51 |
|
| 52 |
// ai_engine::EngineError error; |
| 53 |
ai_engine::result::AiEngineBaseResult res; |
| 54 |
res = vision_TextRecognition_->init(); |
| 55 |
res = vision_ImageProcess_->initMattingsModule(); |
| 56 |
vision_TextRecognition_->setTextRecognitionResultCallback(ocrPrintResult); |
| 57 |
vision_ImageProcess_->setMattingResultCallback(mattingPrintResult); |
| 58 |
|
| 59 |
vision_ImageProcess_->setImageBinaryResultCallback(imgBinPrintResult); |
| 60 |
std::string model_info = vision_TextRecognition_->modelInfo(); |
| 61 |
printf("vision_TextRecognition_:model_info:%s\n",model_info.c_str()); |
| 62 |
std::string model_info2 = vision_ImageProcess_->modelInfo(); |
| 63 |
printf("vision_ImageProcess_:model_info:%s\n",model_info2.c_str()); |
| 64 |
int index = 0; |
| 65 |
|
| 66 |
std::string image_data_ocr = file_to_base64(img_path_ocr); |
| 67 |
std::string image_data_matting = file_to_base64(img_path_matting); |
| 68 |
// std::string image_data_ddcp = file_to_base64(img_path_ddcp); |
| 69 |
std::string image_data_bin = file_to_base64(img_path_ddcp); |
| 70 |
ai_engine::EngineError error2; |
| 71 |
res = vision_TextRecognition_->recognizeTextFromBase64ImageData(image_data_ocr.c_str()); |
| 72 |
res = vision_ImageProcess_->mattingFromBase64ImageData(image_data_matting.c_str()); |
| 73 |
res = vision_ImageProcess_->binarizeImageFromBase64ImageData(image_data_bin.c_str()); |
| 74 |
} |