Skip to content
Open

Deploee #1965

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions csrc/mmdeploy/operation/cuda/cvtcolor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,20 @@ class CvtColorImpl : public CvtColor {

auto height = src.height();
auto width = src.width();
auto channels = src.channel();
auto stride = width * channels;
auto src_channels = src.channel();
auto src_stride = width * src_channels;

Mat dst_mat(height, width, dst_fmt, src.type(), device());
auto dst_stride = width * dst_mat.channel();

auto convert = [&](auto type) -> Result<void> {
using T = typename decltype(type)::type;
auto converter = GetConverter<T>(src.pixel_format(), dst_fmt);
if (!converter) {
return Status(eNotSupported);
}
auto ret =
converter(cuda_stream, height, width, stride, src.data<T>(), stride, dst_mat.data<T>());
auto ret = converter(cuda_stream, height, width, src_stride, src.data<T>(), dst_stride,
dst_mat.data<T>());
if (ret != ppl::common::RC_SUCCESS) {
return Status(eFail);
}
Expand Down
2 changes: 1 addition & 1 deletion csrc/mmdeploy/preprocess/transform/load.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class PrepareImage : public Transform {
if (color_type_ == "color" || color_type_ == "color_ignore_orientation") {
OUTCOME_TRY(cvt_color_.Apply(src_mat, dst_mat, PixelFormat::kBGR));
} else {
OUTCOME_TRY(cvt_color_.Apply(dst_mat, dst_mat, PixelFormat::kGRAYSCALE));
OUTCOME_TRY(cvt_color_.Apply(src_mat, dst_mat, PixelFormat::kGRAYSCALE));
}
auto tensor = to_tensor(dst_mat);
if (to_float32_) {
Expand Down
2 changes: 2 additions & 0 deletions demo/csrc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ if (MMDEPLOY_BUILD_SDK_CXX_API)
add_example(restorer cpp restorer)
add_example(text_detector cpp text_ocr)
add_example(text_detector cpp text_det_recog)
add_example(text_detector cpp text_det)
add_example(text_recognizer cpp text_recog)
add_example(pose_detector cpp pose_detector)
add_example(rotated_detector cpp rotated_detector)
add_example(pose_detector cpp pose_tracker)
Expand Down
47 changes: 47 additions & 0 deletions demo/csrc/cpp/text_det.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

#include <opencv2/imgcodecs/imgcodecs.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <string>

#include "mmdeploy/common.hpp"
#include "mmdeploy/text_detector.hpp"

int main(int argc, char* argv[]) {
if (argc != 4) {
fprintf(stderr, "usage:\n text_det 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;
}

mmdeploy::Profiler profiler{"/tmp/profile.bin"};
mmdeploy::Context context(mmdeploy::Device(device_name, 0));
context.Add(profiler);

mmdeploy::Model model(model_path);
mmdeploy::TextDetector detector(model, context);

const int REPEAT = 20;
auto res = detector.Apply(img);
for (int i = 0; i < REPEAT - 1; ++i) {
res = detector.Apply(img);
}

for (const auto& det : res) {
const auto& box = det.bbox;
for (int i = 0; i < 4; i++) {
cv::rectangle(img, cv::Point{(int)box[i].x, (int)box[i].y},
cv::Point{(int)box[(i + 1) % 4].x, (int)box[(i + 1) % 4].y},
cv::Scalar{0, 255, 0});
}
}
cv::imwrite("output_ocr_detection.jpg", img);

return 0;
}
52 changes: 52 additions & 0 deletions demo/csrc/cpp/text_recog.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@

#include <opencv2/imgcodecs/imgcodecs.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <string>
#include <vector>

#include "mmdeploy/common.hpp"
#include "mmdeploy/text_detector.hpp"
#include "mmdeploy/text_recognizer.hpp"

int main(int argc, char* argv[]) {
if (argc != 4) {
fprintf(stderr, "usage:\n text_recog 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;
}

mmdeploy::TextDetection bbox = {{{0.f, (float)img.rows - 1},
{0.f, 0.f},
{(float)img.cols - 1, 0},
{(float)img.cols, (float)img.rows - 1}},
1.0f};
std::vector<mmdeploy::TextDetection> bboxes = {bbox};

mmdeploy::Profiler profiler{"/tmp/profile.bin"};
mmdeploy::Context context(mmdeploy::Device(device_name, 0));
context.Add(profiler);

mmdeploy::Model model(model_path);
mmdeploy::TextRecognizer recognizer(model, context);

const int REPEAT = 20;
auto res = recognizer.Apply(img, bboxes);
for (int i = 0; i < REPEAT - 1; ++i) {
res = recognizer.Apply(img);
}

for (auto& reg : res) {
for (int i = 0; i < reg.length; i++) {
printf("%c %f\n", reg.text[i], reg.score[i]);
}
}

return 0;
}