mmdeploy/demo/csrc/image_restorer.cpp
lvhan028 e10a1b7c9e
Add more demos (#305)
* add more examples

* change to restore's output image to BGR

* use BUILD_SHARED_LIBS

* update graph module's cmake

* add condition for spdlog package

* change cmakelists

* update cmakelists

* add device_name in each demo

* remove duplicate cmake function

* use palette to draw segmentation's result

* no need to find_package(pplnn) when use MMDeploy's static libs

* remove MMDeploy_LIBS' dependency on spdlog

* #include <opencv2/imgproc/imgproc.hpp>

* change from mmdeploy_core to mmdeploy::core
2021-12-21 21:32:39 +08:00

50 lines
1.3 KiB
C++

// Copyright (c) OpenMMLab. All rights reserved.
#include <fstream>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <string>
#include "restorer.h"
int main(int argc, char *argv[]) {
if (argc != 4) {
fprintf(stderr, "usage:\n image_restorer device_name model_path image_path\n");
return 1;
}
auto device_name = argv[1];
auto model_path = argv[2];
auto image_path = argv[3];
cv::Mat img = cv::imread(image_path);
if (!img.data) {
fprintf(stderr, "failed to load image: %s\n", image_path);
return 1;
}
mm_handle_t restorer{};
int status{};
status = mmdeploy_restorer_create_by_path(model_path, device_name, 0, &restorer);
if (status != MM_SUCCESS) {
fprintf(stderr, "failed to create restorer, code: %d\n", (int)status);
return 1;
}
mm_mat_t mat{img.data, img.rows, img.cols, 3, MM_BGR, MM_INT8};
mm_mat_t *result{};
status = mmdeploy_restorer_apply(restorer, &mat, 1, &result);
if (status != MM_SUCCESS) {
fprintf(stderr, "failed to apply restorer, code: %d\n", (int)status);
return 1;
}
cv::Mat sr_img(result->height, result->width, CV_8UC3, result->data);
cv::cvtColor(sr_img, sr_img, cv::COLOR_RGB2BGR);
cv::imwrite("output_restorer.bmp", sr_img);
mmdeploy_restorer_release_result(result, 1);
mmdeploy_restorer_destroy(restorer);
return 0;
}