vendor: OpenCV 5.0.0 snapshot at 755e50675d97db9b7d449d8bd6b09888646f6c6e

This commit is contained in:
Gitea Mirror Bot
2026-08-22 00:11:13 +08:00
commit 12022378a3
3872 changed files with 2513409 additions and 0 deletions
@@ -0,0 +1,7 @@
#ifndef ASCENDC_KERNELS_H
#define ASCENDC_KERNELS_H
#include "../../ascendc_kernels/kernel_tiling_types.h"
#include "aclrtlaunch_threshold_opencv.h"
#endif //ASCENDC_KERNELS_H
+343
View File
@@ -0,0 +1,343 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
#ifndef OPENCV_CANNOPS_CANN_HPP
#define OPENCV_CANNOPS_CANN_HPP
#include "opencv2/core.hpp"
/**
@defgroup cannops Ascend-accelerated Computer Vision
@{
@defgroup canncore Core part
@{
@defgroup cann_struct Data Structures
@defgroup cann_init Initialization and Information
@}
@}
*/
namespace cv
{
namespace cann
{
class AscendStream;
//! @addtogroup cann_struct
//! @{
//===================================================================================
// AscendMat
//===================================================================================
/** @brief Base storage class for NPU memory with reference counting.
* AscendMat class has a similar interface with Mat and AscendMat, and work on [Ascend
* NPU](https://www.hiascend.com/) backend.
* @sa Mat cuda::GpuMat
*/
class AscendStream;
class CV_EXPORTS_W AscendMat
{
public:
class CV_EXPORTS_W Allocator
{
public:
virtual ~Allocator() {}
// basic allocator
virtual std::shared_ptr<uchar> allocate(size_t size) = 0;
// allocator must fill data, step and refcount fields
virtual bool allocate(AscendMat* mat, int rows, int cols, size_t elemSize) = 0;
};
/**
* @brief Create default allocator for AscendMat. This allocator alloc memory from device for
* specific size.
*/
CV_WRAP static AscendMat::Allocator* defaultAllocator();
/**
* @brief Set allocator for AscendMat.
* @param allocator
*/
CV_WRAP static void setDefaultAllocator(AscendMat::Allocator* allocator);
//! default constructor
CV_WRAP explicit AscendMat(AscendMat::Allocator* allocator_ = AscendMat::defaultAllocator());
//! constructs AscendMat of the specified size and type
CV_WRAP AscendMat(int rows, int cols, int type,
AscendMat::Allocator* allocator = AscendMat::defaultAllocator());
//! constructs AscendMat of the specified size and type
CV_WRAP AscendMat(Size size, int type,
AscendMat::Allocator* allocator = AscendMat::defaultAllocator());
//! constructs AscendMat and fills it with the specified value s
CV_WRAP AscendMat(int rows, int cols, int type, Scalar& s,
AscendMat::Allocator* allocator = AscendMat::defaultAllocator());
//! constructs AscendMat and fills it with the specified value s
CV_WRAP AscendMat(Size size, int type, Scalar& s,
AscendMat::Allocator* allocator = AscendMat::defaultAllocator());
//! copy constructor
CV_WRAP AscendMat(const AscendMat& m);
//! constructs AscendMat by crop a certain area from another
CV_WRAP AscendMat(InputArray _m, const Rect& roi);
CV_WRAP AscendMat(InputArray _m, const Rect& roi, AscendStream& stream);
//! builds AscendMat from host memory (Blocking call)
CV_WRAP explicit AscendMat(InputArray arr, AscendStream& stream,
AscendMat::Allocator* allocator = AscendMat::defaultAllocator());
//! assignment operators
AscendMat& operator=(const AscendMat& m);
//! sets some of the AscendMat elements to s (Blocking call)
CV_WRAP AscendMat& setTo(const Scalar& s);
//! sets some of the AscendMat elements to s (Non-Blocking call)
CV_WRAP AscendMat& setTo(const Scalar& s, AscendStream& stream);
//! sets all of the AscendMat elements to float (Blocking call)
CV_WRAP AscendMat& setTo(float sc);
//! sets all of the AscendMat elements to float (Non-Blocking call)
CV_WRAP AscendMat& setTo(float sc, AscendStream& stream);
//! swaps with other smart pointer
CV_WRAP void swap(AscendMat& mat);
//! allocates new AscendMat data unless the AscendMat already has specified size and type
CV_WRAP void create(int rows, int cols, int type);
//! upload host memory data to AscendMat (Blocking call)
CV_WRAP void upload(InputArray arr);
//! upload host memory data to AscendMat (Non-Blocking call)
CV_WRAP void upload(InputArray arr, AscendStream& stream);
//! download data from AscendMat to host (Blocking call)
CV_WRAP void download(OutputArray dst) const;
//! download data from AscendMat to host (Non-Blocking call)
CV_WRAP void download(OutputArray dst, AscendStream& stream) const;
//! converts AscendMat to another datatype (Blocking call)
CV_WRAP void convertTo(CV_OUT AscendMat& dst, int rtype) const;
//! converts AscendMat to another datatype (Non-Blocking call)
CV_WRAP void convertTo(CV_OUT AscendMat& dst, int rtype, AscendStream& stream) const;
//! converts AscendMat to another datatype, dst mat is allocated. (Non-Blocking call)
CV_WRAP void convertTo(CV_OUT AscendMat& dst, AscendStream& stream) const;
//! returns true iff the AscendMat data is continuous
//! (i.e. when there are no gaps between successive rows)
CV_WRAP bool isContinuous() const;
//! returns element size in bytes
CV_WRAP size_t elemSize() const;
//! returns the size of element channel in bytes
CV_WRAP size_t elemSize1() const;
//! returns element type
CV_WRAP int type() const;
//! returns element type
CV_WRAP int depth() const;
//! returns number of channels
CV_WRAP int channels() const;
//! returns step/elemSize1()
CV_WRAP size_t step1() const;
//! returns AscendMat size : width == number of columns, height == number of rows
CV_WRAP Size size() const;
//! returns true if AscendMat data is NULL
CV_WRAP bool empty() const;
//! internal use method: updates the continuity flag
CV_WRAP void updateContinuityFlag();
/*! includes several bit-fields:
- the magic signature
- continuity flag
- depth
- number of channels
*/
int flags;
//! the number of rows and columns
int rows, cols;
//! a distance between successive rows in bytes; includes the gap if any
CV_PROP size_t step;
//! pointer to the data
std::shared_ptr<uchar> data;
//! helper fields used in locateROI and adjustROI
uchar* datastart;
const uchar* dataend;
//! allocator
Allocator* allocator;
};
class AscendStream;
class AscendStreamAccessor;
class AscendEvent;
class AscendEventAccessor;
class DefaultDeviceInitializer;
//===================================================================================
// AscendStream
//===================================================================================
/** @brief In AscendCL Stream(AscendStream) is a task queue. Stream is used to manage the
* parallelism of tasks. The tasks inside a Stream are executed sequentially, that is, the Stream
* executes sequentially according to the sent tasks; the tasks in different Streams are executed in
* parallel.
*
* All Non-blocking functions should pass parameter stream, These function returns immediately after
* the task is submitted. Caller should wait stream until completion.
*
* Blocking functions implicityly use the default stream, and synchronize stream before function
* return.
* @sa cuda::Stream
*/
// TODO: Stream is defined in namespace cuda, and pybind code does not use a namespace of stream,
// change stream name to AscendStream to avoid confilct.
class CV_EXPORTS_W AscendStream
{
public:
CV_WRAP AscendStream();
//! blocks the current CPU thread until all operations in the stream are complete.
CV_WRAP void waitForCompletion();
//! blocks the current CPU thread until event trigger.
CV_WRAP void waitAscendEvent(const cv::cann::AscendEvent& event);
/**
* @brief return default AscendStream object for default Acl stream.
*/
CV_WRAP static AscendStream& Null();
// acl symbols CANNOT used in any hpp files. Use a inner class to avoid acl symbols defined in
// hpp.
class Impl;
void addTensorHolder(const std::shared_ptr<uchar>& holder);
private:
Ptr<Impl> impl_;
AscendStream(const Ptr<Impl>& impl);
friend class AscendStreamAccessor;
friend class DefaultDeviceInitializer;
};
/**
* @brief AscendEvent to synchronize between different streams.
*/
class CV_EXPORTS_W AscendEvent
{
public:
CV_WRAP AscendEvent();
//! records an event
CV_WRAP void record(AscendStream& stream);
//! waits for an event to complete
CV_WRAP void waitForComplete() const;
class Impl;
private:
Ptr<Impl> impl_;
AscendEvent(const Ptr<Impl>& impl);
friend class AscendEventAccessor;
};
/** @brief Bindings overload to create a Stream object from the address stored in an existing CANN
* Runtime API stream pointer (aclrtStream).
* @param AscendStreamAddress Memory address stored in a CANN Runtime API stream pointer
* (aclrtStream). The created Stream object does not perform any allocation or deallocation and
* simply wraps existing raw CANN Runtime API stream pointer.
* @note Overload for generation of bindings only, not exported or intended for use internally fro
* C++.
*/
CV_EXPORTS_W AscendStream wrapStream(size_t AscendStreamAddress);
//! @} cann_struct
//===================================================================================
// Initialization & Info
//===================================================================================
//! @addtogroup cann_init
//! @{
//! Get Ascend matrix object from Input array, upload matrix memory if need. (Non-Blocking call)
AscendMat getInputMat(InputArray src, AscendStream& stream);
//! Get Ascend matrix object from Output array, upload matrix memory if need.
AscendMat getOutputMat(OutputArray dst, int rows, int cols, int type, AscendStream& stream);
//! Sync output matrix to Output array, download matrix memory if need.
void syncOutput(const AscendMat& dst, OutputArray _dst, AscendStream& stream);
/**
* @brief Choose Ascend npu device.
*/
CV_EXPORTS_W void setDevice(int device);
/**
* @brief Clear all context created in current Ascend device.
*/
CV_EXPORTS_W void resetDevice();
/**
* @brief Get current Ascend device.
*/
CV_EXPORTS_W int32_t getDevice();
/**
* @brief init AscendCL.
*/
CV_EXPORTS_W void initAcl();
/**
* @brief finalize AscendCL.
* @note finalizeAcl only can be called once for a process. Call this function after all AscendCL
* options finished.
*/
CV_EXPORTS_W void finalizeAcl();
/**
* @brief init DVPP system.
* @note The DVPP interfaces used are all version V2.
* Supported devices: Atlas Inference Series products, Atlas 200/500 A2 Inference products and
* Atlas A2 Training Series products/Atlas 300I A2 Inference products
*/
CV_EXPORTS_W void initDvpp();
/**
* @brief finalize DVPP system.
* @note Supported devices: Atlas Inference Series products, Atlas 200/500 A2 Inference products and
* Atlas A2 Training Series products/Atlas 300I A2 Inference products
*/
CV_EXPORTS_W void finalizeDvpp();
//! @} cann_init
} // namespace cann
} // namespace cv
#include "opencv2/cann.inl.hpp"
#endif // OPENCV_CANNOPS_CANN_HPP
@@ -0,0 +1,97 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
#ifndef OPENCV_CANNOPS_CANN_INL_HPP
#define OPENCV_CANNOPS_CANN_INL_HPP
#include "opencv2/cann.hpp"
namespace cv
{
namespace cann
{
inline AscendMat::AscendMat(AscendMat::Allocator* allocator_)
: flags(0), rows(0), cols(0), step(0), datastart(0), dataend(0),
allocator(allocator_)
{
// Empty mat is also continuous.
flags |= Mat::CONTINUOUS_FLAG;
}
inline AscendMat::AscendMat(int rows_, int cols_, int type_, AscendMat::Allocator* allocator_)
: flags(0), rows(0), cols(0), step(0), datastart(0), dataend(0),
allocator(allocator_)
{
if (rows_ > 0 && cols_ > 0)
create(rows_, cols_, type_);
}
inline AscendMat::AscendMat(Size size_, int type_, AscendMat::Allocator* allocator_)
: flags(0), rows(0), cols(0), step(0), datastart(0), dataend(0),
allocator(allocator_)
{
if (size_.height > 0 && size_.width > 0)
create(size_.height, size_.width, type_);
}
inline AscendMat::AscendMat(InputArray arr, AscendStream& stream, AscendMat::Allocator* allocator_)
: flags(0), rows(0), cols(0), step(0), datastart(0), dataend(0),
allocator(allocator_)
{
upload(arr, stream);
}
inline AscendMat::AscendMat(const AscendMat& m)
: flags(m.flags), rows(m.rows), cols(m.cols), step(m.step), data(m.data),
datastart(m.datastart), dataend(m.dataend), allocator(m.allocator)
{}
inline AscendMat& AscendMat::operator=(const AscendMat& m)
{
if (this != &m)
{
AscendMat temp(m);
swap(temp);
}
return *this;
}
inline void AscendMat::swap(AscendMat& b)
{
std::swap(flags, b.flags);
std::swap(rows, b.rows);
std::swap(cols, b.cols);
std::swap(step, b.step);
std::swap(data, b.data);
std::swap(datastart, b.datastart);
std::swap(dataend, b.dataend);
std::swap(allocator, b.allocator);
}
inline bool AscendMat::isContinuous() const { return (flags & Mat::CONTINUOUS_FLAG) != 0; }
inline size_t AscendMat::elemSize() const { return CV_ELEM_SIZE(flags); }
inline size_t AscendMat::elemSize1() const { return CV_ELEM_SIZE1(flags); }
inline int AscendMat::type() const { return CV_MAT_TYPE(flags); }
inline int AscendMat::depth() const { return CV_MAT_DEPTH(flags); }
inline int AscendMat::channels() const { return CV_MAT_CN(flags); }
inline size_t AscendMat::step1() const { return step / elemSize1(); }
inline Size AscendMat::size() const { return Size(cols, rows); }
inline bool AscendMat::empty() const { return data == 0; }
inline AscendStream::AscendStream(const Ptr<AscendStream::Impl>& impl) : impl_(impl) {}
inline AscendEvent::AscendEvent(const Ptr<AscendEvent::Impl>& impl) : impl_(impl) {}
} // namespace cann
} // namespace cv
#endif // OPENCV_CANNOPS_CANN_INL_HPP
@@ -0,0 +1,181 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
#ifndef OPENCV_CANNOPS_CANN_CALL_HPP
#define OPENCV_CANNOPS_CANN_CALL_HPP
#include <vector>
#include <set>
#include <string>
#include <acl/acl_base.h>
#include "cann.hpp"
#include "stream_accessor.hpp"
#include "ascendc_kernels.hpp"
class aclopAttr;
namespace cv
{
namespace cann
{
CV_EXPORTS void checkAclError(aclError err, const char* file, const int line, const char* func);
void checkAclPtr(void* ptr, const char* file, const int line, const char* func);
#define CV_ACL_SAFE_CALL(expr) checkAclError((expr), __FILE__, __LINE__, CV_Func)
#define CV_ACL_SAFE_CALL_PTR(expr) \
({ \
auto ptr = (expr); \
checkAclPtr(ptr, __FILE__, __LINE__, CV_Func); \
ptr; \
})
// Warpper for functions in CANN, callers should not call CANN's api directly, but should call the
// function provided in cann_call.
void aclrtMallocWarpper(void** data, size_t size);
void aclrtFreeWarpper(void* data);
void aclrtMemcpyWarpper(std::shared_ptr<uchar>& dst, size_t offset, const void* src, size_t size,
AscendStream& stream);
void aclrtMemcpyWarpper(void* dst, const std::shared_ptr<uchar>& src, size_t offset, size_t size,
AscendStream& stream);
void aclrtMemcpyWarpper(std::shared_ptr<uchar>& dst, size_t dstOffset,
const std::shared_ptr<uchar>& src, size_t srcOffset, size_t size,
AscendStream& stream);
void aclrtMemcpy2dWarpper(std::shared_ptr<uchar>& dst, size_t offset, size_t dpitch,
const void* src, size_t spitch, size_t width, size_t length,
AscendStream& stream);
void aclrtMemcpy2dWarpper(void* dst, size_t dpitch, const std::shared_ptr<uchar>& src,
size_t offset, size_t spitch, size_t width, size_t length,
AscendStream& stream);
void aclrtMemsetWarpper(std::shared_ptr<uchar>& ptr, int32_t value, size_t count,
AscendStream& stream);
//! Type mapping between opencv and cann.
aclDataType getACLType(int opencvdepth);
//! Malloc and upload raw data to devices.
CV_EXPORTS std::shared_ptr<uchar> mallocAndUpload(const void* data, size_t size, AscendStream& stream,
AscendMat::Allocator* allocator);
/**
* @brief Warpper of CANN streams.
*/
class AscendStream::Impl
{
public:
aclrtStream stream;
bool ownStream;
/**
* @brief Ascend and CANN use stream to implement asynchronous calls. Which means when function
* returns, operator may not finish, even not start. If caller free any tensors that participate
* in this operatation, it have a chance to access invalid memory.
* All tensors should add to holder, holder will be cleaned by waitForCompletion function, or when
* the stream is destructing.
*/
std::set<std::shared_ptr<uchar>> tensorHolders;
Impl();
explicit Impl(aclrtStream stream);
void AddTensorHolder(const std::shared_ptr<uchar>& tensorData);
};
/**
* @brief Warpper of CANN event.
*/
class AscendEvent::Impl
{
public:
aclrtEvent event;
bool ownEvent;
Impl();
explicit Impl(aclrtEvent event);
~Impl();
};
/**
* @brief Parameter type for call_call interfaces.
*/
struct AscendTensor
{
const char* name;
std::shared_ptr<uchar> data;
size_t dataSize;
std::vector<int64_t> dims;
aclDataType dtype;
aclFormat format;
AscendTensor(){};
AscendTensor(std::shared_ptr<uchar> _data, size_t _dataSize, int64_t* _dims, size_t _dimSize,
aclDataType _dtype, const char* _name = "", aclFormat _format = ACL_FORMAT_ND);
AscendTensor(std::shared_ptr<uchar> _data, size_t _dataSize, std::vector<int64_t>& _dims,
aclDataType _dtype, const char* _name = "", aclFormat _format = ACL_FORMAT_ND)
: name(_name), data(_data), dataSize(_dataSize), dims(_dims), dtype(_dtype),
format(_format){};
AscendTensor(const AscendMat& ascendMat, const char* _name = "",
aclFormat format = ACL_FORMAT_ND);
};
/**
* @brief Interface to call operators in CANN package.
*/
class OperatorRunner
{
private:
std::vector<aclDataBuffer*> inputBuffers_;
std::vector<aclDataBuffer*> outputBuffers_;
std::vector<aclTensorDesc*> inputDesc_;
std::vector<aclTensorDesc*> outputDesc_;
aclopAttr* opAttr_;
bool opAttrInit;
std::string op;
std::set<std::shared_ptr<uchar>> holder;
OperatorRunner& addInput(AscendTensor& mat);
OperatorRunner& addOutput(AscendTensor& mat);
public:
OperatorRunner() : opAttrInit(false) {}
virtual ~OperatorRunner() { reset(); }
OperatorRunner& setOp(const char* op);
OperatorRunner& addInput(const AscendMat& mat);
OperatorRunner& addOutput(AscendMat& mat);
OperatorRunner& addAttr(float value, const char* name);
OperatorRunner& addAttr(const char* value, const char* name);
OperatorRunner& addAttr(int value, const char* name);
OperatorRunner& addAttr(bool value, const char* name);
OperatorRunner& addAttr(const int64_t* value, int size, const char* name);
OperatorRunner& addInput(const AscendMat& mat, const char* name);
OperatorRunner& addInput(const Scalar& sc, int type, const char* name);
template <typename T>
OperatorRunner& addInput(const T* value, int64_t* dims, size_t dimSize, aclDataType type,
const char* name)
{
int64_t size = dims[0];
for (size_t i = 1; i < dimSize; i++)
size *= dims[i];
size_t dataSize = size * sizeof(T);
std::shared_ptr<uchar> ptr =
mallocAndUpload(value, dataSize, AscendStream::Null(), AscendMat::defaultAllocator());
AscendTensor tensor(ptr, dataSize, dims, dimSize, type, name);
return addInput(tensor);
}
OperatorRunner& addOutput(AscendMat& mat, const char* name);
OperatorRunner& reset();
OperatorRunner& run(AscendStream& stream);
};
template <typename KERNEL_TYPE, typename TILING_TYPE, typename... ARGS>
void kernel_launch(KERNEL_TYPE kernel, AscendStream& stream, TILING_TYPE& tiling, ARGS... args)
{
std::shared_ptr<uchar> tilingDevice =
mallocAndUpload(&tiling, sizeof(TILING_TYPE), stream, AscendMat::defaultAllocator());
aclrtStream rawStream = AscendStreamAccessor::getStream(stream);
CV_ACL_SAFE_CALL(kernel(1, rawStream, tilingDevice.get(), args...));
if (rawStream == nullptr)
{
stream.waitForCompletion();
}
}
} // namespace cann
} // namespace cv
#endif // OPENCV_CANNOPS_CANN_CALL_HPP
@@ -0,0 +1,633 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
#ifndef OPENCV_CANNOPS_CANN_INTERFACE_HPP
#define OPENCV_CANNOPS_CANN_INTERFACE_HPP
#include "opencv2/cann.hpp"
namespace cv
{
namespace cann
{
/**
@addtogroup cannops
@{
@defgroup cannops_ops Operations for Ascend Backend.
@{
@defgroup cannops_elem Per-element Operations
@defgroup cannops_core Core Operations on Matrices
@defgroup cannimgproc Image Processing
@}
@}
*/
//! @addtogroup cannops_elem
//! @{
/** @brief Computes a matrix-matrix or matrix-scalar sum.
* @param src1 First source matrix or scalar.
* @param src2 Second source matrix or scalar. Matrix should have the same size and type as src1 .
* @param dst Destination matrix that has the same size and number of channels as the input
* array(s). The depth is defined by dtype or src1 depth.
* @param mask Optional operation mask, 8-bit single channel array, that specifies elements of the
* destination array to be changed. The mask can be used only with single channel images.
* @param dtype Optional depth of the output array.
* @param stream AscendStream for the asynchronous version.
* @sa cv::add cuda::add
*/
CV_EXPORTS_W void add(const InputArray src1, const InputArray src2, OutputArray dst,
const InputArray mask = noArray(), int dtype = -1,
AscendStream& stream = AscendStream::Null());
// This code should not be compiled nor analyzed by doxygen. This interface only for python binding
// code generation. add(InputArray, InputArray ...) can accept Scalar as its parametr.(Scalar -> Mat
// -> InputArray)
#ifdef NEVER_DEFINED
CV_EXPORTS_W void add(const InputArray src1, const Scalar& src2, OutputArray dst,
const InputArray mask = noArray(), int dtype = -1,
AscendStream& stream = AscendStream::Null());
CV_EXPORTS_W void add(const Scalar& src1, const InputArray src2, OutputArray dst,
const InputArray mask = noArray(), int dtype = -1,
AscendStream& stream = AscendStream::Null());
#endif
// More overload functions. In order to decouple from the main opencv repository and simplify
// user calling methods, besides the traditional Input/OutputArray parameters, some
// overloaded functions for the AcendMat parameter is also provided.
/** @overload */
CV_EXPORTS_W void add(const AscendMat& src1, const AscendMat& src2, CV_OUT AscendMat& dst,
const AscendMat& mask = AscendMat(), int dtype = -1,
AscendStream& stream = AscendStream::Null());
/** @overload */
CV_EXPORTS_W void add(const AscendMat& src1, const Scalar& src2, CV_OUT AscendMat& dst,
const AscendMat& mask = AscendMat(), int dtype = -1,
AscendStream& stream = AscendStream::Null());
/** @overload */
CV_EXPORTS_W void add(const Scalar& src1, const AscendMat& src2, CV_OUT AscendMat& dst,
const AscendMat& mask = AscendMat(), int dtype = -1,
AscendStream& stream = AscendStream::Null());
/** @brief Computes a matrix-matrix or matrix-scalar difference.
* @param src1 First source matrix or scalar.
* @param src2 Second source matrix or scalar. Matrix should have the same size and type as src1 .
* @param dst Destination matrix that has the same size and number of channels as the input
* array(s). The depth is defined by dtype or src1 depth.
* @param mask Optional operation mask, 8-bit single channel array, that specifies elements of the
* destination array to be changed. The mask can be used only with single channel images.
* @param dtype Optional depth of the output array.
* @param stream AscendStream for the asynchronous version.
* @sa cv::subtract cuda::subtract
*/
CV_EXPORTS_W void subtract(const InputArray src1, const InputArray src2, OutputArray dst,
const InputArray mask = noArray(), int dtype = -1,
AscendStream& stream = AscendStream::Null());
#ifdef NEVER_DEFINED
CV_EXPORTS_W void subtract(const InputArray src1, const Scalar& src2, OutputArray dst,
const InputArray mask = noArray(), int dtype = -1,
AscendStream& stream = AscendStream::Null());
CV_EXPORTS_W void subtract(const Scalar& src1, const InputArray src2, OutputArray dst,
const InputArray mask = noArray(), int dtype = -1,
AscendStream& stream = AscendStream::Null());
#endif
/** @overload */
CV_EXPORTS_W void subtract(const AscendMat& src1, const AscendMat& src2, CV_OUT AscendMat& dst,
const AscendMat& mask = AscendMat(), int dtype = -1,
AscendStream& stream = AscendStream::Null());
/** @overload */
CV_EXPORTS_W void subtract(const AscendMat& src1, const Scalar& src2, CV_OUT AscendMat& dst,
const AscendMat& mask = AscendMat(), int dtype = -1,
AscendStream& stream = AscendStream::Null());
/** @overload */
CV_EXPORTS_W void subtract(const Scalar& src1, const AscendMat& src2, CV_OUT AscendMat& dst,
const AscendMat& mask = AscendMat(), int dtype = -1,
AscendStream& stream = AscendStream::Null());
/** @brief Computes a matrix-matrix or matrix-scalar per-element product.
* @param src1 First source matrix or scalar.
* @param src2 Second source matrix or scalar. Matrix should have the same size and type as src1 .
* @param dst Destination matrix that has the same size and number of channels as the input
* array(s). The depth is defined by dtype or src1 depth.
* @param scale Optional scale factor.
* @param dtype Optional depth of the output array.
* @param stream AscendStream for the asynchronous version.
* @note when scale != 1, src must be one of the following types: float16, float32, int32
* @sa cv::multiply cuda::multiply
*/
CV_EXPORTS_W void multiply(const InputArray src1, const InputArray src2, OutputArray dst,
float scale = 1, int dtype = -1,
AscendStream& stream = AscendStream::Null());
#ifdef NEVER_DEFINED
CV_EXPORTS_W void multiply(const InputArray src1, const Scalar& src2, OutputArray dst,
float scale = 1, int dtype = -1,
AscendStream& stream = AscendStream::Null());
CV_EXPORTS_W void multiply(const Scalar& src1, const InputArray src2, OutputArray dst,
float scale = 1, int dtype = -1,
AscendStream& stream = AscendStream::Null());
#endif
/** @overload */
CV_EXPORTS_W void multiply(const AscendMat& src1, const AscendMat& src2, CV_OUT AscendMat& dst,
float scale = 1, int dtype = -1,
AscendStream& stream = AscendStream::Null());
/** @overload */
CV_EXPORTS_W void multiply(const AscendMat& src1, const Scalar& src2, CV_OUT AscendMat& dst,
float scale = 1, int dtype = -1,
AscendStream& stream = AscendStream::Null());
/** @overload */
CV_EXPORTS_W void multiply(const Scalar& src1, const AscendMat& src2, CV_OUT AscendMat& dst,
float scale = 1, int dtype = -1,
AscendStream& stream = AscendStream::Null());
/** @brief Computes a matrix-matrix or matrix-scalar division.
* @param src1 First source matrix or scalar.
* @param src2 Second source matrix or scalar. Matrix should have the same size and type as src1 .
* @param dst Destination matrix that has the same size and number of channels as the input
* array(s). The depth is defined by dtype or src1 depth.
* @param scale Optional scale factor.
* @param dtype Optional depth of the output array.
* @param stream AscendStream for the asynchronous version.
* @note when scale == 1, src must be one of the following types: float16, float32, double, uint16,
* int8, uint8, int16, int32, int64; when scale != 1, src must be one of the following types:
* int32, int16, float16, float32.
* @sa cv::divide cuda::divide
*/
CV_EXPORTS_W void divide(const InputArray src1, const InputArray src2, OutputArray dst,
float scale = 1, int dtype = -1,
AscendStream& stream = AscendStream::Null());
#ifdef NEVER_DEFINED
CV_EXPORTS_W void divide(const InputArray src1, const Scalar& src2, OutputArray dst,
float scale = 1, int dtype = -1,
AscendStream& stream = AscendStream::Null());
CV_EXPORTS_W void divide(const Scalar& src1, const InputArray src2, OutputArray dst,
float scale = 1, int dtype = -1,
AscendStream& stream = AscendStream::Null());
#endif
CV_EXPORTS_W void divide(const AscendMat& src1, const AscendMat& src2, CV_OUT AscendMat& dst,
float scale = 1, int dtype = -1,
AscendStream& stream = AscendStream::Null());
/** @overload */
CV_EXPORTS_W void divide(const AscendMat& src1, const Scalar& src2, CV_OUT AscendMat& dst,
float scale = 1, int dtype = -1,
AscendStream& stream = AscendStream::Null());
/** @overload */
CV_EXPORTS_W void divide(const Scalar& src1, const AscendMat& src2, CV_OUT AscendMat& dst,
float scale = 1, int dtype = -1,
AscendStream& stream = AscendStream::Null());
/** @brief Performs a per-element bitwise conjunction of two matrices (or of matrix and scalar).
* @param src1 First source matrix or scalar.
* @param src2 Second source matrix or scalar.
* @param dst Destination matrix that has the same size and number of channels as the input
* array(s). The depth is defined by dtype or src1 depth.
* @param mask Optional operation mask, 8-bit single channel array, that specifies elements of the
* destination array to be changed. The mask can be used only with single channel images.
* @param stream AscendStream for the asynchronous version.
* @note src must be one of the following types: int32, int16, uint16
* @sa cv::bitwise_and cuda::bitwise_and
*/
CV_EXPORTS_W void bitwise_and(const InputArray src1, const InputArray src2, OutputArray dst,
const InputArray mask = noArray(),
AscendStream& stream = AscendStream::Null());
#ifdef NEVER_DEFINED
CV_EXPORTS_W void bitwise_and(const InputArray src1, const Scalar& src2, OutputArray dst,
const InputArray mask = noArray(),
AscendStream& stream = AscendStream::Null());
CV_EXPORTS_W void bitwise_and(const Scalar& src1, const InputArray src2, OutputArray dst,
const InputArray mask = noArray(),
AscendStream& stream = AscendStream::Null());
#endif
CV_EXPORTS_W void bitwise_and(const AscendMat& src1, const AscendMat& src2, CV_OUT AscendMat& dst,
const AscendMat& mask = AscendMat(),
AscendStream& stream = AscendStream::Null());
/** @overload */
CV_EXPORTS_W void bitwise_and(const AscendMat& src1, const Scalar& src2, CV_OUT AscendMat& dst,
const AscendMat& mask = AscendMat(),
AscendStream& stream = AscendStream::Null());
/** @overload */
CV_EXPORTS_W void bitwise_and(const Scalar& src1, const AscendMat& src2, CV_OUT AscendMat& dst,
const AscendMat& mask = AscendMat(),
AscendStream& stream = AscendStream::Null());
/** @brief Performs a per-element bitwise disjunction of two matrices (or of matrix and scalar).
* @param src1 First source matrix or scalar.
* @param src2 Second source matrix or scalar.
* @param dst Destination matrix that has the same size and number of channels as the input
* array(s). The depth is defined by dtype or src1 depth.
* @param mask Optional operation mask, 8-bit single channel array, that specifies elements of the
* destination array to be changed. The mask can be used only with single channel images.
* @param stream AscendStream for the asynchronous version.
* @note src must be one of the following types: int32, int16, uint16
* @sa cv::bitwise_or cuda::bitwise_or
*/
CV_EXPORTS_W void bitwise_or(const InputArray src1, const InputArray src2, OutputArray dst,
const InputArray mask = noArray(),
AscendStream& stream = AscendStream::Null());
#ifdef NEVER_DEFINED
CV_EXPORTS_W void bitwise_or(const InputArray src1, const Scalar& src2, OutputArray dst,
const InputArray mask = noArray(),
AscendStream& stream = AscendStream::Null());
CV_EXPORTS_W void bitwise_or(const Scalar& src1, const InputArray src2, OutputArray dst,
const InputArray mask = noArray(),
AscendStream& stream = AscendStream::Null());
#endif
CV_EXPORTS_W void bitwise_or(const AscendMat& src1, const AscendMat& src2, CV_OUT AscendMat& dst,
const AscendMat& mask = AscendMat(),
AscendStream& stream = AscendStream::Null());
/** @overload */
CV_EXPORTS_W void bitwise_or(const AscendMat& src1, const Scalar& src2, CV_OUT AscendMat& dst,
const AscendMat& mask = AscendMat(),
AscendStream& stream = AscendStream::Null());
/** @overload */
CV_EXPORTS_W void bitwise_or(const Scalar& src1, const AscendMat& src2, CV_OUT AscendMat& dst,
const AscendMat& mask = AscendMat(),
AscendStream& stream = AscendStream::Null());
/** @brief Performs a per-element bitwise exclusive or operation of two matrices (or of matrix and
* scalar).
* @param src1 First source matrix or scalar.
* @param src2 Second source matrix or scalar.
* @param dst Destination matrix that has the same size and number of channels as the input
* array(s). The depth is defined by dtype or src1 depth.
* @param mask Optional operation mask, 8-bit single channel array, that specifies elements of the
* destination array to be changed. The mask can be used only with single channel images.
* @param stream AscendStream for the asynchronous version.
* @note src must be one of the following types: int32, int16, uint16
* @sa cv::bitwise_xor cuda::bitwise_xor
*/
CV_EXPORTS_W void bitwise_xor(const InputArray src1, const InputArray src2, OutputArray dst,
const InputArray mask = noArray(),
AscendStream& stream = AscendStream::Null());
#ifdef NEVER_DEFINED
CV_EXPORTS_W void bitwise_xor(const InputArray src1, const Scalar& src2, OutputArray dst,
const InputArray mask = noArray(),
AscendStream& stream = AscendStream::Null());
CV_EXPORTS_W void bitwise_xor(const Scalar& src1, const InputArray src2, OutputArray dst,
const InputArray mask = noArray(),
AscendStream& stream = AscendStream::Null());
#endif
CV_EXPORTS_W void bitwise_xor(const AscendMat& src1, const AscendMat& src2, CV_OUT AscendMat& dst,
const AscendMat& mask = AscendMat(),
AscendStream& stream = AscendStream::Null());
/** @overload */
CV_EXPORTS_W void bitwise_xor(const AscendMat& src1, const Scalar& src2, CV_OUT AscendMat& dst,
const AscendMat& mask = AscendMat(),
AscendStream& stream = AscendStream::Null());
/** @overload */
CV_EXPORTS_W void bitwise_xor(const Scalar& src1, const AscendMat& src2, CV_OUT AscendMat& dst,
const AscendMat& mask = AscendMat(),
AscendStream& stream = AscendStream::Null());
/** @brief Performs a per-element bitwise inversion.
* @param src First source matrix.
* @param dst Destination matrix that has the same size and number of channels as the input
* array(s). The depth is defined by dtype or src1 depth.
* @param mask Optional operation mask, 8-bit single channel array, that specifies elements of the
* destination array to be changed. The mask can be used only with single channel images.
* @param stream AscendStream for the asynchronous version.
* @note src must be one of the following types: int32, int16, uint16
* @sa cv::bitwise_not cuda::bitwise_not
*/
CV_EXPORTS_W void bitwise_not(const InputArray src, OutputArray dst,
const InputArray mask = noArray(),
AscendStream& stream = AscendStream::Null());
/** @overload */
CV_EXPORTS_W void bitwise_not(const AscendMat& src, CV_OUT AscendMat& dst,
const AscendMat& mask = AscendMat(),
AscendStream& stream = AscendStream::Null());
/** @brief Computes the weighted sum of two arrays.
@param src1 First source array.
@param alpha Weight for the first array elements.
@param src2 Second source array of the same size and channel number as src1 .
@param beta Weight for the second array elements.
@param dst Destination array that has the same size and number of channels as the input arrays.
@param gamma Scalar added to each sum.
@param dtype Optional depth of the destination array. When both input arrays have the same depth,
dtype can be set to -1, which will be equivalent to src1.depth().
@param stream Stream for the asynchronous version.
The function addWeighted calculates the weighted sum of two arrays as follows:
\f[\texttt{dst} (I)= \texttt{saturate} ( \texttt{src1} (I)* \texttt{alpha} + \texttt{src2} (I)*
\texttt{beta} + \texttt{gamma} )\f]
where I is a multi-dimensional index of array elements. In case of multi-channel arrays, each
channel is processed independently.
@note src must be one of the following types: int32, int16, float16, float32.
@sa cv::addWeighted cv::cuda::addWeighted
*/
CV_EXPORTS_W void addWeighted(const InputArray src1, double alpha, const InputArray src2,
double beta, double gamma, OutputArray dst, int dtype = -1,
AscendStream& stream = AscendStream::Null());
/** @overload */
CV_EXPORTS_W void addWeighted(const AscendMat& src1, double alpha, const AscendMat& src2,
double beta, double gamma, CV_OUT AscendMat& dst, int dtype = -1,
AscendStream& stream = AscendStream::Null());
/** @brief Applies a fixed-level threshold to each array element.
@param src Source array (single-channel).
@param dst Destination array with the same size and type as src .
@param thresh Threshold value.
@param maxval Maximum value to use with THRESH_BINARY and THRESH_BINARY_INV threshold types.
@param type Threshold type. For details, see threshold . The THRESH_MASK, THRESH_OTSU and
THRESH_TRIANGLE threshold types are not supported.
@param stream AscendStream for the asynchronous version.
@note src must be one of the following types: float16, float32.
@sa cv::threshold cv::cuda::threshold
*/
CV_EXPORTS_W double threshold(const InputArray src, OutputArray dst, double thresh, double maxval,
int type, AscendStream& stream = AscendStream::Null());
/** @overload */
CV_EXPORTS_W double threshold(const AscendMat& src, CV_OUT AscendMat& dst, double thresh,
double maxval, int type, AscendStream& stream = AscendStream::Null());
//! @} cannops_elem
//! @addtogroup cannops_core
//! @{
/** @brief Makes a multi-channel matrix out of several single-channel matrices.
@param src Array/vector of source matrices.
@param n Number of source matrices.
@param dst Destination matrix.
@param stream AscendStream for the asynchronous version.
@note src must be one of the following types: float16, float32, double, int32, int16, int8, int64,
uint8, uint16, uint32, uint64.
@sa cv::merge cv::cuda::merge
*/
CV_EXPORTS_W void merge(const AscendMat* src, size_t n, CV_OUT AscendMat& dst,
AscendStream& stream = AscendStream::Null());
/** @overload */
CV_EXPORTS_W void merge(const std::vector<AscendMat>& src, CV_OUT AscendMat& dst,
AscendStream& stream = AscendStream::Null());
/** @overload */
CV_EXPORTS_W void merge(const AscendMat* src, size_t n, OutputArray& dst,
AscendStream& stream = AscendStream::Null());
/** @overload */
CV_EXPORTS_W void merge(const std::vector<AscendMat>& src, OutputArray& dst,
AscendStream& stream = AscendStream::Null());
/** @brief Copies each plane of a multi-channel matrix into an array.
@param src Source matrix.
@param dst Destination array/vector of single-channel matrices.
@param stream AscendStream for the asynchronous version.
@note src must be one of the types:float16, float32, double, int64, int32, uint8, uint16, uint32,
uint64, int8, int16, bool
@sa cv::split cv::cuda::split
*/
CV_EXPORTS_W void split(const AscendMat& src, AscendMat* dst,
AscendStream& stream = AscendStream::Null());
/** @overload */
CV_EXPORTS_W void split(const AscendMat& src, CV_OUT std::vector<AscendMat>& dst,
AscendStream& stream = AscendStream::Null());
/** @overload */
CV_EXPORTS_W void split(const InputArray src, AscendMat* dst,
AscendStream& stream = AscendStream::Null());
/** @overload */
CV_EXPORTS_W void split(const InputArray src, CV_OUT std::vector<AscendMat>& dst,
AscendStream& stream = AscendStream::Null());
/** @brief Transposes a matrix.
@param src Source matrix.
@param dst Destination matrix.
@param stream AscendStream for the asynchronous version.
@note src must be one of the following types:
float16,float,int8,int16,int32,int64,uint8,uint16,uint32,uint64,bool
@sa cv::transpose cv::cuda::transpose
*/
CV_EXPORTS_W void transpose(InputArray src, OutputArray dst,
AscendStream& stream = AscendStream::Null());
/** @overload */
CV_EXPORTS_W void transpose(const AscendMat& src, CV_OUT AscendMat& dst,
AscendStream& stream = AscendStream::Null());
/** @brief Flips a 2D matrix around vertical, horizontal, or both axes.
@param src Source matrix.
@param dst Destination matrix.
@param flipCode Flip mode for the source:
- 0 Flips around x-axis.
- \> 0 Flips around y-axis.
- \< 0 Flips around both axes.
@param stream AscendStream for the asynchronous version.
@note src must be one of the following types: float16,float,int64,int32,int16,uint16
@sa cv::flip cv::cuda::flip
*/
CV_EXPORTS_W void flip(InputArray src, OutputArray dst, int flipCode,
AscendStream& stream = AscendStream::Null());
/** @overload */
CV_EXPORTS_W void flip(const AscendMat& src, CV_OUT AscendMat& dst, int flipCode,
AscendStream& stream = AscendStream::Null());
/** @brief Rotates a 2D array in multiples of 90 degrees.
The function cv::rotate rotates the array in one of three different ways:
* Rotate by 90 degrees clockwise (rotateCode = ROTATE_90_CLOCKWISE).
* Rotate by 180 degrees clockwise (rotateCode = ROTATE_180).
* Rotate by 270 degrees clockwise (rotateCode = ROTATE_90_COUNTERCLOCKWISE).
@param src input array.
@param dst output array of the same type as src. The size is the same with ROTATE_180,
and the rows and cols are switched for ROTATE_90_CLOCKWISE and ROTATE_90_COUNTERCLOCKWISE.
@param rotateCode an enum to specify how to rotate the array; see the enum #RotateFlags
@param stream AscendStream for the asynchronous version.
@note src must be one of the following types: float16,float,int64,int32,int16,uint16
@sa cv::rotate
*/
CV_EXPORTS_W void rotate(InputArray src, OutputArray dst, int rotateCode,
AscendStream& stream = AscendStream::Null());
/** @overload */
CV_EXPORTS_W void rotate(const AscendMat& src, CV_OUT AscendMat& dst, int rotateMode,
AscendStream& stream = AscendStream::Null());
/** @brief crop a 2D array.
The function crops the matrix by given cv::Rect.
Output matrix must be of the same depth as input one, size is specified by given rect size.
@param src input array.
@param rect a rect to crop a array to
@param stream AscendStream for the asynchronous version.
@sa cv::gapi::crop
*/
CV_EXPORTS_W AscendMat crop(InputArray src, const Rect& rect,
AscendStream& stream = AscendStream::Null());
/** @overload */
CV_EXPORTS_W AscendMat crop(const AscendMat& src, const Rect& rect,
AscendStream& stream = AscendStream::Null());
//! interpolation algorithm
enum InterpolationFlags
{
/** nearest neighbor interpolation */
INTER_NEAREST = 0,
/** bilinear interpolation */
INTER_LINEAR = 1,
/** bicubic interpolation */
INTER_CUBIC = 2,
/** resampling using pixel area relation. It may be a preferred method for image decimation, as
it gives moire'-free results. But when the image is zoomed, it is similar to the INTER_NEAREST
method. */
INTER_AREA = 3,
/** mask for interpolation codes */
INTER_MAX = 7,
};
/** @brief Resizes an image src down to or up to the specified size.
@param src input image
@param dst output image; it has the size dsize (when it is non-zero) or the size computed from
src.size(), fx, and fy; the type of dst is the same as of src.
@param dsize output image size; if it equals zero, it is computed as:
\f[𝚍𝚜𝚒𝚣𝚎 = 𝚂𝚒𝚣𝚎(𝚛𝚘𝚞𝚗𝚍(𝚏𝚡*𝚜𝚛𝚌.𝚌𝚘𝚕𝚜), 𝚛𝚘𝚞𝚗𝚍(𝚏𝚢*𝚜𝚛𝚌.𝚛𝚘𝚠𝚜))\f]
Either dsize or both fx and fy must be non-zero.
@param fx scale factor along the horizontal axis; when it equals 0, it is computed as
\f[(𝚍𝚘𝚞𝚋𝚕𝚎)𝚍𝚜𝚒𝚣𝚎.𝚠𝚒𝚍𝚝𝚑/𝚜𝚛𝚌.𝚌𝚘𝚕𝚜\f]
@param fy scale factor along the vertical axis; when it equals 0, it is computed as
\f[(𝚍𝚘𝚞𝚋𝚕𝚎)𝚍𝚜𝚒𝚣𝚎.𝚑𝚎𝚒𝚐𝚑𝚝/𝚜𝚛𝚌.𝚛𝚘𝚠𝚜\f]
@param interpolation interpolation method(see **cv.cann.InterpolationFlags**)
@param stream AscendStream for the asynchronous version.
* @note There are some constraints for the input datatype:
* when resampling using
* nearest neighbor or bilinear interpolation: Input images must be uint8, and only GRAY and BGR
images are supported. The resolution of input and output images must in range of [10*6,
4096*4096].
* bicubic interpolation: Input images can be of different types, output images must be
float or uint8.
* pixel area interpolation: Input images can be of different types but output images
are always float.\n
* Only the following devices are supported when resampling using nearest neighbor or bilinear
interpolation: Atlas Inference Series products, Atlas 200/500 A2 Inference products and
Atlas A2 Training Series products/Atlas 300I A2 Inference products
@sa cv::resize
*/
CV_EXPORTS_W void resize(InputArray src, OutputArray dst, Size dsize, double fx, double fy,
int interpolation, AscendStream& stream = AscendStream::Null());
/** @overload */
CV_EXPORTS_W void resize(const AscendMat& src, CV_OUT AscendMat& dst, Size dsize, double fx,
double fy, int interpolation, AscendStream& stream = AscendStream::Null());
/** @brief crop a sub image from a big one, and resize it to certain size.
@param src input array.
@param dst output array. it has the size dsize (when it is non-zero) or the size computed from
src.size(), fx, and fy; the type of dst is the same as of src.
@param rect a rect to crop a array to
@param dsize output image size; if it equals zero, it is computed as cv::resize do.
@param fx scale factor along the horizontal axis; when it equals 0, it is computed as
\f[(𝚍𝚘𝚞𝚋𝚕𝚎)𝚍𝚜𝚒𝚣𝚎.𝚠𝚒𝚍𝚝𝚑/𝚜𝚛𝚌.𝚌𝚘𝚕𝚜\f]
@param fy scale factor along the vertical axis; when it equals 0, it is computed as
\f[(𝚍𝚘𝚞𝚋𝚕𝚎)𝚍𝚜𝚒𝚣𝚎.𝚑𝚎𝚒𝚐𝚑𝚝/𝚜𝚛𝚌.𝚛𝚘𝚠𝚜\f]
@param interpolation interpolation method, only support INTER_NEAREST and INTER_LINEAR here.
(see **cv.cann.InterpolationFlags**)
@note The input images must be uint8, and only GRAY and BGR images are supported. The resolution of
input and output images must in range of [10*6, 4096*4096].
@note Only the following devices are supported: Atlas Inference Series products, Atlas 200/500 A2
Inference products and Atlas A2 Training Series products/Atlas 300I A2 Inference products.
@sa cv::gapi::crop, cv::resize, cv::cann::resize
*/
CV_EXPORTS_W void cropResize(const InputArray src, OutputArray dst, const Rect& rect, Size dsize,
double fx, double fy, int interpolation);
/** @overload */
CV_EXPORTS_W void cropResize(const AscendMat& src, CV_OUT AscendMat& dst, const Rect& rect,
Size dsize, double fx, double fy, int interpolation);
/** @brief crop a sub image from a big one, resize it to certain size, and form the top/left border
and fills it with specified bordertype.
@param src input array.
@param dst output array; it has the size Size(dsize.height + top, dsize.width + left).
@param rect a rect to crop a array to
@param dsize resize size;
@param fx scale factor along the horizontal axis;
@param fy scale factor along the vertical axis;
@param interpolation interpolation method, only INTER_NEAREST and INTER_LINEAR are supported.
(see **cv.cann.InterpolationFlags**)
@param borderType border extrapolate method, only cv::BorderTypes::BORDER_CONSTANT and
cv::BorderTypes::BORDER_REPLICATE are supported.
@param value Border BGR or YUV value if borderType==BORDER_CONSTANT.
@param top Number of pixels for top padding
@param left Number of pixels for left padding
@note The input images must be uint8, and only GRAY and BGR images are supported. The resolution of
input and output images must in range of [10*6, 4096*4096].
@note Only the following devices are supported: Atlas Inference Series products, Atlas 200/500 A2
Inference products and Atlas A2 Training Series products/Atlas 300I A2 Inference products.
@sa cv::gapi::crop, cv::resize, cv::cann::resize, cv::BorderTypes
*/
CV_EXPORTS_W void cropResizeMakeBorder(const InputArray src, OutputArray dst, const Rect& rect,
Size dsize, double fx, double fy, int interpolation, int top,
int left, const int borderType, Scalar value = Scalar());
/** @overload */
CV_EXPORTS_W void cropResizeMakeBorder(const AscendMat& src, CV_OUT AscendMat& dst,
const Rect& rect, Size dsize, double fx, double fy,
int interpolation, int top, int left, const int borderType,
Scalar value = Scalar());
/** @brief Forms a border and fills it with specified bordertype around the copy of input image.
@param src Source image.
@param dst Destination image of the same type as src and the size Size(src.cols+left+right,
src.rows+top+bottom).
@param top Number of pixels for top padding
@param bottom Number of pixels for bottom padding
@param left Number of pixels for left padding
@param right Number of pixels for right padding
Parameter specifying how many pixels in each direction from the source image rectangle to
extrapolate. For example, top=1, bottom=1, left=1, right=1 mean that 1 pixel-wide border needs to be
built.
@param borderType Border type. only cv::BorderTypes::BORDER_CONSTANT and
cv::BorderTypes::BORDER_REPLICATE are supported.
@param value Border BGR or YUV value if borderType==BORDER_CONSTANT.
@note The input images must be uint8, and only GRAY and BGR images are supported. The resolution of
input and output images must in range of [10*6, 4096*4096].
@note Only the following devices are supported: Atlas Inference Series products, Atlas 200/500 A2
Inference products and Atlas A2 Training Series products/Atlas 300I A2 Inference products.
@sa cv::copyMakeBorder, cv::borderInterpolate
*/
CV_EXPORTS_W void copyMakeBorder(const InputArray src, OutputArray dst, int top, int bottom,
int left, int right, int borderType,
const Scalar& value = Scalar());
/** @overload */
CV_EXPORTS_W void copyMakeBorder(const AscendMat& src, CV_OUT AscendMat& dst, int top, int bottom,
int left, int right, int borderType,
const Scalar& value = Scalar());
//! @} cannops_core
//! @addtogroup cannimgproc
//! @{
/** @brief Converts an image from one color space to another.
@param src Source image with CV_8U , CV_16U , or CV_32F depth and 1, 3, or 4 channels.
@param dst Destination image.
@param code Color space conversion code. For details, see cv::ColorConversionCodes .
@param dstCn Number of channels in the destination image. If the parameter is 0, the number of the
channels is derived automatically from src and the code .
@param stream AscendStream for the asynchronous version.
@note The supported conversion types are as follows:
{ CV_BGR2BGRA, CV_BGRA2BGR, CV_BGR2RGBA, CV_RGBA2BGR,
CV_BGR2RGB, CV_BGRA2RGBA, CV_BGR2GRAY, CV_RGB2GRAY,
CV_GRAY2BGR, CV_GRAY2BGRA, CV_BGRA2GRAY, CV_RGBA2GRAY,
CV_BGR2XYZ, CV_RGB2XYZ, CV_XYZ2BGR, CV_XYZ2RGB,
CV_BGR2YCrCb, CV_RGB2YCrCb, CV_YCrCb2BGR, CV_YCrCb2RGB,
CV_BGR2YUV, CV_RGB2YUV, CV_YUV2BGR, CV_YUV2RGB }
@sa cv::cvtColor cv::cuda::cvtColor
*/
CV_EXPORTS_W void cvtColor(const InputArray src, OutputArray dst, int code, int dstCn = 0,
AscendStream& stream = AscendStream::Null());
/** @overload */
CV_EXPORTS_W void cvtColor(const AscendMat& src, CV_OUT AscendMat& dst, int code, int dstCn = 0,
AscendStream& stream = AscendStream::Null());
//! @} cannimgproc
} // namespace cann
} // namespace cv
#endif // OPENCV_CANNOPS_CANN_INTERFACE_HPP
@@ -0,0 +1,33 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
#ifndef OPENCV_CANNOPS_CANN_PRIVATE_HPP
#define OPENCV_CANNOPS_CANN_PRIVATE_HPP
#include "opencv2/cann.hpp"
namespace cv
{
namespace cann
{
void arithm_op(const AscendMat& src1, const AscendMat& src2, AscendMat& dst, const char* op,
AscendStream& stream);
void arithm_op(const AscendMat& src, const Scalar& sc, AscendMat& dst, const char* op,
AscendStream& stream);
void arithm_op(const Scalar& sc, const AscendMat& src, AscendMat& dst, const char* op,
AscendStream& stream);
void arithm_op(const AscendMat& src, AscendMat& dst, const char* op, AscendStream& stream);
void arithm_op(const AscendMat& src, float scalar, AscendMat& dst, const char* op,
AscendStream& stream);
void transpose(const AscendMat& src, int64_t* perm, AscendMat& dst, AscendStream& stream);
void flip(const AscendMat& src, std::vector<int32_t>& asixs, AscendMat& dst, AscendStream& stream);
void crop(const AscendMat& src, AscendMat& dst, const AscendMat& sizeSrcNpu, int64_t* offset,
AscendStream& stream);
void transData(const AscendMat& src, AscendMat& dst, const char* from, const char* to,
AscendStream& stream);
void resize(const AscendMat& src, AscendMat& dst, int32_t* dstSize, int interpolation,
AscendStream& stream);
} // namespace cann
} // namespace cv
#endif // OPENCV_CANNOPS_CANN_PRIVATE_HPP
@@ -0,0 +1,107 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
#ifndef ENABLE_DVPP_INTERFACE
#define ENABLE_DVPP_INTERFACE
#endif // ENABLE_DVPP_INTERFACE
#include <vector>
#include <string>
#include <acl/acl.h>
#include <acl/acl_op_compiler.h>
#include <acl/dvpp/hi_dvpp.h>
#include "acl/acl_op.h"
#include "cann_call.hpp"
namespace cv
{
namespace cann
{
struct AscendPicDesc
{
const char* name;
std::shared_ptr<hi_void> data;
std::vector<int64_t> batchNum;
size_t widthAlignment = 16;
size_t heightAlignment = 1;
size_t sizeAlignment = 3;
size_t sizeNum = 3;
hi_vpc_pic_info Pic;
AscendPicDesc& setMemAlign();
AscendPicDesc& setPic(hi_pixel_format _picture_format);
std::shared_ptr<hi_void> allocate();
AscendPicDesc(){};
AscendPicDesc(const AscendMat& ascendMat, hi_pixel_format _picture_format);
AscendPicDesc(const Mat& mat, hi_pixel_format _picture_format);
};
/*
***************************** hi_mpi_vpc warppers ***************************
The DVPP VPC interfaces here are all version v2. Only the following devices are supported: Atlas
Inference Series products, Atlas 200/500 A2 Inference products and Atlas A2 Training Series
products/Atlas 300I A2 Inference products.
*/
inline void vpcResizeWarpper(hi_vpc_chn chnId, hi_vpc_pic_info& inPic, hi_vpc_pic_info& outPic,
int interpolation, uint32_t* taskID)
{
uint32_t ret = hi_mpi_vpc_resize(chnId, &inPic, &outPic, 0, 0, interpolation, taskID, -1);
if (ret != HI_SUCCESS)
CV_Error(Error::StsBadFlag, "failed to resize image");
}
void vpcCropResizeWarpper(hi_vpc_chn chnId, hi_vpc_pic_info& inPic, hi_vpc_pic_info& outPic,
int cnt, uint32_t* taskID, const Rect& rect, Size dsize,
int interpolation);
void vpcCropResizeMakeBorderWarpper(hi_vpc_chn chnId, std::vector<AscendPicDesc>& inPicDesc,
std::vector<AscendPicDesc>& outPicDesc, int cnt,
uint32_t* taskID, const Rect& rect, Size dsize,
int interpolation, const int borderType, Scalar scalarV,
int top, int left);
void vpcCopyMakeBorderWarpper(hi_vpc_chn chnId, hi_vpc_pic_info& inPic, hi_vpc_pic_info& outPic,
uint32_t* taskID, int* offsets, int bordertype, Scalar value);
/*****************************************************************************/
/**
* @brief Interface for calling DVPP operator descriptors.
* The DVPP VPC interfaces here are all version v2. Supported devices: Atlas Inference Series
* products, Atlas 200/500 A2 Inference products and Atlas A2 Training Series products/Atlas 300I A2
* Inference products.
*/
class DvppOperatorDesc
{
private:
DvppOperatorDesc& addInput(AscendPicDesc& picDesc);
DvppOperatorDesc& addOutput(AscendPicDesc& picDesc);
std::set<std::shared_ptr<hi_void>> holder;
public:
DvppOperatorDesc()
{
chnId = 0;
stChnAttr = {};
createChannel();
}
virtual ~DvppOperatorDesc() { reset(); }
DvppOperatorDesc& addInput(const AscendMat& mat);
DvppOperatorDesc& addOutput(AscendMat& mat);
DvppOperatorDesc& addInput(const Mat& mat);
DvppOperatorDesc& addOutput(Mat& mat);
DvppOperatorDesc& getResult(Mat& dst, uint32_t& taskIDResult);
DvppOperatorDesc& getResult(AscendMat& dst, uint32_t& taskIDResult);
DvppOperatorDesc& reset();
DvppOperatorDesc& createChannel();
std::vector<AscendPicDesc> inputDesc_;
std::vector<AscendPicDesc> outputDesc_;
hi_vpc_chn chnId;
hi_vpc_chn_attr stChnAttr;
};
} // namespace cann
} // namespace cv
@@ -0,0 +1,39 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
#ifndef OPENCV_CANNOPS_STREAM_ACCESSOR_HPP
#define OPENCV_CANNOPS_STREAM_ACCESSOR_HPP
#include <acl/acl_base.h>
#include "opencv2/cann.hpp"
namespace cv
{
namespace cann
{
//! @addtogroup cann_struct
//! @{
/** @brief Class that enables getting aclrtAscendStream from cann::AscendStream
*/
struct AscendStreamAccessor
{
CV_EXPORTS static aclrtStream getStream(const AscendStream& stream);
CV_EXPORTS static AscendStream wrapStream(aclrtStream stream);
};
/** @brief Class that enables getting aclrtAscendEvent from cann::AscendEvent
*/
struct AscendEventAccessor
{
CV_EXPORTS static aclrtEvent getEvent(const AscendEvent& event);
CV_EXPORTS static AscendEvent wrapEvent(aclrtEvent event);
};
//! @} cann_struct
} // namespace cann
} // namespace cv
#endif // OPENCV_CANNOPS_STREAM_ACCESSOR_HPP