29 #include <opencv2/core/version.hpp>
30 #include <opencv2/imgproc/imgproc.hpp>
31 #if CV_MAJOR_VERSION >= 3
32 # include <opencv2/imgcodecs.hpp>
34 # 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[])
81 throw std::runtime_error(std::string(
"Usage: ") + argv[0] +
" <cpu|pva|cuda> <input image>");
84 std::string strBackend = argv[1];
85 std::string strInputFileName = argv[2];
88 cvImage = cv::imread(strInputFileName);
91 throw std::runtime_error(
"Can't open '" + strInputFileName +
"'");
101 if (strBackend ==
"cpu")
105 else if (strBackend ==
"cuda")
109 else if (strBackend ==
"pva")
115 throw std::runtime_error(
"Backend '" + strBackend +
160 "' not recognized, it must be either cpu, cuda or pva.");
135 float kernel[3 * 3] = {1, 0, -1, 0, 0, 0, -1, 0, 1};
156 imwrite(
"edges_" + strBackend +
".png", cvOut);
162 catch (std::exception &e)
164 std::cerr << e.what() << std::endl;
用于处理 VPI 与 OpenCV 互操作性的函数。
VPIStatus vpiSubmitConvolution(VPIStream stream, uint64_t backend, VPIImage input, VPIImage output, const float *kernelData, int32_t kernelWidth, int32_t kernelHeight, VPIBorderExtension border)
对图像运行通用的 2D 卷积。
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 中。
struct VPIStreamImpl * VPIStream
流的句柄。
VPIStatus vpiStreamSync(VPIStream stream)
阻塞调用线程,直到此流队列中所有提交的命令都完成(队列为空)。
void vpiStreamDestroy(VPIStream stream)
销毁流实例并释放所有硬件资源。
VPIStatus vpiStreamCreate(uint64_t flags, VPIStream *stream)
创建流实例。
@ VPI_BACKEND_CUDA
CUDA 后端。
@ VPI_BORDER_ZERO
图像外部的所有像素都被视为零。
@ VPI_LOCK_READ
仅锁定内存以进行读取。