29 #include <opencv2/core/version.hpp>
30 #if CV_MAJOR_VERSION >= 3
31 # include <opencv2/imgcodecs.hpp>
33 # include <opencv2/highgui/highgui.hpp>
49 #define CHECK_STATUS(STMT) \
52 VPIStatus status = (STMT); \
53 if (status != VPI_SUCCESS) \
55 char buffer[VPI_MAX_STATUS_MESSAGE_LENGTH]; \
56 vpiGetLastStatusMessage(buffer, sizeof(buffer)); \
57 std::ostringstream ss; \
58 ss << vpiStatusGetName(status) << ": " << buffer; \
59 throw std::runtime_error(ss.str()); \
63 int main(
int argc,
char *argv[])
82 throw std::runtime_error(std::string(
"Usage: ") + argv[0] +
" <cpu|vic|cuda> <input image>");
85 std::string strBackend = argv[1];
86 std::string strInputFileName = argv[2];
89 cvImage = cv::imread(strInputFileName);
92 throw std::runtime_error(
"Can't open '" + strInputFileName +
"'");
95 assert(cvImage.type() == CV_8UC3);
100 if (strBackend ==
"cpu")
104 else if (strBackend ==
"cuda")
108 else if (strBackend ==
"vic")
114 throw std::runtime_error(
"Backend '" + strBackend +
"' not recognized, it must be either cpu, cuda or vic");
163 imwrite(
"scaled_" + strBackend +
".png", cvOut);
169 catch (std::exception &e)
171 std::cerr << e.what() << std::endl;
用于处理 OpenCV 与 VPI 互操作性的函数。
VPIImageBuffer buffer
存储图像内容。
VPIImagePlanePitchLinear planes[VPI_MAX_PLANE_COUNT]
pitch-linear 布局中所有图像平面的数据。
VPIImageBufferPitchLinear pitch
以 pitch-linear 布局存储的图像。
VPIImageBufferType bufferType
图像缓冲区类型。
int32_t height
此平面的高度(以像素为单位)。
int32_t width
此平面的宽度(以像素为单位)。
int32_t pitchBytes
一行开头与上一行开头之间的字节差。
void vpiImageDestroy(VPIImage img)
销毁图像实例。
struct VPIImageImpl * VPIImage
图像的句柄。
VPIStatus vpiImageLockData(VPIImage img, VPILockMode mode, VPIImageBufferType bufType, VPIImageData *data)
获取图像对象的锁并返回图像内容。
VPIStatus vpiImageCreate(int32_t width, int32_t height, VPIImageFormat fmt, uint64_t flags, VPIImage *img)
使用指定的标志创建空的图像实例。
VPIStatus vpiImageUnlock(VPIImage img)
释放图像对象的锁。
@ VPI_IMAGE_BUFFER_HOST_PITCH_LINEAR
主机可访问,平面采用 pitch-linear 内存布局。
VPIStatus vpiImageCreateWrapperOpenCVMat(const cv::Mat &mat, VPIImageFormat fmt, uint64_t flags, VPIImage *img)
使用给定的图像格式将 cv::Mat 封装到 VPIImage 中。
VPIStatus vpiSubmitRescale(VPIStream stream, uint64_t backend, VPIImage input, VPIImage output, VPIInterpolationType interpolationType, VPIBorderExtension border, uint64_t flags)
更改 2D 图像的大小和比例。
struct VPIStreamImpl * VPIStream
流的句柄。
VPIStatus vpiStreamSync(VPIStream stream)
阻塞调用线程,直到此流队列中的所有提交命令完成(队列为空)。
void vpiStreamDestroy(VPIStream stream)
销毁流实例并释放所有硬件资源。
VPIStatus vpiStreamCreate(uint64_t flags, VPIStream *stream)
创建流实例。
@ VPI_BACKEND_CUDA
CUDA 后端。
@ VPI_BORDER_CLAMP
无限重复边界像素。
@ VPI_LOCK_READ
仅锁定内存以进行读取。