mmdeploy/tests/test_csrc/capi/test_detector.cpp
lzhangzz a494a6f6ff
[SDK] sync changes according to performance benchmarks (#297)
* sync SDK changes according to performance benchmarks

* fix end-of-file lint

* fix clang-format issue

* fix clang-format by adding 'clang-format off'

* remove useless casts

* remove 'data' argument of 'operator()'

* change 'Tensor2Img' to 'TensorToImg' according to spec

* correct tensor's name according spec

Co-authored-by: lvhan028 <lvhan_028@163.com>
2021-12-16 13:51:22 +08:00

41 lines
1.4 KiB
C++

// Copyright (c) OpenMMLab. All rights reserved.
// clang-format off
#include "catch.hpp"
// clang-format on
#include <iostream>
#include "apis/c/detector.h"
#include "opencv2/opencv.hpp"
using namespace std;
TEST_CASE("test detector's c api", "[detector]") {
mm_handle_t handle{nullptr};
auto model_path = "../../config/detector/retinanet_t4-cuda11.1-trt7.2-fp32";
auto ret = mmdeploy_detector_create_by_path(model_path, "cuda", 0, &handle);
REQUIRE(ret == MM_SUCCESS);
cv::Mat mat = cv::imread("../../tests/data/images/dogs.jpg");
vector<mm_mat_t> mats{{mat.data, mat.rows, mat.cols, mat.channels(), MM_BGR, MM_INT8}};
mm_detect_t* results{nullptr};
int* result_count{nullptr};
ret = mmdeploy_detector_apply(handle, mats.data(), (int)mats.size(), &results, &result_count);
REQUIRE(ret == MM_SUCCESS);
auto result_ptr = results;
for (auto i = 0; i < mats.size(); ++i) {
cout << "the " << i << "-th image has '" << result_count[i] << "' objects" << endl;
for (auto j = 0; j < result_count[i]; ++j, ++result_ptr) {
auto& bbox = result_ptr->bbox;
cout << " >> bbox[" << bbox.left << ", " << bbox.top << ", " << bbox.right << ", "
<< bbox.bottom << "], label_id " << result_ptr->label_id << ", score "
<< result_ptr->score << endl;
}
}
mmdeploy_detector_release_result(results, result_count, (int)mats.size());
mmdeploy_detector_destroy(handle);
}