VPI - Vision Programming Interface

0.4.4 Release

KLT Bounding Box Tracker

Overview

This application tracks bounding boxes on an input video, draws the frames on each frame and saves them to disk. The user can define what backend will be used for processing.

Note
The output will be in grayscale as the algorithm currently only supports grayrescales.

This sample shows the following:

  • Creating and destroying a VPI stream.
  • Wrapping an image hosted on CPU (input frame) to be used by VPI.
  • Wrapping an array hosted on CPU (input bounding boxes) to be used by VPI.
  • Creating a VPI-managed 2D image where output will be written to.
  • Use the multi-frame KLT Bounding Box Tracker algorithm.
  • Simple stream synchronization.
  • Array locking to access its contents from CPU side.
  • Error handling.
  • Environment clean up using user-defined context.

Instructions

The usage is:

./vpi_sample_06_klt_tracker <backend> <input video> <input bboxes> <output frames>

where

  • backend: either cpu, cuda or pva; it defines the backend that will perform the processing.
  • input video: input video file name, it accepts all video types that OpenCV's cv::VideoCapture accepts.
  • input bboxes: file with input bounding boxes and in what frame they appear. The file is composed of multiple lines with the following format:
       <frame> <bbox_x> <bbox_y> <bbox_width> <bbox_height>
    It's important that the lines are sorted with frames in ascending order.
  • output frames: the file name that will be used for the output frames. Example: output.png will generate frames output_0000.png, output_0001.png, output_0002.png, and so on.

Here's one example:

./vpi_sample_06_klt_tracker cuda ../assets/dashcam.mp4 ../assets/dashcam_bboxes.txt frame.png

This is using the CUDA backend and one of the provided sample videos and bounding boxes.

Results

Frame 0445Frame 0465

Source code

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

1 /*
2 * Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of NVIDIA CORPORATION nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
24 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28 
29 #include <opencv2/core/version.hpp>
30 #if CV_MAJOR_VERSION >= 3
31 # include <opencv2/imgcodecs.hpp>
32 # include <opencv2/videoio.hpp>
33 #else
34 # include <opencv2/highgui/highgui.hpp>
35 #endif
36 
37 #include <opencv2/imgproc/imgproc.hpp>
38 
39 #include <vpi/Array.h>
40 #include <vpi/Context.h>
41 #include <vpi/Image.h>
42 #include <vpi/Status.h>
43 #include <vpi/Stream.h>
45 
46 #include <cstring> // for memset
47 #include <fstream>
48 #include <iostream>
49 #include <map>
50 #include <sstream>
51 #include <vector>
52 
53 #define CHECK_STATUS(STMT) \
54  do \
55  { \
56  VPIStatus status = (STMT); \
57  if (status != VPI_SUCCESS) \
58  { \
59  char buffer[VPI_MAX_STATUS_MESSAGE_LENGTH]; \
60  vpiGetLastStatusMessage(buffer, sizeof(buffer)); \
61  std::ostringstream ss; \
62  ss << vpiStatusGetName(status) << ": " << buffer; \
63  throw std::runtime_error(ss.str()); \
64  } \
65  } while (0);
66 
67 // Utility function to wrap a cv::Mat into a VPIImage. If 'image'
68 // is NULL, it'll create the wrapper, or else, it'll update 'image's wrapped
69 // frame with the new frame, without allocating memory.
70 static VPIImage ToVPIImage(VPIImage image, const cv::Mat &frame)
71 {
72  VPIImageData imgData;
73  memset(&imgData, 0, sizeof(imgData));
74 
75  switch (frame.type())
76  {
77  case CV_16U:
78  imgData.type = VPI_IMAGE_FORMAT_U16;
79  break;
80  case CV_8U:
81  imgData.type = VPI_IMAGE_FORMAT_U8;
82  break;
83  default:
84  throw std::runtime_error("Frame type not supported");
85  }
86 
87  // First fill VPIImageData with the, well, image data...
88  imgData.numPlanes = 1;
89  imgData.planes[0].width = frame.cols;
90  imgData.planes[0].height = frame.rows;
91  imgData.planes[0].pitchBytes = frame.step[0];
92  imgData.planes[0].data = frame.data;
93 
94  if (image == nullptr)
95  {
96  // Now create a VPIImage that wraps it.
97  CHECK_STATUS(vpiImageCreateHostMemWrapper(&imgData, 0, &image));
98  }
99  else
100  {
101  // reuse existing VPIImage wrapper to wrap the new frame.
102  CHECK_STATUS(vpiImageSetWrappedHostMem(image, &imgData));
103  }
104  return image;
105 }
106 
107 // Utility to draw the bounding boxes into an image and save it to disk.
108 static void SaveKLTBoxes(VPIImage img, VPIArray boxes, VPIArray preds, const std::string &filename, int frame)
109 {
110  // Convert img into a cv::Mat
111  cv::Mat out;
112  {
113  VPIImageData imgdata;
114  CHECK_STATUS(vpiImageLock(img, VPI_LOCK_READ, &imgdata));
115 
116  int cvtype;
117  switch (imgdata.type)
118  {
119  case VPI_IMAGE_FORMAT_U8:
120  cvtype = CV_8U;
121  break;
122 
123  case VPI_IMAGE_FORMAT_S8:
124  cvtype = CV_8S;
125  break;
126 
128  cvtype = CV_16UC1;
129  break;
130 
132  cvtype = CV_16SC1;
133  break;
134 
135  default:
136  throw std::runtime_error("Image type not supported");
137  }
138 
139  cv::Mat cvimg(imgdata.planes[0].height, imgdata.planes[0].width, cvtype, imgdata.planes[0].data,
140  imgdata.planes[0].pitchBytes);
141 
142  if (cvimg.type() == CV_16U)
143  {
144  cvimg.convertTo(out, CV_8U);
145  cvimg = out;
146  out = cv::Mat();
147  }
148 
149  cvtColor(cvimg, out, cv::COLOR_GRAY2BGR);
150 
151  CHECK_STATUS(vpiImageUnlock(img));
152  }
153 
154  // Now draw the bounding boxes.
155  VPIArrayData boxdata;
156  CHECK_STATUS(vpiArrayLock(boxes, VPI_LOCK_READ, &boxdata));
157 
158  VPIArrayData preddata;
159  CHECK_STATUS(vpiArrayLock(preds, VPI_LOCK_READ, &preddata));
160 
161  auto *pboxes = reinterpret_cast<VPIKLTTrackedBoundingBox *>(boxdata.data);
162  auto *ppreds = reinterpret_cast<VPIHomographyTransform2D *>(preddata.data);
163 
164  srand(0);
165  for (size_t i = 0; i < boxdata.size; ++i)
166  {
167  if (pboxes[i].trackingStatus == 1)
168  {
169  // So that the colors assigned to bounding boxes don't change
170  // when some bbox isn't tracked anymore.
171  rand();
172  rand();
173  rand();
174  continue;
175  }
176 
177  float x, y, w, h;
178  x = pboxes[i].bbox.xform.mat3[0][2] + ppreds[i].mat3[0][2];
179  y = pboxes[i].bbox.xform.mat3[1][2] + ppreds[i].mat3[1][2];
180  w = pboxes[i].bbox.width * pboxes[i].bbox.xform.mat3[0][0] * ppreds[i].mat3[0][0];
181  h = pboxes[i].bbox.height * pboxes[i].bbox.xform.mat3[1][1] * ppreds[i].mat3[1][1];
182 
183  rectangle(out, cv::Rect(x, y, w, h), cv::Scalar(rand() % 256, rand() % 256, rand() % 256), 2);
184  }
185 
186  CHECK_STATUS(vpiArrayUnlock(preds));
187  CHECK_STATUS(vpiArrayUnlock(boxes));
188 
189  // Create the output file name
190  std::string fname = filename;
191  int ext = fname.rfind('.');
192 
193  char buffer[512] = {};
194  snprintf(buffer, sizeof(buffer) - 1, "%s_%04d%s", fname.substr(0, ext).c_str(), frame, fname.substr(ext).c_str());
195 
196  // Finally, write frame to disk
197  if (!imwrite(buffer, out, {cv::IMWRITE_JPEG_QUALITY, 70}))
198  {
199  throw std::runtime_error("Can't write to " + std::string(buffer));
200  }
201 }
202 
203 int main(int argc, char *argv[])
204 {
205  // We'll create all our objects under this context, so that
206  // we don't have to track what objects to destroy. Just destroying
207  // the context will destroy all objects.
208  VPIContext ctx = nullptr;
209 
210  int retval = 0;
211 
212  try
213  {
214  if (argc != 5)
215  {
216  throw std::runtime_error(std::string("Usage: ") + argv[0] +
217  " <cpu|pva|cuda> <input_video> <bbox descr> <output>");
218  }
219 
220  std::string strBackend = argv[1];
221  std::string strInputVideo = argv[2];
222  std::string strInputBBoxes = argv[3];
223  std::string strOutputFiles = argv[4];
224 
225  // Load the input video
226  cv::VideoCapture invid;
227  if (!invid.open(strInputVideo))
228  {
229  throw std::runtime_error("Can't open '" + strInputVideo + "'");
230  }
231 
232  // Create our context.
233  CHECK_STATUS(vpiContextCreate(0, &ctx));
234 
235  // Activate it. From now on all created objects will be owned by it.
236  CHECK_STATUS(vpiContextSetCurrent(ctx));
237 
238  // Load the bounding boxes
239  // Format is: <frame number> <bbox_x> <bbox_y> <bbox_width> <bbox_height>
240  // Important assumption: bboxes must be sorted with increasing frame numbers.
241 
242  // Arrays that will store our input bboxes and predicted transform.
243  VPIArray inputBoxList, inputPredList;
244 
245  // These arrays will actually wrap these vectors.
246  std::vector<VPIKLTTrackedBoundingBox> bboxes;
247  std::vector<VPIHomographyTransform2D> preds;
248 
249  // Stores how many bboxes there are in each frame. Only
250  // stores when the bboxes count change.
251  std::map<int, size_t> bboxes_size_at_frame; // frame -> bbox count
252 
253  // PVA requires that array capacity is 128.
254  bboxes.reserve(128);
255  preds.reserve(128);
256 
257  // Read bounding boxes
258  {
259  std::ifstream in(strInputBBoxes);
260  if (!in)
261  {
262  throw std::runtime_error("Can't open '" + strInputBBoxes + "'");
263  }
264 
265  // For each bounding box,
266  int frame, x, y, w, h;
267  while (in >> frame >> x >> y >> w >> h)
268  {
269  if (bboxes.size() == 64)
270  {
271  throw std::runtime_error("Too many bounding boxes");
272  }
273 
274  // Convert the axis-aligned bounding box into our tracking
275  // structure.
276 
277  VPIKLTTrackedBoundingBox track = {};
278  // scale
279  track.bbox.xform.mat3[0][0] = 1;
280  track.bbox.xform.mat3[1][1] = 1;
281  // position
282  track.bbox.xform.mat3[0][2] = x;
283  track.bbox.xform.mat3[1][2] = y;
284  // must be 1
285  track.bbox.xform.mat3[2][2] = 1;
286 
287  track.bbox.width = w;
288  track.bbox.height = h;
289  track.trackingStatus = 0; // valid tracking
290  track.templateStatus = 1; // must update
291 
292  bboxes.push_back(track);
293 
294  // Identity predicted transform.
295  VPIHomographyTransform2D xform = {};
296  xform.mat3[0][0] = 1;
297  xform.mat3[1][1] = 1;
298  xform.mat3[2][2] = 1;
299  preds.push_back(xform);
300 
301  bboxes_size_at_frame[frame] = bboxes.size();
302  }
303 
304  if (!in && !in.eof())
305  {
306  throw std::runtime_error("Can't parse bounding boxes, stopped at bbox #" +
307  std::to_string(bboxes.size()));
308  }
309 
310  // Wrap the input arrays into VPIArray's
311  VPIArrayData data = {};
313  data.capacity = bboxes.capacity();
314  data.size = 0;
315  data.data = &bboxes[0];
316  CHECK_STATUS(vpiArrayCreateHostMemWrapper(&data, 0, &inputBoxList));
317 
319  data.data = &preds[0];
320  CHECK_STATUS(vpiArrayCreateHostMemWrapper(&data, 0, &inputPredList));
321  }
322 
323  // Now parse the backend
324  VPIBackend backendType;
325 
326  if (strBackend == "cpu")
327  {
328  backendType = VPI_BACKEND_CPU;
329  }
330  else if (strBackend == "cuda")
331  {
332  backendType = VPI_BACKEND_CUDA;
333  }
334  else if (strBackend == "pva")
335  {
336  backendType = VPI_BACKEND_PVA;
337  }
338  else
339  {
340  throw std::runtime_error("Backend '" + strBackend +
341  "' not recognized, it must be either cpu, cuda or pva.");
342  }
343 
344  // Create the stream for the given backend.
345  VPIStream stream;
346  CHECK_STATUS(vpiStreamCreate(backendType, &stream));
347 
348  // Helper function to fetch a frame from input
349  int nextFrame = 0;
350  auto fetchFrame = [&invid, &nextFrame, backendType]() {
351  cv::Mat frame;
352  if (!invid.read(frame))
353  {
354  return cv::Mat();
355  }
356 
357  // We only support grayscale inputs
358  if (frame.channels() == 3)
359  {
360  cvtColor(frame, frame, cv::COLOR_BGR2GRAY);
361  }
362 
363  if (backendType == VPI_BACKEND_PVA)
364  {
365  // PVA only supports 16-bit unsigned inputs,
366  // where each element is in 0-255 range, so
367  // no rescaling needed.
368  cv::Mat aux;
369  frame.convertTo(aux, CV_16U);
370  frame = aux;
371  }
372  else
373  {
374  assert(frame.type() == CV_8U);
375  }
376 
377  ++nextFrame;
378  return frame;
379  };
380 
381  // Fetch the first frame and wrap it into a VPIImage.
382  // Templates will be based on this frame.
383  cv::Mat cvTemplate = fetchFrame(), cvReference;
384  VPIImage imgTemplate = ToVPIImage(nullptr, cvTemplate);
385 
386  VPIImageFormat imgFormat;
387  CHECK_STATUS(vpiImageGetType(imgTemplate, &imgFormat));
388 
389  // Using this first frame's characteristics, create a KLT Bounding Box Tracker payload
390  VPIPayload klt;
391  CHECK_STATUS(vpiCreateKLTFeatureTracker(backendType, cvTemplate.cols, cvTemplate.rows, imgFormat, &klt));
392 
393  // Parameters we'll use. No need to change them on the fly, so just define them here.
394  VPIKLTFeatureTrackerParams params = {};
395  params.numberOfIterationsScaling = 20;
396  params.nccThresholdUpdate = 0.8f;
397  params.nccThresholdKill = 0.6f;
398  params.nccThresholdStop = 1.0f;
399  params.maxScaleChange = 0.2f;
400  params.maxTranslationChange = 1.5f;
402 
403  // Output array with estimated bbox for current frame.
404  VPIArray outputBoxList;
405  CHECK_STATUS(vpiArrayCreate(128, VPI_ARRAY_TYPE_KLT_TRACKED_BOUNDING_BOX, 0, &outputBoxList));
406 
407  // Output array with estimated transform of input bbox to match output bbox.
408  VPIArray outputEstimList;
409  CHECK_STATUS(vpiArrayCreate(128, VPI_ARRAY_TYPE_HOMOGRAPHY_TRANSFORM_2D, 0, &outputEstimList));
410 
411  // Reference (current) frame.
412  VPIImage imgReference = nullptr;
413 
414  size_t curNumBoxes = 0;
415 
416  do
417  {
418  size_t curFrame = nextFrame - 1;
419 
420  // Get the number of bounding boxes in current frame.
421  auto tmp = --bboxes_size_at_frame.upper_bound(curFrame);
422  size_t bbox_count = tmp->second;
423 
424  assert(bbox_count >= curNumBoxes && "input bounding boxes must be sorted by frame");
425 
426  // Does current frame have new bounding boxes?
427  if (curNumBoxes != bbox_count)
428  {
429  // Update the input array sizes, the new frame is already there as we populated
430  // these arrays with all input bounding boxes.
431  CHECK_STATUS(vpiArrayLock(inputBoxList, VPI_LOCK_READ_WRITE, nullptr));
432  CHECK_STATUS(vpiArraySetSize(inputBoxList, bbox_count));
433  CHECK_STATUS(vpiArrayUnlock(inputBoxList));
434 
435  CHECK_STATUS(vpiArrayLock(inputPredList, VPI_LOCK_READ_WRITE, nullptr));
436  CHECK_STATUS(vpiArraySetSize(inputPredList, bbox_count));
437  CHECK_STATUS(vpiArrayUnlock(inputPredList));
438 
439  for (size_t i = 0; i < bbox_count - curNumBoxes; ++i)
440  {
441  std::cout << curFrame << " -> new " << curNumBoxes + i << std::endl;
442  }
443  assert(bbox_count <= bboxes.capacity());
444  assert(bbox_count <= preds.capacity());
445 
446  curNumBoxes = bbox_count;
447  }
448 
449  // Save this frame to disk.
450  SaveKLTBoxes(imgTemplate, inputBoxList, inputPredList, strOutputFiles, curFrame);
451 
452  // Fetch a new frame
453  cvReference = fetchFrame();
454 
455  // Video ended?
456  if (cvReference.data == nullptr)
457  {
458  // Just end gracefully.
459  break;
460  }
461 
462  // Wrap frame into a VPIImage
463  imgReference = ToVPIImage(imgReference, cvReference);
464 
465  // Estimate the bounding boxes in current frame (reference) given their position in previous
466  // frame (template).
467  CHECK_STATUS(vpiSubmitKLTFeatureTracker(stream, klt, imgTemplate, inputBoxList, inputPredList, imgReference,
468  outputBoxList, outputEstimList, &params));
469 
470  // Wait for processing to finish.
471  CHECK_STATUS(vpiStreamSync(stream));
472 
473  // Now we lock the output arrays to properly set up the input for the next iteration.
474  VPIArrayData updatedBBoxData;
475  CHECK_STATUS(vpiArrayLock(outputBoxList, VPI_LOCK_READ, &updatedBBoxData));
476 
477  VPIArrayData estimData;
478  CHECK_STATUS(vpiArrayLock(outputEstimList, VPI_LOCK_READ, &estimData));
479 
480  auto *updated_bbox = reinterpret_cast<VPIKLTTrackedBoundingBox *>(updatedBBoxData.data);
481  auto *estim = reinterpret_cast<VPIHomographyTransform2D *>(estimData.data);
482 
483  // For each bounding box,
484  for (size_t b = 0; b < curNumBoxes; ++b)
485  {
486  // Did tracking failed?
487  if (updated_bbox[b].trackingStatus)
488  {
489  // Do we have to update the input bbox's tracking status too?
490  if (bboxes[b].trackingStatus == 0)
491  {
492  std::cout << curFrame << " -> dropped " << b << std::endl;
493  bboxes[b].trackingStatus = 1;
494  }
495 
496  continue;
497  }
498 
499  // Must update template for this bounding box??
500  if (updated_bbox[b].templateStatus)
501  {
502  std::cout << curFrame << " -> update " << b << std::endl;
503 
504  // There are usually two approaches here:
505  // 1. Redefine the bounding box using a feature detector such as
506  // \ref algo_harris_corners "Harris keypoint detector", or
507  // 2. Use updated_bbox[b], which is still valid, although tracking
508  // errors might accumulate over time.
509  //
510  // We'll go to the second option, less robust, but simple enough
511  // to implement.
512  bboxes[b] = updated_bbox[b];
513 
514  // Signal the input that the template for this bounding box must be updated.
515  bboxes[b].templateStatus = 1;
516 
517  // Predicted transform is now identity as we reset the tracking.
518  preds[b] = VPIHomographyTransform2D{};
519  preds[b].mat3[0][0] = 1;
520  preds[b].mat3[1][1] = 1;
521  preds[b].mat3[2][2] = 1;
522  }
523  else
524  {
525  // Inform that the template for this bounding box doesn't need to be pdated.
526  bboxes[b].templateStatus = 0;
527 
528  // We just update the input transform with the estimated one.
529  preds[b] = estim[b];
530  }
531  }
532 
533  // We're finished working with the output arrays.
534  CHECK_STATUS(vpiArrayUnlock(outputBoxList));
535  CHECK_STATUS(vpiArrayUnlock(outputEstimList));
536 
537  // Since we've updated the input arrays, tell VPI to invalidate
538  // any internal buffers that might still refer to the old data.
539  CHECK_STATUS(vpiArrayInvalidate(inputBoxList));
540  CHECK_STATUS(vpiArrayInvalidate(inputPredList));
541 
542  // Next's reference frame is current's template.
543  std::swap(imgTemplate, imgReference);
544  std::swap(cvTemplate, cvReference);
545  } while (true);
546  }
547  catch (std::exception &e)
548  {
549  std::cerr << e.what() << std::endl;
550  retval = 1;
551  }
552 
553  // Clean up
554  vpiContextDestroy(ctx);
555 
556  return retval;
557 }
VPIImagePlane::height
uint32_t height
Height of this plane in pixels.
Definition: Image.h:138
VPIContext
struct VPIContextImpl * VPIContext
A handle to a context.
Definition: Types.h:178
VPIKLTFeatureTrackerParams
Structure that defines the parameters for vpiCreateKLTFeatureTracker.
Definition: KLTFeatureTracker.h:106
vpiCreateKLTFeatureTracker
VPIStatus vpiCreateKLTFeatureTracker(VPIBackend backend, uint32_t imageWidth, uint32_t imageHeight, VPIImageFormat imageFormat, VPIPayload *payload)
Creates payload for vpiSubmitKLTFeatureTracker.
VPIImagePlane::width
uint32_t width
Width of this plane in pixels.
Definition: Image.h:137
vpiArrayCreate
VPIStatus vpiArrayCreate(uint32_t capacity, VPIArrayType fmt, uint32_t flags, VPIArray *array)
Create an empty array instance.
VPIHomographyTransform2D::mat3
float mat3[3][3]
3x3 homogeneous matrix that defines the homography.
Definition: Types.h:385
vpiStreamCreate
VPIStatus vpiStreamCreate(uint32_t flags, VPIStream *stream)
Create a stream instance.
VPIBackend
VPIBackend
VPI Backend types.
Definition: Types.h:89
VPIKLTTrackedBoundingBox
Stores a bounding box that is being tracked by KLT Tracker.
Definition: Types.h:415
VPI_LOCK_READ_WRITE
@ VPI_LOCK_READ_WRITE
Lock memory for reading and writing.
Definition: Types.h:461
vpiContextCreate
VPIStatus vpiContextCreate(uint32_t flags, VPIContext *ctx)
Create a context instance.
VPIKLTFeatureTrackerParams::numberOfIterationsScaling
uint32_t numberOfIterationsScaling
Number of Inverse compositional iterations of scale estimations.
Definition: KLTFeatureTracker.h:107
vpiContextSetCurrent
VPIStatus vpiContextSetCurrent(VPIContext ctx)
Sets the context for the calling thread.
VPI_LOCK_READ
@ VPI_LOCK_READ
Lock memory only for reading.
Definition: Types.h:447
VPI_IMAGE_FORMAT_U16
@ VPI_IMAGE_FORMAT_U16
Single plane with one 16-bit unsigned integer channel.
Definition: ImageFormat.h:105
vpiSubmitKLTFeatureTracker
VPIStatus vpiSubmitKLTFeatureTracker(VPIStream stream, VPIPayload payload, VPIImage templateImage, VPIArray inputBoxList, VPIArray inputPredictionList, VPIImage referenceImage, VPIArray outputBoxList, VPIArray outputEstimationList, const VPIKLTFeatureTrackerParams *params)
Runs KLT Feature Tracker on two frames.
VPIArrayData::type
VPIArrayType type
Type of each array element.
Definition: Array.h:118
vpiArraySetSize
VPIStatus vpiArraySetSize(VPIArray array, uint32_t size)
Set the array size in elements.
VPIKLTFeatureTrackerParams::maxScaleChange
float maxScaleChange
Maximum relative scale change.
Definition: KLTFeatureTracker.h:114
vpiArrayUnlock
VPIStatus vpiArrayUnlock(VPIArray array)
Releases the lock on array object.
vpiImageUnlock
VPIStatus vpiImageUnlock(VPIImage img)
Releases the lock on an image object.
Array.h
Functions and structures for dealing with VPI arrays.
vpiArrayCreateHostMemWrapper
VPIStatus vpiArrayCreateHostMemWrapper(const VPIArrayData *arrayData, uint32_t flags, VPIArray *array)
Create an array object by wrapping an existing host memory block.
vpiStreamSync
VPIStatus vpiStreamSync(VPIStream stream)
Blocks the calling thread until all submitted commands in this stream queue are done (queue is empty)...
VPI_BACKEND_CUDA
@ VPI_BACKEND_CUDA
CUDA backend.
Definition: Types.h:91
VPIImageData
Stores information about image characteristics and content.
Definition: Image.h:159
VPI_IMAGE_FORMAT_S16
@ VPI_IMAGE_FORMAT_S16
Single plane with one 16-bit signed integer channel.
Definition: ImageFormat.h:108
VPIStream
struct VPIStreamImpl * VPIStream
A handle to a stream.
Definition: Types.h:190
VPIKLTTrackedBoundingBox::bbox
VPIBoundingBox bbox
Bounding box being tracked.
Definition: Types.h:417
VPIArrayData::size
uint32_t size
Number of elements in the array.
Definition: Array.h:119
VPI_ARRAY_TYPE_HOMOGRAPHY_TRANSFORM_2D
@ VPI_ARRAY_TYPE_HOMOGRAPHY_TRANSFORM_2D
VPIHomographyTransform2D element.
Definition: Types.h:234
VPIKLTTrackedBoundingBox::trackingStatus
uint8_t trackingStatus
Tracking status of this bounding box.
Definition: Types.h:424
vpiContextDestroy
void vpiContextDestroy(VPIContext ctx)
Destroy a context instance as well as all resources it owns.
VPI_IMAGE_FORMAT_S8
@ VPI_IMAGE_FORMAT_S8
Single plane with one 8-bit signed integer channel.
Definition: ImageFormat.h:102
VPIArrayData::capacity
uint32_t capacity
Maximum number of elements that the array can hold.
Definition: Array.h:120
VPIArrayData::data
void * data
Points to the first element of the array.
Definition: Array.h:122
VPIImageData::planes
VPIImagePlane planes[VPI_MAX_PLANE_COUNT]
Data of all image planes.
Definition: Image.h:166
Image.h
Functions and structures for dealing with VPI images.
VPIKLTFeatureTrackerParams::nccThresholdUpdate
float nccThresholdUpdate
Threshold for requiring template update.
Definition: KLTFeatureTracker.h:108
VPI_IMAGE_FORMAT_U8
@ VPI_IMAGE_FORMAT_U8
Single plane with one 8-bit unsigned integer channel.
Definition: ImageFormat.h:99
VPI_ARRAY_TYPE_KLT_TRACKED_BOUNDING_BOX
@ VPI_ARRAY_TYPE_KLT_TRACKED_BOUNDING_BOX
VPIKLTTrackedBoundingBox element.
Definition: Types.h:235
VPIImagePlane::pitchBytes
uint32_t pitchBytes
Difference in bytes of beginning of one row and the beginning of the previous.
Definition: Image.h:139
VPIImage
struct VPIImageImpl * VPIImage
A handle to an image.
Definition: Types.h:196
VPIKLTFeatureTrackerParams::trackingType
VPIKLTFeatureTrackerType trackingType
Type of KLT tracking that will be performed.
Definition: KLTFeatureTracker.h:121
VPIImageData::numPlanes
int32_t numPlanes
Number of planes.
Definition: Image.h:161
KLTFeatureTracker.h
Declares functions that implement the KLT Feature Tracker algorithm.
VPIBoundingBox::width
float width
Bounding box width.
Definition: Types.h:406
VPIArrayData
Stores information about array characteristics and content.
Definition: Array.h:117
VPIPayload
struct VPIPayloadImpl * VPIPayload
A handle to an algorithm payload.
Definition: Types.h:208
vpiImageLock
VPIStatus vpiImageLock(VPIImage img, VPILockMode mode, VPIImageData *hostData)
Acquires the lock on an image object and returns a pointer to the image planes.
VPI_KLT_INVERSE_COMPOSITIONAL
@ VPI_KLT_INVERSE_COMPOSITIONAL
Inverse compositional algorithm for KLT tracker.
Definition: KLTFeatureTracker.h:92
VPIHomographyTransform2D
Stores a generic 2D homography transform.
Definition: Types.h:384
VPIImageData::type
VPIImageFormat type
Image type.
Definition: Image.h:160
Status.h
Declaration of VPI status codes handling functions.
vpiArrayLock
VPIStatus vpiArrayLock(VPIArray array, VPILockMode mode, VPIArrayData *arrayData)
Acquires the lock on array object and returns a pointer to array data.
VPI_BACKEND_CPU
@ VPI_BACKEND_CPU
CPU backend.
Definition: Types.h:90
VPIArray
struct VPIArrayImpl * VPIArray
A handle to an array.
Definition: Types.h:172
vpiImageCreateHostMemWrapper
VPIStatus vpiImageCreateHostMemWrapper(const VPIImageData *hostData, uint32_t flags, VPIImage *img)
Create an image object by wrapping around an existing host memory block.
VPIBoundingBox::xform
VPIHomographyTransform2D xform
Defines the bounding box top left corner and its homography.
Definition: Types.h:405
Stream.h
Declares functions dealing with VPI streams.
VPIBoundingBox::height
float height
Bounding box height.
Definition: Types.h:407
vpiArrayInvalidate
VPIStatus vpiArrayInvalidate(VPIArray array)
Informs that the array's wrapped memory was updated outside VPI.
VPIImageFormat
VPIImageFormat
Pre-defined image formats.
Definition: ImageFormat.h:94
vpiImageSetWrappedHostMem
VPIStatus vpiImageSetWrappedHostMem(VPIImage img, const VPIImageData *hostData)
Redefines the wrapped host memory in an existing VPIImage wrapper.
VPIImagePlane::data
void * data
Pointer to the first row of this plane.
Definition: Image.h:147
VPIKLTFeatureTrackerParams::nccThresholdStop
float nccThresholdStop
Threshold to stop estimating.
Definition: KLTFeatureTracker.h:110
VPIKLTFeatureTrackerParams::maxTranslationChange
float maxTranslationChange
Maximum relative translation change.
Definition: KLTFeatureTracker.h:118
VPI_BACKEND_PVA
@ VPI_BACKEND_PVA
PVA backend.
Definition: Types.h:92
VPIKLTFeatureTrackerParams::nccThresholdKill
float nccThresholdKill
Threshold to consider template tracking was lost.
Definition: KLTFeatureTracker.h:109
VPIKLTTrackedBoundingBox::templateStatus
uint8_t templateStatus
Status of the template related to this bounding box.
Definition: Types.h:431
Context.h
Functions and structures for dealing with VPI contexts.
vpiImageGetType
VPIStatus vpiImageGetType(VPIImage img, VPIImageFormat *type)
Get the image format.