ACMX 2.139.0
Dual-Backend Real-Time GPU Video Synthesis
Loading...
Searching...
No Matches
dnn.hpp
Go to the documentation of this file.
1#ifndef ACMX2_DNN_HPP
2#define ACMX2_DNN_HPP
3
4#include <memory>
5#include <string>
6#include <string_view>
7
8#include <opencv2/core/mat.hpp>
9#include <opencv2/dnn/dnn.hpp>
10#ifdef ACMX2_WITH_CUDA
11#include <opencv2/core/cuda.hpp>
12#endif
13
14namespace ac_dnn {
15
16 /// Generic ONNX image-to-image wrapper configured by a YAML file.
18 public:
19 explicit OnnxWrapper(std::string_view yamlPath);
21
22 OnnxWrapper(const OnnxWrapper &) = delete;
23 OnnxWrapper &operator=(const OnnxWrapper &) = delete;
24
25 void proc(const cv::Mat &image, cv::Mat &output);
26#ifdef ACMX2_WITH_CUDA
27 /// Postprocess directly into CUDA RGBA memory for OpenGL interop.
28 /// Returns false when the output shape is unsupported or the CUDA
29 /// postprocessing path is unavailable, allowing the caller to use
30 /// proc() as a portable fallback.
31 bool procGpu(const cv::Mat &image, cv::cuda::GpuMat &output);
32#endif
33
34 private:
35 struct Impl;
36 std::unique_ptr<Impl> impl;
37 };
38
39 /// DexiNed edge detector.
40 class Dexined {
41 public:
42 explicit Dexined(const std::string &modelPath);
44
45 Dexined(const Dexined &) = delete;
46 Dexined &operator=(const Dexined &) = delete;
47
48 void processFrame(const cv::Mat &image, cv::Mat &result);
49
50 private:
51 struct Impl;
52 std::unique_ptr<Impl> impl;
53 };
54
55 /// PP-HumanSeg foreground segmentation model.
56 class PPHS {
57 public:
58 // Passing -1/-1 enables the one-time automatic CPU/CUDA benchmark.
59 explicit PPHS(const std::string &modelPath, int backendId = -1, int targetId = -1);
61
62 PPHS(const PPHS &) = delete;
63 PPHS &operator=(const PPHS &) = delete;
64
65 cv::Mat preprocess(const cv::Mat &image);
66 cv::Mat infer(const cv::Mat &image);
67 cv::Mat postprocess(const cv::Mat &outputBlob);
68
69 private:
70 struct Impl;
71 std::unique_ptr<Impl> impl;
72 };
73
74 cv::Mat isolateBody(const cv::Mat &image, const cv::Mat &mask, float blackPoint = 0.35f, float whitePoint = 0.75f);
75 cv::Mat hardenedAlphaMask(const cv::Mat &image, const cv::Mat &mask, float blackPoint = 0.35f, float whitePoint = 0.75f);
76
77} // namespace ac_dnn
78
79#endif // ACMX2_DNN_HPP
std::unique_ptr< Impl > impl
Definition dnn.hpp:52
Dexined(const std::string &modelPath)
Definition dnn.cpp:524
Dexined(const Dexined &)=delete
void processFrame(const cv::Mat &image, cv::Mat &result)
Definition dnn.cpp:528
Dexined & operator=(const Dexined &)=delete
std::unique_ptr< Impl > impl
Definition dnn.hpp:36
OnnxWrapper & operator=(const OnnxWrapper &)=delete
OnnxWrapper(const OnnxWrapper &)=delete
OnnxWrapper(std::string_view yamlPath)
Definition dnn.cpp:474
void proc(const cv::Mat &image, cv::Mat &output)
Definition dnn.cpp:478
PPHS(const std::string &modelPath, int backendId=-1, int targetId=-1)
Definition dnn.cpp:592
cv::Mat postprocess(const cv::Mat &outputBlob)
Definition dnn.cpp:606
cv::Mat infer(const cv::Mat &image)
Definition dnn.cpp:598
std::unique_ptr< Impl > impl
Definition dnn.hpp:71
PPHS & operator=(const PPHS &)=delete
cv::Mat preprocess(const cv::Mat &image)
Definition dnn.cpp:596
PPHS(const PPHS &)=delete
Definition dnn.cpp:25
cv::Mat hardenedAlphaMask(const cv::Mat &image, const cv::Mat &mask, float blackPoint, float whitePoint)
Definition dnn.cpp:690
cv::Mat isolateBody(const cv::Mat &image, const cv::Mat &mask, float blackPoint, float whitePoint)
Definition dnn.cpp:698