VPI - Vision Programming Interface

2.0 Release

Stereo Disparity

Overview

The Stereo Disparity application receives left and right stereo pair images and returns the disparity between them, which is a function of image depth. The result is saved as an image file to disk. If available, it'll also output the corresponding confidence map.

Instructions

The command line parameters are:

<backend> <left image> <right image>

where

  • backend: either cpu, cuda, pva, ofa, ofa-pva-vic or pva-nvenc-vic; it defines the backend that will perform the processing. pva-nvenc-vic, ofa-pva-vic and cuda allow output of the confidence map in addition to the disparity.
  • left image: left input image of a rectified stereo pair, it accepts png, jpeg and possibly others.
  • right image: right input image of a stereo pair.

Here's one example:

  • C++
    ./vpi_sample_02_stereo_disparity cuda ../assets/chair_stereo_left.png ../assets/chair_stereo_right.png
  • Python
    python3 main.py cuda ../assets/chair_stereo_left.png ../assets/chair_stereo_right.png

This is using the CUDA backend and the provided sample images. You can try with other stereo pair images, respecting the constraints imposed by the algorithm.

Results

Left input image Right input image
Stereo disparity Confidence map

Source Code

For convenience, here's the code that is also installed in the samples directory.

Language:
27 import cv2
28 import sys
29 import vpi
30 import numpy as np
31 from PIL import Image
32 from argparse import ArgumentParser
33 
34 # ----------------------------
35 # Parse command line arguments
36 
37 parser = ArgumentParser()
38 parser.add_argument('backend', choices=['cpu','cuda','pva','ofa','ofa-pva-vic','pva-nvenc-vic'],
39  help='Backend to be used for processing')
40 
41 parser.add_argument('left',
42  help='Rectified left input image from a stereo pair')
43 
44 parser.add_argument('right',
45  help='Rectified right input image from a stereo pair')
46 
47 args = parser.parse_args()
48 
49 # pixel value scaling factor when loading input
50 scale=1
51 
52 if args.backend == 'cpu':
53  backend = vpi.Backend.CPU
54 elif args.backend == 'cuda':
55  backend = vpi.Backend.CUDA
56 elif args.backend == 'pva':
57  backend = vpi.Backend.PVA
58 elif args.backend == 'ofa':
59  backend = vpi.Backend.OFA
60 elif args.backend == 'ofa-pva-vic':
61  backend = vpi.Backend.OFA|vpi.Backend.PVA|vpi.Backend.VIC
62 else:
63  assert args.backend == 'pva-nvenc-vic'
64  backend = vpi.Backend.PVA|vpi.Backend.NVENC|vpi.Backend.VIC
65 
66  # For PVA+NVENC+VIC mode, 16bpp input must be MSB-aligned, which
67  # is equivalent to say that it is Q8.8 (fixed-point, 8 decimals).
68  scale=256
69 
70 # Streams for left and right independent pre-processing
71 streamLeft = vpi.Stream()
72 streamRight = vpi.Stream()
73 
74 # --------------------------------------------------------------
75 # Load input into a vpi.Image and convert it to grayscale, 16bpp
76 with vpi.Backend.CUDA:
77  with streamLeft:
78  left = vpi.asimage(np.asarray(Image.open(args.left))).convert(vpi.Format.Y16_ER, scale=scale)
79  with streamRight:
80  right = vpi.asimage(np.asarray(Image.open(args.right))).convert(vpi.Format.Y16_ER, scale=scale)
81 
82 # --------------------------------------------------------------
83 # Preprocess input
84 
85 # Block linear format is needed for pva-nvenc-vic pipeline and ofa backend
86 # Currently we can only convert to block-linear using VIC backend.
87 # The input also must be 1080p
88 if args.backend == 'pva-nvenc-vic':
89  with vpi.Backend.VIC:
90  with streamLeft:
91  left = left.convert(vpi.Format.Y16_ER_BL).rescale((1920,1080))
92  with streamRight:
93  right = right.convert(vpi.Format.Y16_ER_BL).rescale((1920,1080))
94  maxDisparity = 256
95 elif 'ofa' in args.backend:
96  with vpi.Backend.VIC:
97  with streamLeft:
98  left = left.convert(vpi.Format.Y16_ER_BL).rescale((1920,1080))
99  with streamRight:
100  right = right.convert(vpi.Format.Y16_ER_BL).rescale((1920,1080))
101  maxDisparity = 128
102 else:
103  maxDisparity = 64
104 
105 downscale = 1
106 
107 if args.backend == 'cuda' or args.backend == 'ofa-pva-vic':
108  # only OFA-PVA-VIC and CUDA have confidence map
109  confidenceMap = vpi.Image(left.size, vpi.Format.U16)
110 elif args.backend == 'pva-nvenc-vic':
111  # PVA-NVENC-VIC only supports 1/4 of the input size
112  downscale = 4
113  confidenceMap = vpi.Image((left.size[0] // downscale, left.size[1] // downscale), vpi.Format.U16)
114 else:
115  confidenceMap = None
116 
117 # Use stream left to consolidate actual stereo processing
118 streamStereo = streamLeft
119 
120 # ---------------------------------------------
121 # Estimate stereo disparity
122 with streamStereo, backend:
123  disparity = vpi.stereodisp(left, right, downscale = downscale, out_confmap=confidenceMap, window=5, maxdisp=maxDisparity)
124 
125 # ---------------------------------------------
126 # Postprocess results and save them to disk
127 with streamStereo, vpi.Backend.CUDA:
128  # Since OFA outputs disparities in block-linear format, we must convert them to
129  # pitch-linear for consistency with the other backends.
130  if args.backend == 'ofa':
131  disparity = disparity.convert(vpi.Format.S16, backend = vpi.Backend.VIC)
132 
133  # Scale disparity and confidence map so that values like between 0 and 255.
134 
135  # Disparities are in Q10.5 format, so to map it to float, it gets
136  # divided by 32. Then the resulting disparity range, from 0 to
137  # stereo.maxDisparity gets mapped to 0-255 for proper output.
138  disparity = disparity.convert(vpi.Format.U8, scale=255.0/(32*maxDisparity))
139 
140  # Apply JET colormap to turn the disparities into color, reddish hues
141  # represent objects closer to the camera, blueish are farther away.
142  disparityColor = cv2.applyColorMap(disparity.cpu(), cv2.COLORMAP_JET)
143 
144  # Converts to RGB for output with PIL
145  disparityColor = cv2.cvtColor(disparityColor, cv2.COLOR_BGR2RGB)
146 
147  if confidenceMap:
148  confidenceMap = confidenceMap.convert(vpi.Format.U8, scale=255.0/65535)
149 
150  # When pixel confidence is 0, its color in the disparity
151  # output is black.
152  mask = cv2.threshold(confidenceMap.cpu(), 1, 255, cv2.THRESH_BINARY)[1]
153  mask = cv2.cvtColor(mask, cv2.COLOR_GRAY2BGR)
154  disparityColor = cv2.bitwise_and(disparityColor, mask)
155 
156 # -------------------
157 # Save result to disk
158 
159 Image.fromarray(disparityColor).save('disparity_python'+str(sys.version_info[0])+'_'+args.backend+'.png')
160 
161 if confidenceMap:
162  Image.fromarray(confidenceMap.cpu()).save('confidence_python'+str(sys.version_info[0])+'_'+args.backend+'.png')
29 #include <opencv2/core/version.hpp>
30 #if CV_MAJOR_VERSION >= 3
31 # include <opencv2/imgcodecs.hpp>
32 #else
33 # include <opencv2/contrib/contrib.hpp> // for colormap
34 # include <opencv2/highgui/highgui.hpp>
35 #endif
36 
37 #include <opencv2/imgproc/imgproc.hpp>
38 #include <vpi/OpenCVInterop.hpp>
39 
40 #include <vpi/Image.h>
41 #include <vpi/Status.h>
42 #include <vpi/Stream.h>
44 #include <vpi/algo/Rescale.h>
46 
47 #include <cstring> // for memset
48 #include <iostream>
49 #include <sstream>
50 
51 #define CHECK_STATUS(STMT) \
52  do \
53  { \
54  VPIStatus status = (STMT); \
55  if (status != VPI_SUCCESS) \
56  { \
57  char buffer[VPI_MAX_STATUS_MESSAGE_LENGTH]; \
58  vpiGetLastStatusMessage(buffer, sizeof(buffer)); \
59  std::ostringstream ss; \
60  ss << vpiStatusGetName(status) << ": " << buffer; \
61  throw std::runtime_error(ss.str()); \
62  } \
63  } while (0);
64 
65 int main(int argc, char *argv[])
66 {
67  // OpenCV image that will be wrapped by a VPIImage.
68  // Define it here so that it's destroyed *after* wrapper is destroyed
69  cv::Mat cvImageLeft, cvImageRight;
70 
71  // VPI objects that will be used
72  VPIImage inLeft = NULL;
73  VPIImage inRight = NULL;
74  VPIImage tmpLeft = NULL;
75  VPIImage tmpRight = NULL;
76  VPIImage stereoLeft = NULL;
77  VPIImage stereoRight = NULL;
78  VPIImage disparity = NULL;
79  VPIImage confidenceMap = NULL;
80  VPIStream stream = NULL;
81  VPIPayload stereo = NULL;
82 
83  int retval = 0;
84 
85  try
86  {
87  // =============================
88  // Parse command line parameters
89 
90  if (argc != 4)
91  {
92  throw std::runtime_error(std::string("Usage: ") + argv[0] +
93  " <cpu|pva|cuda|pva-nvenc-vic|ofa|ofa-pva-vic> <left image> <right image>");
94  }
95 
96  std::string strBackend = argv[1];
97  std::string strLeftFileName = argv[2];
98  std::string strRightFileName = argv[3];
99 
100  uint64_t backends;
101 
102  if (strBackend == "cpu")
103  {
104  backends = VPI_BACKEND_CPU;
105  }
106  else if (strBackend == "cuda")
107  {
108  backends = VPI_BACKEND_CUDA;
109  }
110  else if (strBackend == "pva")
111  {
112  backends = VPI_BACKEND_PVA;
113  }
114  else if (strBackend == "pva-nvenc-vic")
115  {
117  }
118  else if (strBackend == "ofa")
119  {
120  backends = VPI_BACKEND_OFA;
121  }
122  else if (strBackend == "ofa-pva-vic")
123  {
125  }
126  else
127  {
128  throw std::runtime_error(
129  "Backend '" + strBackend +
130  "' not recognized, it must be either cpu, cuda, pva, ofa, ofa-pva-vic or pva-nvenc-vic.");
131  }
132 
133  // =====================
134  // Load the input images
135  cvImageLeft = cv::imread(strLeftFileName);
136  if (cvImageLeft.empty())
137  {
138  throw std::runtime_error("Can't open '" + strLeftFileName + "'");
139  }
140 
141  cvImageRight = cv::imread(strRightFileName);
142  if (cvImageRight.empty())
143  {
144  throw std::runtime_error("Can't open '" + strRightFileName + "'");
145  }
146 
147  // =================================
148  // Allocate all VPI resources needed
149 
150  int32_t inputWidth = cvImageLeft.cols;
151  int32_t inputHeight = cvImageLeft.rows;
152 
153  // Create the stream that will be used for processing.
154  CHECK_STATUS(vpiStreamCreate(0, &stream));
155 
156  // We now wrap the loaded images into a VPIImage object to be used by VPI.
157  // VPI won't make a copy of it, so the original image must be in scope at all times.
158  CHECK_STATUS(vpiImageCreateWrapperOpenCVMat(cvImageLeft, 0, &inLeft));
159  CHECK_STATUS(vpiImageCreateWrapperOpenCVMat(cvImageRight, 0, &inRight));
160 
161  // Format conversion parameters needed for input pre-processing
162  VPIConvertImageFormatParams convParams;
163  CHECK_STATUS(vpiInitConvertImageFormatParams(&convParams));
164 
165  // Set algorithm parameters to be used. Only values what differs from defaults will be overwritten.
167  CHECK_STATUS(vpiInitStereoDisparityEstimatorCreationParams(&stereoParams));
168 
169  // Default format and size for inputs and outputs
171  VPIImageFormat disparityFormat = VPI_IMAGE_FORMAT_S16;
172 
173  int stereoWidth = inputWidth;
174  int stereoHeight = inputHeight;
175  int outputWidth = inputWidth;
176  int outputHeight = inputHeight;
177 
178  // Override some backend-dependent parameters
179  if (strBackend == "pva-nvenc-vic")
180  {
181  // Input and output width and height has to be 1920x1080 in block-linear format for pva-nvenc-vic pipeline
182  stereoFormat = VPI_IMAGE_FORMAT_Y16_ER_BL;
183  stereoWidth = 1920;
184  stereoHeight = 1080;
185 
186  // For PVA+NVENC+VIC mode, 16bpp input must be MSB-aligned, which
187  // is equivalent to say that it is Q8.8 (fixed-point, 8 decimals).
188  convParams.scale = 256;
189 
190  // Maximum disparity is fixed to 256.
191  stereoParams.maxDisparity = 256;
192 
193  // pva-nvenc-vic pipeline only supports downscaleFactor = 4
194  stereoParams.downscaleFactor = 4;
195  outputWidth = stereoWidth / stereoParams.downscaleFactor;
196  outputHeight = stereoHeight / stereoParams.downscaleFactor;
197  }
198  else if (strBackend.find("ofa") != std::string::npos)
199  {
200  // Implementations using OFA require BL input
201  stereoFormat = VPI_IMAGE_FORMAT_Y16_ER_BL;
202 
203  if (strBackend == "ofa")
204  {
205  disparityFormat = VPI_IMAGE_FORMAT_S16_BL;
206  }
207 
208  // Output width including downscaleFactor must be at least max(64, maxDisparity/downscaleFactor) when OFA+PVA+VIC are used
209  if (strBackend.find("pva") != std::string::npos)
210  {
211  int downscaledWidth = (inputWidth + stereoParams.downscaleFactor - 1) / stereoParams.downscaleFactor;
212  int minWidth = std::max(stereoParams.maxDisparity / stereoParams.downscaleFactor, downscaledWidth);
213  outputWidth = std::max(64, minWidth);
214  outputHeight = (inputHeight * stereoWidth) / inputWidth;
215  stereoWidth = outputWidth * stereoParams.downscaleFactor;
216  stereoHeight = outputHeight * stereoParams.downscaleFactor;
217  }
218 
219  // Maximum disparity can be either 128 or 256
220  stereoParams.maxDisparity = 128;
221  }
222  else if (strBackend == "pva")
223  {
224  // PVA requires that input and output resolution is 480x270
225  stereoWidth = outputWidth = 480;
226  stereoHeight = outputHeight = 270;
227 
228  // maxDisparity must be 64
229  stereoParams.maxDisparity = 64;
230  }
231 
232  // Create the payload for Stereo Disparity algorithm.
233  // Payload is created before the image objects so that non-supported backends can be trapped with an error.
234  CHECK_STATUS(vpiCreateStereoDisparityEstimator(backends, stereoWidth, stereoHeight, stereoFormat, &stereoParams,
235  &stereo));
236 
237  // Create the image where the disparity map will be stored.
238  CHECK_STATUS(vpiImageCreate(outputWidth, outputHeight, disparityFormat, 0, &disparity));
239 
240  // Create the input stereo images
241  CHECK_STATUS(vpiImageCreate(stereoWidth, stereoHeight, stereoFormat, 0, &stereoLeft));
242  CHECK_STATUS(vpiImageCreate(stereoWidth, stereoHeight, stereoFormat, 0, &stereoRight));
243 
244  // Create some temporary images, and the confidence image if the backend can support it
245  if (strBackend == "pva-nvenc-vic")
246  {
247  // Need an temporary image to convert BGR8 input from OpenCV into pixel-linear 16bpp grayscale.
248  // We can't convert it directly to block-linear since CUDA backend doesn't support it, and
249  // VIC backend doesn't support BGR8 inputs.
250  CHECK_STATUS(vpiImageCreate(inputWidth, inputHeight, VPI_IMAGE_FORMAT_Y16_ER, 0, &tmpLeft));
251  CHECK_STATUS(vpiImageCreate(inputWidth, inputHeight, VPI_IMAGE_FORMAT_Y16_ER, 0, &tmpRight));
252 
253  // confidence map is needed for pva-nvenc-vic pipeline
254  CHECK_STATUS(vpiImageCreate(outputWidth, outputHeight, VPI_IMAGE_FORMAT_U16, 0, &confidenceMap));
255  }
256  else if (strBackend.find("ofa") != std::string::npos)
257  {
258  // OFA also needs a temporary buffer for format conversion
259  CHECK_STATUS(vpiImageCreate(inputWidth, inputHeight, VPI_IMAGE_FORMAT_Y16_ER, 0, &tmpLeft));
260  CHECK_STATUS(vpiImageCreate(inputWidth, inputHeight, VPI_IMAGE_FORMAT_Y16_ER, 0, &tmpRight));
261 
262  if (strBackend.find("pva") != std::string::npos)
263  {
264  // confidence map is supported by OFA+PVA
265  CHECK_STATUS(vpiImageCreate(outputWidth, outputHeight, VPI_IMAGE_FORMAT_U16, 0, &confidenceMap));
266  }
267  }
268  else if (strBackend == "pva")
269  {
270  // PVA also needs a temporary buffer for format conversion and rescaling
271  CHECK_STATUS(vpiImageCreate(inputWidth, inputHeight, stereoFormat, 0, &tmpLeft));
272  CHECK_STATUS(vpiImageCreate(inputWidth, inputHeight, stereoFormat, 0, &tmpRight));
273  }
274  else if (strBackend == "cuda")
275  {
276  CHECK_STATUS(vpiImageCreate(inputWidth, inputHeight, VPI_IMAGE_FORMAT_U16, 0, &confidenceMap));
277  }
278 
279  // ================
280  // Processing stage
281 
282  // -----------------
283  // Pre-process input
284  if (strBackend == "pva-nvenc-vic" || strBackend == "pva" || strBackend == "ofa" || strBackend == "ofa-pva-vic")
285  {
286  // Convert opencv input to temporary grayscale format using CUDA
287  CHECK_STATUS(vpiSubmitConvertImageFormat(stream, VPI_BACKEND_CUDA, inLeft, tmpLeft, &convParams));
288  CHECK_STATUS(vpiSubmitConvertImageFormat(stream, VPI_BACKEND_CUDA, inRight, tmpRight, &convParams));
289 
290  // Do both scale and final image format conversion on VIC.
291  CHECK_STATUS(
292  vpiSubmitRescale(stream, VPI_BACKEND_VIC, tmpLeft, stereoLeft, VPI_INTERP_LINEAR, VPI_BORDER_CLAMP, 0));
293  CHECK_STATUS(vpiSubmitRescale(stream, VPI_BACKEND_VIC, tmpRight, stereoRight, VPI_INTERP_LINEAR,
294  VPI_BORDER_CLAMP, 0));
295  }
296  else
297  {
298  // Convert opencv input to grayscale format using CUDA
299  CHECK_STATUS(vpiSubmitConvertImageFormat(stream, VPI_BACKEND_CUDA, inLeft, stereoLeft, &convParams));
300  CHECK_STATUS(vpiSubmitConvertImageFormat(stream, VPI_BACKEND_CUDA, inRight, stereoRight, &convParams));
301  }
302 
303  // ------------------------------
304  // Do stereo disparity estimation
305 
306  // Submit it with the input and output images
307  CHECK_STATUS(vpiSubmitStereoDisparityEstimator(stream, backends, stereo, stereoLeft, stereoRight, disparity,
308  confidenceMap, NULL));
309 
310  // Wait until the algorithm finishes processing
311  CHECK_STATUS(vpiStreamSync(stream));
312 
313  // ========================================
314  // Output pre-processing and saving to disk
315  // Lock output to retrieve its data on cpu memory
316  VPIImageData data;
317  CHECK_STATUS(vpiImageLockData(disparity, VPI_LOCK_READ, VPI_IMAGE_BUFFER_HOST_PITCH_LINEAR, &data));
318 
319  // Make an OpenCV matrix out of this image
320  cv::Mat cvDisparity;
321  CHECK_STATUS(vpiImageDataExportOpenCVMat(data, &cvDisparity));
322 
323  // Scale result and write it to disk. Disparities are in Q10.5 format,
324  // so to map it to float, it gets divided by 32. Then the resulting disparity range,
325  // from 0 to stereo.maxDisparity gets mapped to 0-255 for proper output.
326  cvDisparity.convertTo(cvDisparity, CV_8UC1, 255.0 / (32 * stereoParams.maxDisparity), 0);
327 
328  // Apply JET colormap to turn the disparities into color, reddish hues
329  // represent objects closer to the camera, blueish are farther away.
330  cv::Mat cvDisparityColor;
331  applyColorMap(cvDisparity, cvDisparityColor, cv::COLORMAP_JET);
332 
333  // Done handling output, don't forget to unlock it.
334  CHECK_STATUS(vpiImageUnlock(disparity));
335 
336  // If we have a confidence map,
337  if (confidenceMap)
338  {
339  // Write it to disk too.
340  //
341  VPIImageData data;
342  CHECK_STATUS(vpiImageLockData(confidenceMap, VPI_LOCK_READ, VPI_IMAGE_BUFFER_HOST_PITCH_LINEAR, &data));
343 
344  cv::Mat cvConfidence;
345  CHECK_STATUS(vpiImageDataExportOpenCVMat(data, &cvConfidence));
346 
347  // Confidence map varies from 0 to 65535, we scale it to
348  // [0-255].
349  cvConfidence.convertTo(cvConfidence, CV_8UC1, 255.0 / 65535, 0);
350  imwrite("confidence_" + strBackend + ".png", cvConfidence);
351 
352  CHECK_STATUS(vpiImageUnlock(confidenceMap));
353 
354  // When pixel confidence is 0, its color in the disparity
355  // output is black.
356  cv::Mat cvMask;
357  threshold(cvConfidence, cvMask, 1, 255, cv::THRESH_BINARY);
358  cvtColor(cvMask, cvMask, cv::COLOR_GRAY2BGR);
359  bitwise_and(cvDisparityColor, cvMask, cvDisparityColor);
360  }
361 
362  imwrite("disparity_" + strBackend + ".png", cvDisparityColor);
363  }
364  catch (std::exception &e)
365  {
366  std::cerr << e.what() << std::endl;
367  retval = 1;
368  }
369 
370  // ========
371  // Clean up
372 
373  // Destroying stream first makes sure that all work submitted to
374  // it is finished.
375  vpiStreamDestroy(stream);
376 
377  // Only then we can destroy the other objects, as we're sure they
378  // aren't being used anymore.
379 
380  vpiImageDestroy(inLeft);
381  vpiImageDestroy(inRight);
382  vpiImageDestroy(tmpLeft);
383  vpiImageDestroy(tmpRight);
384  vpiImageDestroy(stereoLeft);
385  vpiImageDestroy(stereoRight);
386  vpiImageDestroy(confidenceMap);
387  vpiImageDestroy(disparity);
388  vpiPayloadDestroy(stereo);
389 
390  return retval;
391 }
Declares functions that handle image format conversion.
#define VPI_IMAGE_FORMAT_S16_BL
Single plane with one block-linear 16-bit signed integer channel.
Definition: ImageFormat.h:121
#define VPI_IMAGE_FORMAT_U16
Single plane with one 16-bit unsigned integer channel.
Definition: ImageFormat.h:109
#define VPI_IMAGE_FORMAT_S16
Single plane with one 16-bit signed integer channel.
Definition: ImageFormat.h:118
#define VPI_IMAGE_FORMAT_Y16_ER_BL
Single plane with one block-linear 16-bit unsigned integer channel with full-range luma (grayscale) i...
Definition: ImageFormat.h:176
#define VPI_IMAGE_FORMAT_Y16_ER
Single plane with one pitch-linear 16-bit unsigned integer channel with full-range luma (grayscale) i...
Definition: ImageFormat.h:171
Functions and structures for dealing with VPI images.
Functions for handling OpenCV interoperability with VPI.
Declares functions that implement the Rescale algorithm.
Declaration of VPI status codes handling functions.
Declares functions that implement stereo disparity estimation algorithms.
Declares functions dealing with VPI streams.
float scale
Scaling factor.
VPIStatus vpiInitConvertImageFormatParams(VPIConvertImageFormatParams *params)
Initialize VPIConvertImageFormatParams with default values.
VPIStatus vpiSubmitConvertImageFormat(VPIStream stream, uint64_t backend, VPIImage input, VPIImage output, const VPIConvertImageFormatParams *params)
Converts the image contents to the desired format, with optional scaling and offset.
Parameters for customizing image format conversion.
uint64_t VPIImageFormat
Pre-defined image formats.
Definition: ImageFormat.h:94
void vpiImageDestroy(VPIImage img)
Destroy an image instance.
struct VPIImageImpl * VPIImage
A handle to an image.
Definition: Types.h:256
VPIStatus vpiImageLockData(VPIImage img, VPILockMode mode, VPIImageBufferType bufType, VPIImageData *data)
Acquires the lock on an image object and returns the image contents.
VPIStatus vpiImageCreate(int32_t width, int32_t height, VPIImageFormat fmt, uint64_t flags, VPIImage *img)
Create an empty image instance with the specified flags.
VPIStatus vpiImageUnlock(VPIImage img)
Releases the lock on an image object.
@ VPI_IMAGE_BUFFER_HOST_PITCH_LINEAR
Host-accessible with planes in pitch-linear memory layout.
Definition: Image.h:172
Stores information about image characteristics and content.
Definition: Image.h:230
VPIStatus vpiImageCreateWrapperOpenCVMat(const cv::Mat &mat, VPIImageFormat fmt, uint64_t flags, VPIImage *img)
Wraps a cv::Mat in an VPIImage with the given image format.
VPIStatus vpiImageDataExportOpenCVMat(const VPIImageData &imgData, cv::Mat *mat)
Fills an existing cv::Mat with data from VPIImageData coming from a locked VPIImage.
struct VPIPayloadImpl * VPIPayload
A handle to an algorithm payload.
Definition: Types.h:268
void vpiPayloadDestroy(VPIPayload payload)
Deallocates the payload object and all associated resources.
VPIStatus vpiSubmitRescale(VPIStream stream, uint64_t backend, VPIImage input, VPIImage output, VPIInterpolationType interpolationType, VPIBorderExtension border, uint64_t flags)
Changes the size and scale of a 2D image.
int32_t maxDisparity
Maximum disparity for matching search.
int32_t downscaleFactor
Output's downscale factor with respect to the input's resolution.
VPIStatus vpiInitStereoDisparityEstimatorCreationParams(VPIStereoDisparityEstimatorCreationParams *params)
Initializes VPIStereoDisparityEstimatorCreationParams with default values.
VPIStatus vpiCreateStereoDisparityEstimator(uint64_t backends, int32_t imageWidth, int32_t imageHeight, VPIImageFormat inputFormat, const VPIStereoDisparityEstimatorCreationParams *params, VPIPayload *payload)
Creates payload for vpiSubmitStereoDisparityEstimator.
VPIStatus vpiSubmitStereoDisparityEstimator(VPIStream stream, uint64_t backend, VPIPayload payload, VPIImage left, VPIImage right, VPIImage disparity, VPIImage confidenceMap, const VPIStereoDisparityEstimatorParams *params)
Runs stereo processing on a pair of images and outputs a disparity map.
Structure that defines the parameters for vpiCreateStereoDisparityEstimator.
struct VPIStreamImpl * VPIStream
A handle to a stream.
Definition: Types.h:250
VPIStatus vpiStreamSync(VPIStream stream)
Blocks the calling thread until all submitted commands in this stream queue are done (queue is empty)...
void vpiStreamDestroy(VPIStream stream)
Destroy a stream instance and deallocate all HW resources.
VPIStatus vpiStreamCreate(uint64_t flags, VPIStream *stream)
Create a stream instance.
@ VPI_BACKEND_CUDA
CUDA backend.
Definition: Types.h:93
@ VPI_BACKEND_PVA
PVA backend.
Definition: Types.h:94
@ VPI_BACKEND_NVENC
NVENC backend.
Definition: Types.h:96
@ VPI_BACKEND_OFA
OFA backend.
Definition: Types.h:97
@ VPI_BACKEND_VIC
VIC backend.
Definition: Types.h:95
@ VPI_BACKEND_CPU
CPU backend.
Definition: Types.h:92
@ VPI_BORDER_CLAMP
Border pixels are repeated indefinitely.
Definition: Types.h:279
@ VPI_INTERP_LINEAR
Linear interpolation.
Definition: Interpolation.h:93
@ VPI_LOCK_READ
Lock memory only for reading.
Definition: Types.h:435