| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- #ifndef SP_IMAGE_H
- #define SP_IMAGE_H
- #include "core_v2/ndarray_helper.hpp"
- #include "core_v2/meta_helper.hpp"
- #include <opencv2/core/types.hpp>
- constexpr auto image_rank = 2;
- struct sp_image : ndarray_proxy<image_rank>,
- meta_proxy {
- std::type_index type = typeid(void);
- //@formatter:off
- using base_type = ndarray_proxy;
- base_type *array_base() { return this; }
- [[nodiscard]] cv::Size cv_size() const;
- [[nodiscard]] int cv_type() const;
- [[nodiscard]] cv::Mat cv_mat(void *ptr) const;
- [[nodiscard]] cv::cuda::GpuMat cv_gpu_mat(void *ptr) const;
- [[nodiscard]] sp_image sub_view(cv::Size size, cv::Size start = {}) const;
- //@formatter:on
- template<typename T>
- static sp_image create(const cv::Size size, const size_t align = 1) {
- return create_impl(size, align, typeid(T));
- }
- static sp_image create(const int cv_type, const cv::Size size, const size_t align = 1) {
- return create_impl(size, align, cv_type);
- }
- template<typename T>
- static sp_image create(const cv::Size size, const void *ptr) {
- return create_impl(size, ptr, typeid(T));
- }
- static sp_image create(const cv::Mat &mat);
- template<typename T>
- [[nodiscard]] sp_image cast_view() const {
- return cast_view_impl(typeid(T));
- }
- [[nodiscard]] sp_image cast_view(int cv_type) const;
- protected:
- //@formatter:off
- static sp_image create_impl(cv::Size size, size_t align, std::type_index type);
- static sp_image create_impl(cv::Size size, size_t align, int cv_type);
- static sp_image create_impl(cv::Size size, const void *ptr, std::type_index type);
- [[nodiscard]] sp_image cast_view_impl(std::type_index type) const;
- //@formatter:on
- };
- void copy_sp_image(const sp_image &src, sp_image &dst,
- cudaMemcpyKind kind = cudaMemcpyDefault);
- template<typename T>
- using image_ndarray = ndarray<T, image_rank>;
- #include "core/image_utility_v2.h"
- template<typename T>
- image_type_v2<T> to_cuda_v2(image_ndarray<T> img) {
- auto ret = image_type_v2<T>();
- ret.ptr = (T *) img.data;
- ret.width = img.width();
- ret.height = img.height();
- ret.pitch = img.pitch();
- return ret;
- }
- image_mem_info to_mem_v1(const sp_image &img, void *ptr,
- memory_location loc = MEM_CUDA);
- #endif //SP_IMAGE_H
|