NVIDIA DeepStream SDK API Reference

9.2 Release
sources/libs/nvmultiobjecttracker/include/modules/utility/cv_functions.hpp
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2021-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3  * SPDX-License-Identifier: Apache-2.0
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #ifndef CV_FUNCTIONS_HPP
19 #define CV_FUNCTIONS_HPP
20 
21 #include <sys/stat.h>
22 #include <stdexcept>
23 #include <iostream>
24 #include <vector>
25 
26 #if defined(VIZ_DEBUG) || defined(VIZ_DEBUG_SEG)
27 #include <opencv2/core.hpp>
28 #include <opencv2/imgproc/imgproc.hpp>
29 #endif
30 
31 #include <Eigen/Dense>
32 #include <unsupported/Eigen/MatrixFunctions>
33 
34 #include "modules/utility/dataTypes.hpp"
35 
36 namespace CV_FUNCS {
37 
43 Eigen::VectorXd convertBboxToZ(const NvMotDataTypes::Rect2f &bbox, const bool useAspc=false);
44 
50 void convexHull(const std::vector<Eigen::Vector2d> &points, std::vector<Eigen::Vector2d> &hull);
51 
57 void convexHull(const std::vector<Eigen::Vector2f> &points, std::vector<Eigen::Vector2f> &hull);
58 
63 NvMotDataTypes::Rect2f boundingRect(const std::vector<Eigen::Vector2d> &points);
64 
71 NvMotDataTypes::Rect2f boundingRect(float *mask, const int width, const int height);
72 
73 #ifdef VIZ_DEBUG
74 
78 inline Eigen::Vector2f convertOcvPtToEigenPt(const cv::Point2d pt_ocv)
79 {
80  Eigen::Vector2f pt_e;
81  pt_e << pt_ocv.x, pt_ocv.y;
82  return pt_e;
83 }
84 #endif
85 
94  const float minX=0, const float minY=0, const float width=0, const float height=0
95 )
96 {
97  Eigen::Vector2f min(minX, minY);
98  Eigen::Vector2f max(minX + width, minY + height);
99 
100  return NvMotDataTypes::Rect2f(min, max);
101 }
102 
110  const NvMotDataTypes::Rect2f &bbox, const float displacement_x, const float displacement_y
111 )
112 {
114  Eigen::Vector2f min = bbox.min();
115  Eigen::Vector2f max = bbox.max();
116  min(0) += displacement_x;
117  max(0) += displacement_x;
118  min(1) += displacement_y;
119  max(1) += displacement_y;
120 
121  return NvMotDataTypes::Rect2f(min, max);
122 }
123 
128 inline Eigen::Vector2f getBboxCenterPt(const NvMotDataTypes::Rect2f &bbox)
129 {
130  const Eigen::Vector2f min = bbox.min();
131  const Eigen::Vector2f size = bbox.sizes();
132 
133  return Eigen::Vector2f(min(0) + size(0)/2, min(1) + size(1)/2);
134 }
135 
140 inline const std::string getEigenRectString(const NvMotDataTypes::Rect2f &bbox)
141 {
142  std::stringstream out;
143  out << "[" << bbox.sizes()(0) << " x " << bbox.sizes()(1) << " from (" << bbox.min()(0) << ", " << bbox.min()(1) << ")]";
144  return out.str();
145 }
146 
152 inline bool isBboxEqual(const NvMotDataTypes::Rect2f &bbox1, const NvMotDataTypes::Rect2f &bbox2)
153 {
154  return bbox1.min() == bbox2.min() && bbox1.max() == bbox2.max();
155 }
156 
162 inline int modul(int a, int b)
163 {
164  return ((a % b) + b) % b;
165 }
166 
173 inline NvMotDataTypes::Rect2f getBoxWithAspectRatio(const NvMotDataTypes::Rect2f &bbox, const float aspectRatio)
174 {
175  Eigen::Vector2f min_new = bbox.min();
176  Eigen::Vector2f max_new = bbox.max();
177 
178  const float width_prev = max_new(0) - min_new(0);
179  const float height = max_new(1) - min_new(1);
180  const float width_new = height * aspectRatio;
181  min_new(0) -= (width_new - width_prev) / 2.0;
182  max_new(0) += (width_new - width_prev) / 2.0;
183 
184  return NvMotDataTypes::Rect2f(min_new, max_new);
185 }
186 
187 #if defined(VIZ_DEBUG) || defined(VIZ_DEBUG_SEG)
188 
192 inline NvMotDataTypes::Rect2f convertCvRect2f2MotRect2f(const cv::Rect2f &bbox)
193 {
194  Eigen::Vector2f min; min << bbox.x, bbox.y;
195  Eigen::Vector2f max; max << bbox.x + bbox.width, bbox.y + bbox.height;
196 
197  return NvMotDataTypes::Rect2f(min, max);
198 }
199 
204 inline cv::Rect2f convertMotRect2f2CvRect2f(const NvMotDataTypes::Rect2f &bbox)
205 {
206  Eigen::Vector2f min = bbox.min();
207 
208  return cv::Rect2f(min(0), min(1), bbox.sizes()(0), bbox.sizes()(1));
209 }
210 #endif
211 
217 inline NvMotDataTypes::Rect2f convertXToBbox(const Eigen::VectorXd &x, const bool useAspc=false)
218 {
219  assert(x.rows() >= 4 || x.cols() >= 4);
220 
221  double h = x(3);
222 
224  double w = useAspc ? x(2) * h : x(2);
225 
226  return constructRect2f(x(0)-w/2, x(1)-h/2, w, h);
227 }
228 
235 inline NvMotDataTypes::RowMajorMatrixXf getHanningWindow(const int width, const int height, float offsetFactor_y = 0.f)
236 {
237  Eigen::RowVectorXf hann_rows(height);
238  Eigen::RowVectorXf hann_cols(width);
239  int NN = height - 1;
240 
241  int offset_y = NN * offsetFactor_y;
242 
243  if(NN != 0)
244  {
245  for (int i = 0; i < height; ++i)
246  {
247  int i_p = i-offset_y > height ? 0 : i-offset_y;
248  hann_rows(i) = (float)(1.0/2.0 * (1.0 - cos(2*M_PI*(i_p)/NN)));
249  }
250  }
251  NN = width - 1;
252  if(NN != 0)
253  {
254  for (int i = 0; i < width; ++i)
255  {
256  hann_cols(i) = (float)(1.0/2.0 * (1.0 - cos(2*M_PI*i/NN)));
257  }
258  }
259 
260  NvMotDataTypes::RowMajorMatrixXf hann_window = hann_rows.transpose() * hann_cols;
261 
262  return hann_window;
263 }
264 
270 inline float computeSizeScore(const NvMotDataTypes::Rect2f &currBox, const NvMotDataTypes::Rect2f &prevBox)
271 {
272  const float areaPrev = prevBox.volume();
273  const float areaCurr = currBox.volume();
274 
275  if(prevBox.isEmpty() || areaPrev < std::numeric_limits<float>::epsilon()
276  || currBox.isEmpty() || areaCurr < std::numeric_limits<float>::epsilon())
277  return 0;
278 
279  float sizeRatio = areaCurr / areaPrev;
280 
281  if(sizeRatio > 1)
282  sizeRatio = 1.f / sizeRatio;
283 
284  return sizeRatio;
285 }
286 
293 inline Eigen::MatrixXf circshift(const Eigen::MatrixXf &matrix, int dx, int dy)
294 {
295  Eigen::MatrixXf matrix_out(matrix.rows(), matrix.cols());
296  const int rows = matrix.rows();
297  const int cols = matrix.cols();
298  int idx_y = 0;
299  int idx_x = 0;
300  for(int i=0; i<rows; i++) {
301  for(int j=0; j<cols; j++) {
302  idx_y = modul(i+dy, rows);
303  idx_x = modul(j+dx, cols);
304  matrix_out(idx_y, idx_x) = matrix(i,j);
305  }
306  }
307  return matrix_out;
308 }
309 
317 inline Eigen::MatrixXf get2dGaussianPdf(const float sigma, const int w, const int h, const bool wrap_kernel = true)
318 {
319  Eigen::MatrixXf y(h, w);
320  float w2 = static_cast<float>(int(w/2));
321  float h2 = static_cast<float>(int(h/2));
322 
324  for(int i=0; i<h; i++) {
325  for(int j=0; j<w; j++) {
326  y(i,j) = (float)exp((-0.5 / pow(sigma, 2)) * (pow((i-h2), 2) + pow((j-w2), 2)));
327  }
328  }
329 
331  if(wrap_kernel)
332  {
333  y = circshift(y, int(w/2), int(h/2));
334  }
335 
336  return y;
337 }
338 
347  const NvMotDataTypes::Rect2f tBbox_new,
348  const NvMotDataTypes::Rect2f srcImageBox, const NvMotDataTypes::Rect2f tBbox_prev
349 )
350 {
351  Eigen::Vector2f min_new = tBbox_new.min();
352  Eigen::Vector2f max_new = tBbox_new.max();
353  const float w_new = tBbox_new.sizes()(0);
354  const float h_new = tBbox_new.sizes()(1);
355 
356  const float w_prev = tBbox_prev.sizes()(0);
357  const float h_prev = tBbox_prev.sizes()(1);
358 
359  const float w_src = srcImageBox.max()(0);
360  const float h_src = srcImageBox.max()(1);
361 
363  if(w_prev > w_new && min_new(0) <= 1)
364  {
365  min_new(0) = max_new(0) - w_prev;
366  }
367 
369  if(w_prev > w_new && max_new(0) > w_src - 1)
370  {
371  max_new(0) = min_new(0) + w_prev;
372  }
373 
375  if(h_prev > h_new && min_new(1) <= 1)
376  {
377  min_new(1) = max_new(1) - h_prev;
378  }
379 
381  if(h_prev > h_new && max_new(1) > h_src - 1)
382  {
383  max_new(1) = min_new(1) + h_prev;
384  }
385 
386  return NvMotDataTypes::Rect2f(min_new, max_new);
387 }
388 
395  const NvMotDataTypes::Rect2f &bbox_new, const float paddingScale
396 )
397 {
398  const Eigen::Vector2f min_new = bbox_new.min();
399  const float newW = bbox_new.sizes()(0);
400  const float newH = bbox_new.sizes()(1);
401 
402  Eigen::Vector2f centerPt;
403 
404  centerPt << min_new(0) + newW / 2.0f, min_new(1) + newH / 2.0f;
405 
406  float searchRegionSize_w = static_cast<float>(floorf(newW + paddingScale*sqrt(newW * newH)));
407  float searchRegionSize_h = static_cast<float>(floorf(newH + paddingScale*sqrt(newW * newH)));
408  searchRegionSize_w = (searchRegionSize_w + searchRegionSize_h) / 2.0f;
409  searchRegionSize_h = searchRegionSize_w;
410 
413  centerPt(0) - searchRegionSize_w/2.f, centerPt(1) - searchRegionSize_h/2.f,
414  searchRegionSize_w, searchRegionSize_h
415  );
416 
417  return searchRegion;
418 }
419 
425 inline float computeIOU(const NvMotDataTypes::Rect2f currBox, const NvMotDataTypes::Rect2f prevBox)
426 {
427  const float areaPrev = prevBox.volume();
428  const float areaCurr = currBox.volume();
429 
430  if(prevBox.isEmpty() || areaPrev < std::numeric_limits<float>::epsilon()
431  || currBox.isEmpty() || areaCurr < std::numeric_limits<float>::epsilon())
432  return 0;
433 
434  if(currBox.intersects(prevBox))
435  {
436  float intersection = currBox.intersection(prevBox).volume();
437  float union_area = areaCurr + areaPrev - intersection;
438 
439  if(union_area < std::numeric_limits<float>::epsilon() || intersection < std::numeric_limits<float>::epsilon())
440  {
441  return 0;
442  }
443  else
444  {
445  return intersection / union_area;
446  }
447  }
448  else
449  {
450  return 0;
451  }
452 }
453 
459 inline float computeVisibility(const NvMotDataTypes::Rect2f &objBbox, const NvMotDataTypes::Rect2f &imgBbox)
460 {
461  if(imgBbox.isEmpty() || imgBbox.volume() < std::numeric_limits<float>::epsilon()
462  || objBbox.isEmpty() || objBbox.volume() < std::numeric_limits<float>::epsilon())
463  return 0;
464 
465  if(objBbox.intersects(imgBbox))
466  {
467  float intersection = objBbox.intersection(imgBbox).volume();
468 
469  if(intersection < std::numeric_limits<float>::epsilon())
470  {
471  return 0;
472  }
473  else
474  {
475  float iou = intersection / objBbox.volume();
476 
477  return iou;
478  }
479  }
480  else
481  {
482  return 0;
483  }
484 }
485 
493 inline int orientation(const Eigen::Vector2d& p, const Eigen::Vector2d& q, const Eigen::Vector2d& r)
494 {
495  float val = (q(1) - p(1)) * (r(0) - q(0)) -
496  (q(0) - p(0)) * (r(1) - q(1));
497 
499  if (val == 0.) return 0;
501  return (val > 0) ? 1 : 2;
502 }
503 
511 inline int orientation(const Eigen::Vector2f& p, const Eigen::Vector2f& q, const Eigen::Vector2f& r)
512 {
513  float val = (q(1) - p(1)) * (r(0) - q(0)) -
514  (q(0) - p(0)) * (r(1) - q(1));
515 
517  if (val == 0.) return 0;
519  return (val > 0) ? 1 : 2;
520 }
521 
522 #ifdef VIZ_DEBUG
523 
530 inline cv::Mat circshift(cv::Mat matrix, int dx, int dy)
531 {
532  cv::Mat matrix_out = matrix.clone();
533  int idx_y = 0;
534  int idx_x = 0;
535  for(int i=0; i<matrix.rows; i++) {
536  for(int j=0; j<matrix.cols; j++) {
537  idx_y = modul(i+dy, matrix.rows);
538  idx_x = modul(j+dx, matrix.cols);
539  matrix_out.at<float>(idx_y, idx_x) = matrix.at<float>(i,j);
540  }
541  }
542  return matrix_out;
543 }
544 
556 inline void OverlayImage(
557  const cv::Mat &background, const cv::Mat &foreground, cv::Mat &output,
558  cv::Point2i location = cv::Point(0,0), const cv::Mat &foregroundDensityMap = cv::Mat(),
559  float opacity_min = 0, float opacity_offset = 1, float opacity_scale = 1
560 )
561 {
562  if(background.cols != output.cols || background.rows != output.rows || background.type() != output.type() || background.channels() != output.channels())
563  background.copyTo(output);
564 
566  for(int y = std::max(location.y , 0); y < background.rows; ++y)
567  {
569  int fY = y - location.y;
570 
572  if(fY >= foreground.rows)
573  continue;
574 
576  for(int x = std::max(location.x, 0); x < background.cols; ++x)
577  {
579  int fX = x - location.x;
580 
581  {
582  bool isFilled = false;
583  for(int c = 0; c < output.channels(); ++c)
584  isFilled |= foreground.data[fY*foreground.step + fX*foreground.channels() + c];
585  if(!isFilled)
586  continue;
587  }
588 
590  if(fX >= foreground.cols)
591  continue;
592 
594  double opacity_fg = 0;
595 
596  if(foregroundDensityMap.rows > 0 && foregroundDensityMap.at<float>(fY,fX) > opacity_min)
597  {
598  opacity_fg = std::max(
599  double(0),
600  std::min(double(1.), double(foregroundDensityMap.at<float>(fY,fX)*opacity_scale + opacity_offset))
601  );
602  }
603  unsigned char foregroundPx, backgroundPx;
604  for(int c = 0; opacity_fg > 0 && c < output.channels(); ++c)
605  {
606  foregroundPx = foreground.data[fY*foreground.step + fX*foreground.channels() + c];
607  backgroundPx = background.data[y*background.step + x*background.channels() + c];
608 
609  output.data[y*output.step + output.channels()*x + c] = backgroundPx*(1.-opacity_fg) + foregroundPx*opacity_fg;
610  }
611  }
612  }
613 }
614 
620 inline cv::Point2f ConverPtBtwPlanes(const cv::Point2f &pt, const cv::Mat &projMat_A2B)
621 {
622  cv::Mat pt_homo = cv::Mat(3,1,projMat_A2B.type());
623  pt_homo.at<double>(0,0) = pt.x;
624  pt_homo.at<double>(1,0) = pt.y;
625  pt_homo.at<double>(2,0) = 1.;
626 
627  cv::Mat temp = projMat_A2B * pt_homo;
628 
629  cv::Point2f pt_transformed(temp.at<double>(0,0)/temp.at<double>(2,0), temp.at<double>(1,0)/temp.at<double>(2,0));
630 
631  return pt_transformed;
632 }
633 
639 inline void Density2Opacity(const cv::Mat &input, cv::Mat &output)
640 {
641 
642 }
643 
651 inline bool warpPerspective_custom(const cv::Mat &inImg, cv::Mat &outImg, const cv::Mat &projMat_In2out)
652 {
653  outImg = cv::Mat(inImg.cols, inImg.rows, inImg.type(), cv::Scalar(0));
654 
656  cv::Mat projMat_Out2In = projMat_In2out.inv();
657 
658  for(int y = 0; y < outImg.rows; ++y)
659  {
660  for(int x = 0; x < outImg.cols; ++x)
661  {
662  cv::Point2f pt_in = ConverPtBtwPlanes(cv::Point2f(x,y), projMat_Out2In);
663 
665  if(pt_in.x >= inImg.cols || pt_in.y >= inImg.rows || pt_in.x < 0 || pt_in.y < 0)
666  continue;
667 
668  for(int c = 0; c < outImg.channels(); ++c)
669  {
670  outImg.data[y*outImg.step + x*outImg.channels() + c] = inImg.data[int(pt_in.y+0.5)*inImg.step + int(pt_in.x+0.5)*inImg.channels() + c];
671  }
672  }
673  }
674 
675  return true;
676 }
677 
685 inline bool getTransformedPixelDensity(const cv::Mat &inImg, cv::Mat &densityImg, const cv::Mat &projMat_In2out)
686 {
688  densityImg = cv::Mat(inImg.rows, inImg.cols, CV_32F, cv::Scalar(0));
689 
690  uint STEP = 10;
691 
692  for(uint y = 0; y < densityImg.rows-STEP; y += STEP)
693  {
694  for(uint x = 0; x < densityImg.cols-STEP; x += STEP)
695  {
696  cv::Point2f pt_in_1 = ConverPtBtwPlanes(cv::Point2f(x,y), projMat_In2out);
697  cv::Point2f pt_in_2 = ConverPtBtwPlanes(cv::Point2f(x+1,y+1), projMat_In2out);
698  float dist_sq = pow(pt_in_1.x - pt_in_2.x,2) + pow(pt_in_1.y - pt_in_2.y,2);
700  float density = 1./dist_sq;
701 
702  for(uint m=0; m<STEP; m++)
703  for(uint n=0; n<STEP; n++)
704  densityImg.at<float>(y+m,x+n) = density;
705  }
706  }
707  cv::normalize(densityImg, densityImg, 0, 1, cv::NORM_MINMAX, CV_32F);
708 
709  return true;
710 }
711 
717 inline bool isFileExists(const std::string& filename)
718 {
719  struct stat buf;
720  if (stat(filename.c_str(), &buf) != -1)
721  {
722  return true;
723  }
724  return false;
725 }
726 
731 inline cv::Mat NV12_to_BGR(const cv::Mat nv12_img)
732 {
733  assert(nv12_img.channels() == 1);
734 
735  cv::Mat bgr_img;
736  cv::cvtColor(nv12_img, bgr_img, cv::COLOR_YUV2BGR_NV12);
737 
738  return bgr_img;
739 }
740 
747 inline cv::Mat NV12_to_BGR(unsigned char* yuv_data, unsigned int width, unsigned int height)
748 {
749  cv::Mat nv12_img = cv::Mat(height * 3/2, width, CV_8UC1, yuv_data);
750  cv::Mat bgr_img;
751  cv::cvtColor(nv12_img, bgr_img, cv::COLOR_YUV2BGR_NV12);
752 
753  return bgr_img;
754 }
755 
760 inline cv::Mat BGR_to_NV12(const cv::Mat src)
761 {
762  assert(src.type() == CV_8UC3);
763 
765  cv::Mat dst = cv::Mat::zeros(cv::Size(src.size().width, src.size().height*1.5), CV_8UC1);
766 
768  for(int y=0; y<src.rows; y++)
769  {
770  for(int x=0; x<src.cols; x++)
771  {
772  const cv::Vec3b bgr = src.at<cv::Vec3b>(cv::Point(x,y));
773  const uchar B = bgr.val[0];
774  const uchar G = bgr.val[1];
775  const uchar R = bgr.val[2];
776 
777  uchar &Y = dst.at<uchar>(cv::Point(x,y));
778 
779  Y = 0.257*R + 0.504*G + 0.098*B + 16 + 0.5f;
780  }
781  }
782 
783  for(int y=0; y<src.rows; y+=2)
784  {
785  for(int x=0; x<src.cols; x+=2)
786  {
787  const cv::Vec3b bgr = src.at<cv::Vec3b>(cv::Point(x,y));
788  const uchar B = bgr.val[0];
789  const uchar G = bgr.val[1];
790  const uchar R = bgr.val[2];
791 
792  uchar &Cb = dst.at<uchar>(cv::Point(x+0,y/2+src.rows));
793  uchar &Cr = dst.at<uchar>(cv::Point(x+1,y/2+src.rows));
794 
795  Cb = -0.148*R - 0.291*G + 0.439*B + 128;
796  Cr = 0.439*R - 0.368*G - 0.071*B + 128;
797  }
798  }
799 
800  return dst;
801 }
802 
807 inline cv::Mat BGR_to_NV12_2ch(const cv::Mat src)
808 {
809  assert(src.type() == CV_8UC3);
810 
812  std::vector<cv::Mat> dst_per_ch(2);
813  dst_per_ch[0] = cv::Mat::zeros(src.size(), CV_8UC1);
814  dst_per_ch[1] = cv::Mat::zeros(src.size(), CV_8UC1);
815 
817  for(int y=0; y<src.rows; y++)
818  {
819  for(int x=0; x<src.cols; x++)
820  {
821  const cv::Vec3b bgr = src.at<cv::Vec3b>(cv::Point(x,y));
822  const uchar B = bgr.val[0];
823  const uchar G = bgr.val[1];
824  const uchar R = bgr.val[2];
825 
826  uchar &Y = dst_per_ch[0].at<uchar>(cv::Point(x,y));
827 
828  Y = 0.257*R + 0.504*G + 0.098*B + 16 + 0.5f;
829  }
830  }
831 
832  for(int y=0; y<src.rows; y+=2)
833  {
834  for(int x=0; x<src.cols; x+=2)
835  {
836  const cv::Vec3b bgr = src.at<cv::Vec3b>(cv::Point(x,y));
837  const uchar B = bgr.val[0];
838  const uchar G = bgr.val[1];
839  const uchar R = bgr.val[2];
840 
841  uchar &Cb = dst_per_ch[1].at<uchar>(cv::Point(x+0,y/2));
842  uchar &Cr = dst_per_ch[1].at<uchar>(cv::Point(x+1,y/2));
843 
844  Cb = -0.148*R - 0.291*G + 0.439*B + 128;
845  Cr = 0.439*R - 0.368*G - 0.071*B + 128;
846  }
847  }
848 
849  cv::Mat dst;
850 
852  cv::merge(dst_per_ch, dst);
853 
854  return dst;
855 }
856 
861 inline cv::Mat NV12_2ch_to_BGR(cv::Mat src)
862 {
863  assert(src.channels() == 2);
864 
865  std::vector<cv::Mat> nv12_per_ch;
866 
868  cv::split(src, nv12_per_ch);
869 
870  cv::Mat nv12_img = cv::Mat::zeros(cv::Size(src.size().width, src.size().height*3/2), CV_8UC1);
871 
873  nv12_per_ch[0].copyTo(nv12_img( cv::Rect(0,0,src.size().width,src.size().height) ));
874 
876  nv12_per_ch[1](
877  cv::Rect(0,0,src.size().width,src.size().height*0.5)
878  ).copyTo(nv12_img( cv::Rect(0,src.size().height,src.size().width,src.size().height*0.5) ));
879 
880  cv::Mat bgr_img;
881  cv::cvtColor(nv12_img, bgr_img, cv::COLOR_YUV2BGR_NV12);
882 
883  return bgr_img;
884 }
885 
886 #endif
887 
888 } // end of CV_FUNCS
889 
890 #endif // CV_FUNCTIONS_HPP
CV_FUNCS::getEigenRectString
const std::string getEigenRectString(const NvMotDataTypes::Rect2f &bbox)
Format an Eigen bounding box as a readable string.
Definition: sources/libs/nvmultiobjecttracker/include/modules/utility/cv_functions.hpp:140
NvMotDataTypes::Rect2f
Rect_< float, 2 > Rect2f
Definition: sources/libs/nvmultiobjecttracker/include/modules/utility/dataTypes.hpp:47
width
JDIMENSION JDIMENSION * width
Definition: sources/libs/nvll_batch_jpeg_encode/oss/jpeglib.h:1001
floorf
__host__ __device__ float2 floorf(float2 v)
Apply the floor operation component-wise.
Definition: sources/libs/nvmultiobjecttracker/include/modules/cuDCFv2/helper_math.h:2786
CV_FUNCS::boundingRect
NvMotDataTypes::Rect2f boundingRect(const std::vector< Eigen::Vector2d > &points)
Compute the axis-aligned bounding rectangle of a point set.
CV_FUNCS::computeSizeScore
float computeSizeScore(const NvMotDataTypes::Rect2f &currBox, const NvMotDataTypes::Rect2f &prevBox)
Compute a symmetric area-ratio score between two bounding boxes.
Definition: sources/libs/nvmultiobjecttracker/include/modules/utility/cv_functions.hpp:270
half_float::detail::sqrt
uint32 sqrt(uint32 &r, int &exp)
Fixed point square root.
Definition: includes/half.hpp:1497
half_float::pow
half pow(half x, half y)
Power function.
Definition: includes/half.hpp:3444
half_float::cos
half cos(half arg)
Cosine function.
Definition: includes/half.hpp:3606
CV_FUNCS::orientation
int orientation(const Eigen::Vector2d &p, const Eigen::Vector2d &q, const Eigen::Vector2d &r)
Classify the orientation of three double-precision points.
Definition: sources/libs/nvmultiobjecttracker/include/modules/utility/cv_functions.hpp:493
CV_FUNCS
Definition: sources/libs/nvmultiobjecttracker/include/modules/utility/cv_functions.hpp:36
uchar
unsigned char uchar
Definition: sources/libs/nvmultiobjecttracker/include/modules/utility/dataTypes.hpp:29
uint
unsigned int uint
Definition: sources/libs/nvmultiobjecttracker/include/modules/cuDCFv2/helper_math.h:25
CV_FUNCS::unclipBbox
const NvMotDataTypes::Rect2f unclipBbox(const NvMotDataTypes::Rect2f tBbox_new, const NvMotDataTypes::Rect2f srcImageBox, const NvMotDataTypes::Rect2f tBbox_prev)
Recover bounding-box extent clipped by an image border using the previous box size.
Definition: sources/libs/nvmultiobjecttracker/include/modules/utility/cv_functions.hpp:346
CV_FUNCS::get2dGaussianPdf
Eigen::MatrixXf get2dGaussianPdf(const float sigma, const int w, const int h, const bool wrap_kernel=true)
Create a two-dimensional Gaussian response map.
Definition: sources/libs/nvmultiobjecttracker/include/modules/utility/cv_functions.hpp:317
max
int max(int a, int b)
Compute the component-wise maximum.
Definition: sources/libs/nvmultiobjecttracker/include/modules/cuDCFv2/helper_math.h:60
CV_FUNCS::circshift
Eigen::MatrixXf circshift(const Eigen::MatrixXf &matrix, int dx, int dy)
Circularly shift a matrix along both axes.
Definition: sources/libs/nvmultiobjecttracker/include/modules/utility/cv_functions.hpp:293
CV_FUNCS::computeSearchRegion
const NvMotDataTypes::Rect2f computeSearchRegion(const NvMotDataTypes::Rect2f &bbox_new, const float paddingScale)
Expand a bounding box into a square search region.
Definition: sources/libs/nvmultiobjecttracker/include/modules/utility/cv_functions.hpp:394
CV_FUNCS::getHanningWindow
NvMotDataTypes::RowMajorMatrixXf getHanningWindow(const int width, const int height, float offsetFactor_y=0.f)
Generate a separable two-dimensional Hann window.
Definition: sources/libs/nvmultiobjecttracker/include/modules/utility/cv_functions.hpp:235
CV_FUNCS::getBboxCenterPt
Eigen::Vector2f getBboxCenterPt(const NvMotDataTypes::Rect2f &bbox)
Compute the center point of a bounding box.
Definition: sources/libs/nvmultiobjecttracker/include/modules/utility/cv_functions.hpp:128
CV_FUNCS::computeIOU
float computeIOU(const NvMotDataTypes::Rect2f currBox, const NvMotDataTypes::Rect2f prevBox)
Compute intersection over union for two bounding boxes.
Definition: sources/libs/nvmultiobjecttracker/include/modules/utility/cv_functions.hpp:425
half_float::exp
half exp(half arg)
Exponential function.
Definition: includes/half.hpp:2953
pydeepstreamdoc::tensor::TensorDoc::size
constexpr const char * size
Definition: service-maker/sources/python/src/bindings/docstrings/tensordoc.h:46
CV_FUNCS::convertBboxToZ
Eigen::VectorXd convertBboxToZ(const NvMotDataTypes::Rect2f &bbox, const bool useAspc=false)
Convert a bounding box to an estimator measurement vector.
CV_FUNCS::modul
int modul(int a, int b)
Compute a nonnegative modulo result for positive divisors.
Definition: sources/libs/nvmultiobjecttracker/include/modules/utility/cv_functions.hpp:162
CV_FUNCS::getBoxWithAspectRatio
NvMotDataTypes::Rect2f getBoxWithAspectRatio(const NvMotDataTypes::Rect2f &bbox, const float aspectRatio)
Adjust the width of the bbox according to the aspect ratio specified.
Definition: sources/libs/nvmultiobjecttracker/include/modules/utility/cv_functions.hpp:173
min
int min(int a, int b)
Compute the component-wise minimum.
Definition: sources/libs/nvmultiobjecttracker/include/modules/cuDCFv2/helper_math.h:70
normalize
__host__ __device__ float2 normalize(float2 v)
Normalize a vector to unit length.
Definition: sources/libs/nvmultiobjecttracker/include/modules/cuDCFv2/helper_math.h:2752
CV_FUNCS::isBboxEqual
bool isBboxEqual(const NvMotDataTypes::Rect2f &bbox1, const NvMotDataTypes::Rect2f &bbox2)
Compare two bounding boxes for exact equality.
Definition: sources/libs/nvmultiobjecttracker/include/modules/utility/cv_functions.hpp:152
val
int val
Definition: sources/libs/nvll_batch_jpeg_encode/oss/jpeglib.h:976
CV_FUNCS::constructRect2f
NvMotDataTypes::Rect2f constructRect2f(const float minX=0, const float minY=0, const float width=0, const float height=0)
Construct an axis-aligned rectangle from its origin and size.
Definition: sources/libs/nvmultiobjecttracker/include/modules/utility/cv_functions.hpp:93
CV_FUNCS::convertXToBbox
NvMotDataTypes::Rect2f convertXToBbox(const Eigen::VectorXd &x, const bool useAspc=false)
Convert an estimator state vector to a bounding box.
Definition: sources/libs/nvmultiobjecttracker/include/modules/utility/cv_functions.hpp:217
CV_FUNCS::computeVisibility
float computeVisibility(const NvMotDataTypes::Rect2f &objBbox, const NvMotDataTypes::Rect2f &imgBbox)
Compute the fraction of an object bounding box visible inside an image box.
Definition: sources/libs/nvmultiobjecttracker/include/modules/utility/cv_functions.hpp:459
CV_FUNCS::convexHull
void convexHull(const std::vector< Eigen::Vector2d > &points, std::vector< Eigen::Vector2d > &hull)
Compute the convex hull of double-precision points.
NvMotDataTypes::RowMajorMatrixXf
RowMajorMatrixX< float > RowMajorMatrixXf
Definition: sources/libs/nvmultiobjecttracker/include/modules/utility/dataTypes.hpp:39
NvMotDataTypes::Rect
Rect_< int, 2 > Rect
Definition: sources/libs/nvmultiobjecttracker/include/modules/utility/dataTypes.hpp:49
CV_FUNCS::displaceBbox
NvMotDataTypes::Rect2f displaceBbox(const NvMotDataTypes::Rect2f &bbox, const float displacement_x, const float displacement_y)
Translate a bounding box by horizontal and vertical displacements.
Definition: sources/libs/nvmultiobjecttracker/include/modules/utility/cv_functions.hpp:109