43#ifndef OPENCV_CUDA_BORDER_INTERPOLATE_HPP
44#define OPENCV_CUDA_BORDER_INTERPOLATE_HPP
56namespace cv {
namespace cuda {
namespace device
61 template <
typename D>
struct BrdRowConstant
63 typedef D result_type;
65 explicit __host__ __device__ __forceinline__ BrdRowConstant(
int width_,
const D& val_ = VecTraits<D>::all(0)) : width(width_), val(val_) {}
67 template <
typename T> __device__ __forceinline__ D at_low(
int x,
const T* data)
const
69 return x >= 0 ? saturate_cast<D>(data[x]) : val;
72 template <
typename T> __device__ __forceinline__ D at_high(
int x,
const T* data)
const
74 return x < width ? saturate_cast<D>(data[x]) : val;
77 template <
typename T> __device__ __forceinline__ D at(
int x,
const T* data)
const
79 return (x >= 0 && x < width) ? saturate_cast<D>(data[x]) : val;
86 template <
typename D>
struct BrdColConstant
88 typedef D result_type;
90 explicit __host__ __device__ __forceinline__ BrdColConstant(
int height_,
const D& val_ = VecTraits<D>::all(0)) : height(height_), val(val_) {}
92 template <
typename T> __device__ __forceinline__ D at_low(
int y,
const T* data,
size_t step)
const
94 return y >= 0 ? saturate_cast<D>(*(
const T*)((
const char*)data + y * step)) : val;
97 template <
typename T> __device__ __forceinline__ D at_high(
int y,
const T* data,
size_t step)
const
99 return y < height ? saturate_cast<D>(*(
const T*)((
const char*)data + y * step)) : val;
102 template <
typename T> __device__ __forceinline__ D at(
int y,
const T* data,
size_t step)
const
104 return (y >= 0 && y < height) ? saturate_cast<D>(*(
const T*)((
const char*)data + y * step)) : val;
111 template <
typename D>
struct BrdConstant
113 typedef D result_type;
115 __host__ __device__ __forceinline__ BrdConstant(
int height_,
int width_,
const D& val_ = VecTraits<D>::all(0)) : height(height_), width(width_), val(val_)
119 template <
typename T> __device__ __forceinline__ D at(
int y,
int x,
const T* data,
size_t step)
const
121 return (x >= 0 && x < width && y >= 0 && y < height) ? saturate_cast<D>(((
const T*)((
const uchar*)data + y * step))[x]) : val;
124 template <
typename Ptr2D> __device__ __forceinline__ D at(
typename Ptr2D::index_type y,
typename Ptr2D::index_type x,
const Ptr2D& src)
const
126 return (x >= 0 && x < width && y >= 0 && y < height) ? saturate_cast<D>(src(y, x)) : val;
137 template <
typename D>
struct BrdRowReplicate
139 typedef D result_type;
141 explicit __host__ __device__ __forceinline__ BrdRowReplicate(
int width) : last_col(width - 1) {}
142 template <
typename U> __host__ __device__ __forceinline__ BrdRowReplicate(
int width, U) : last_col(width - 1) {}
144 __device__ __forceinline__
int idx_col_low(
int x)
const
149 __device__ __forceinline__
int idx_col_high(
int x)
const
154 __device__ __forceinline__
int idx_col(
int x)
const
156 return idx_col_low(idx_col_high(x));
159 template <
typename T> __device__ __forceinline__ D at_low(
int x,
const T* data)
const
161 return saturate_cast<D>(data[idx_col_low(x)]);
164 template <
typename T> __device__ __forceinline__ D at_high(
int x,
const T* data)
const
166 return saturate_cast<D>(data[idx_col_high(x)]);
169 template <
typename T> __device__ __forceinline__ D at(
int x,
const T* data)
const
171 return saturate_cast<D>(data[idx_col(x)]);
177 template <
typename D>
struct BrdColReplicate
179 typedef D result_type;
181 explicit __host__ __device__ __forceinline__ BrdColReplicate(
int height) : last_row(height - 1) {}
182 template <
typename U> __host__ __device__ __forceinline__ BrdColReplicate(
int height, U) : last_row(height - 1) {}
184 __device__ __forceinline__
int idx_row_low(
int y)
const
189 __device__ __forceinline__
int idx_row_high(
int y)
const
194 __device__ __forceinline__
int idx_row(
int y)
const
196 return idx_row_low(idx_row_high(y));
199 template <
typename T> __device__ __forceinline__ D at_low(
int y,
const T* data,
size_t step)
const
201 return saturate_cast<D>(*(
const T*)((
const char*)data + idx_row_low(y) * step));
204 template <
typename T> __device__ __forceinline__ D at_high(
int y,
const T* data,
size_t step)
const
206 return saturate_cast<D>(*(
const T*)((
const char*)data + idx_row_high(y) * step));
209 template <
typename T> __device__ __forceinline__ D at(
int y,
const T* data,
size_t step)
const
211 return saturate_cast<D>(*(
const T*)((
const char*)data + idx_row(y) * step));
217 template <
typename D>
struct BrdReplicate
219 typedef D result_type;
221 __host__ __device__ __forceinline__ BrdReplicate(
int height,
int width) : last_row(height - 1), last_col(width - 1) {}
222 template <
typename U> __host__ __device__ __forceinline__ BrdReplicate(
int height,
int width, U) : last_row(height - 1), last_col(width - 1) {}
224 __device__ __forceinline__
int idx_row_low(
int y)
const
229 __device__ __forceinline__
int idx_row_high(
int y)
const
234 __device__ __forceinline__
int idx_row(
int y)
const
236 return idx_row_low(idx_row_high(y));
239 __device__ __forceinline__
int idx_col_low(
int x)
const
244 __device__ __forceinline__
int idx_col_high(
int x)
const
249 __device__ __forceinline__
int idx_col(
int x)
const
251 return idx_col_low(idx_col_high(x));
254 template <
typename T> __device__ __forceinline__ D at(
int y,
int x,
const T* data,
size_t step)
const
256 return saturate_cast<D>(((
const T*)((
const char*)data + idx_row(y) * step))[idx_col(x)]);
259 template <
typename Ptr2D> __device__ __forceinline__ D at(
typename Ptr2D::index_type y,
typename Ptr2D::index_type x,
const Ptr2D& src)
const
261 return saturate_cast<D>(src(idx_row(y), idx_col(x)));
271 template <
typename D>
struct BrdRowReflect101
273 typedef D result_type;
275 explicit __host__ __device__ __forceinline__ BrdRowReflect101(
int width) : last_col(width - 1) {}
276 template <
typename U> __host__ __device__ __forceinline__ BrdRowReflect101(
int width, U) : last_col(width - 1) {}
278 __device__ __forceinline__
int idx_col_low(
int x)
const
283 __device__ __forceinline__
int idx_col_high(
int x)
const
288 __device__ __forceinline__
int idx_col(
int x)
const
290 return idx_col_low(idx_col_high(x));
293 template <
typename T> __device__ __forceinline__ D at_low(
int x,
const T* data)
const
295 return saturate_cast<D>(data[idx_col_low(x)]);
298 template <
typename T> __device__ __forceinline__ D at_high(
int x,
const T* data)
const
300 return saturate_cast<D>(data[idx_col_high(x)]);
303 template <
typename T> __device__ __forceinline__ D at(
int x,
const T* data)
const
305 return saturate_cast<D>(data[idx_col(x)]);
311 template <
typename D>
struct BrdColReflect101
313 typedef D result_type;
315 explicit __host__ __device__ __forceinline__ BrdColReflect101(
int height) : last_row(height - 1) {}
316 template <
typename U> __host__ __device__ __forceinline__ BrdColReflect101(
int height, U) : last_row(height - 1) {}
318 __device__ __forceinline__
int idx_row_low(
int y)
const
323 __device__ __forceinline__
int idx_row_high(
int y)
const
328 __device__ __forceinline__
int idx_row(
int y)
const
330 return idx_row_low(idx_row_high(y));
333 template <
typename T> __device__ __forceinline__ D at_low(
int y,
const T* data,
size_t step)
const
335 return saturate_cast<D>(*(
const D*)((
const char*)data + idx_row_low(y) * step));
338 template <
typename T> __device__ __forceinline__ D at_high(
int y,
const T* data,
size_t step)
const
340 return saturate_cast<D>(*(
const D*)((
const char*)data + idx_row_high(y) * step));
343 template <
typename T> __device__ __forceinline__ D at(
int y,
const T* data,
size_t step)
const
345 return saturate_cast<D>(*(
const D*)((
const char*)data + idx_row(y) * step));
351 template <
typename D>
struct BrdReflect101
353 typedef D result_type;
355 __host__ __device__ __forceinline__ BrdReflect101(
int height,
int width) : last_row(height - 1), last_col(width - 1) {}
356 template <
typename U> __host__ __device__ __forceinline__ BrdReflect101(
int height,
int width, U) : last_row(height - 1), last_col(width - 1) {}
358 __device__ __forceinline__
int idx_row_low(
int y)
const
363 __device__ __forceinline__
int idx_row_high(
int y)
const
368 __device__ __forceinline__
int idx_row(
int y)
const
370 return idx_row_low(idx_row_high(y));
373 __device__ __forceinline__
int idx_col_low(
int x)
const
378 __device__ __forceinline__
int idx_col_high(
int x)
const
383 __device__ __forceinline__
int idx_col(
int x)
const
385 return idx_col_low(idx_col_high(x));
388 template <
typename T> __device__ __forceinline__ D at(
int y,
int x,
const T* data,
size_t step)
const
390 return saturate_cast<D>(((
const T*)((
const char*)data + idx_row(y) * step))[idx_col(x)]);
393 template <
typename Ptr2D> __device__ __forceinline__ D at(
typename Ptr2D::index_type y,
typename Ptr2D::index_type x,
const Ptr2D& src)
const
395 return saturate_cast<D>(src(idx_row(y), idx_col(x)));
405 template <
typename D>
struct BrdRowReflect
407 typedef D result_type;
409 explicit __host__ __device__ __forceinline__ BrdRowReflect(
int width) : last_col(width - 1) {}
410 template <
typename U> __host__ __device__ __forceinline__ BrdRowReflect(
int width, U) : last_col(width - 1) {}
412 __device__ __forceinline__
int idx_col_low(
int x)
const
414 return (::
abs(x) - (x < 0)) % (last_col + 1);
417 __device__ __forceinline__
int idx_col_high(
int x)
const
419 return ::abs(last_col - ::
abs(last_col - x) + (x > last_col)) % (last_col + 1);
422 __device__ __forceinline__
int idx_col(
int x)
const
424 return idx_col_high(::
abs(x) - (x < 0));
427 template <
typename T> __device__ __forceinline__ D at_low(
int x,
const T* data)
const
429 return saturate_cast<D>(data[idx_col_low(x)]);
432 template <
typename T> __device__ __forceinline__ D at_high(
int x,
const T* data)
const
434 return saturate_cast<D>(data[idx_col_high(x)]);
437 template <
typename T> __device__ __forceinline__ D at(
int x,
const T* data)
const
439 return saturate_cast<D>(data[idx_col(x)]);
445 template <
typename D>
struct BrdColReflect
447 typedef D result_type;
449 explicit __host__ __device__ __forceinline__ BrdColReflect(
int height) : last_row(height - 1) {}
450 template <
typename U> __host__ __device__ __forceinline__ BrdColReflect(
int height, U) : last_row(height - 1) {}
452 __device__ __forceinline__
int idx_row_low(
int y)
const
454 return (::
abs(y) - (y < 0)) % (last_row + 1);
457 __device__ __forceinline__
int idx_row_high(
int y)
const
459 return ::abs(last_row - ::
abs(last_row - y) + (y > last_row)) % (last_row + 1);
462 __device__ __forceinline__
int idx_row(
int y)
const
464 return idx_row_high(::
abs(y) - (y < 0));
467 template <
typename T> __device__ __forceinline__ D at_low(
int y,
const T* data,
size_t step)
const
469 return saturate_cast<D>(*(
const D*)((
const char*)data + idx_row_low(y) * step));
472 template <
typename T> __device__ __forceinline__ D at_high(
int y,
const T* data,
size_t step)
const
474 return saturate_cast<D>(*(
const D*)((
const char*)data + idx_row_high(y) * step));
477 template <
typename T> __device__ __forceinline__ D at(
int y,
const T* data,
size_t step)
const
479 return saturate_cast<D>(*(
const D*)((
const char*)data + idx_row(y) * step));
485 template <
typename D>
struct BrdReflect
487 typedef D result_type;
489 __host__ __device__ __forceinline__ BrdReflect(
int height,
int width) : last_row(height - 1), last_col(width - 1) {}
490 template <
typename U> __host__ __device__ __forceinline__ BrdReflect(
int height,
int width, U) : last_row(height - 1), last_col(width - 1) {}
492 __device__ __forceinline__
int idx_row_low(
int y)
const
494 return (::
abs(y) - (y < 0)) % (last_row + 1);
497 __device__ __forceinline__
int idx_row_high(
int y)
const
499 return (last_row - ::abs(last_row - y) + (y > last_row)) ;
502 __device__ __forceinline__
int idx_row(
int y)
const
504 return idx_row_low(idx_row_high(y));
507 __device__ __forceinline__
int idx_col_low(
int x)
const
509 return (::
abs(x) - (x < 0)) % (last_col + 1);
512 __device__ __forceinline__
int idx_col_high(
int x)
const
514 return (last_col - ::
abs(last_col - x) + (x > last_col));
517 __device__ __forceinline__
int idx_col(
int x)
const
519 return idx_col_low(idx_col_high(x));
522 template <
typename T> __device__ __forceinline__ D at(
int y,
int x,
const T* data,
size_t step)
const
524 return saturate_cast<D>(((
const T*)((
const char*)data + idx_row(y) * step))[idx_col(x)]);
527 template <
typename Ptr2D> __device__ __forceinline__ D at(
typename Ptr2D::index_type y,
typename Ptr2D::index_type x,
const Ptr2D& src)
const
529 return saturate_cast<D>(src(idx_row(y), idx_col(x)));
539 template <
typename D>
struct BrdRowWrap
541 typedef D result_type;
543 explicit __host__ __device__ __forceinline__ BrdRowWrap(
int width_) : width(width_) {}
544 template <
typename U> __host__ __device__ __forceinline__ BrdRowWrap(
int width_, U) : width(width_) {}
546 __device__ __forceinline__
int idx_col_low(
int x)
const
548 return (x >= 0) * x + (x < 0) * (x - ((x - width + 1) / width) * width);
551 __device__ __forceinline__
int idx_col_high(
int x)
const
553 return (x < width) * x + (x >= width) * (x % width);
556 __device__ __forceinline__
int idx_col(
int x)
const
558 return idx_col_high(idx_col_low(x));
561 template <
typename T> __device__ __forceinline__ D at_low(
int x,
const T* data)
const
563 return saturate_cast<D>(data[idx_col_low(x)]);
566 template <
typename T> __device__ __forceinline__ D at_high(
int x,
const T* data)
const
568 return saturate_cast<D>(data[idx_col_high(x)]);
571 template <
typename T> __device__ __forceinline__ D at(
int x,
const T* data)
const
573 return saturate_cast<D>(data[idx_col(x)]);
579 template <
typename D>
struct BrdColWrap
581 typedef D result_type;
583 explicit __host__ __device__ __forceinline__ BrdColWrap(
int height_) : height(height_) {}
584 template <
typename U> __host__ __device__ __forceinline__ BrdColWrap(
int height_, U) : height(height_) {}
586 __device__ __forceinline__
int idx_row_low(
int y)
const
588 return (y >= 0) * y + (y < 0) * (y - ((y - height + 1) / height) * height);
591 __device__ __forceinline__
int idx_row_high(
int y)
const
593 return (y < height) * y + (y >= height) * (y % height);
596 __device__ __forceinline__
int idx_row(
int y)
const
598 return idx_row_high(idx_row_low(y));
601 template <
typename T> __device__ __forceinline__ D at_low(
int y,
const T* data,
size_t step)
const
603 return saturate_cast<D>(*(
const D*)((
const char*)data + idx_row_low(y) * step));
606 template <
typename T> __device__ __forceinline__ D at_high(
int y,
const T* data,
size_t step)
const
608 return saturate_cast<D>(*(
const D*)((
const char*)data + idx_row_high(y) * step));
611 template <
typename T> __device__ __forceinline__ D at(
int y,
const T* data,
size_t step)
const
613 return saturate_cast<D>(*(
const D*)((
const char*)data + idx_row(y) * step));
619 template <
typename D>
struct BrdWrap
621 typedef D result_type;
623 __host__ __device__ __forceinline__ BrdWrap(
int height_,
int width_) :
624 height(height_), width(width_)
627 template <
typename U>
628 __host__ __device__ __forceinline__ BrdWrap(
int height_,
int width_, U) :
629 height(height_), width(width_)
633 __device__ __forceinline__
int idx_row_low(
int y)
const
635 return (y >= 0) ? y : (y - ((y - height + 1) / height) * height);
638 __device__ __forceinline__
int idx_row_high(
int y)
const
640 return (y < height) ? y : (y % height);
643 __device__ __forceinline__
int idx_row(
int y)
const
645 return idx_row_high(idx_row_low(y));
648 __device__ __forceinline__
int idx_col_low(
int x)
const
650 return (x >= 0) ? x : (x - ((x - width + 1) / width) * width);
653 __device__ __forceinline__
int idx_col_high(
int x)
const
655 return (x < width) ? x : (x % width);
658 __device__ __forceinline__
int idx_col(
int x)
const
660 return idx_col_high(idx_col_low(x));
663 template <
typename T> __device__ __forceinline__ D at(
int y,
int x,
const T* data,
size_t step)
const
665 return saturate_cast<D>(((
const T*)((
const char*)data + idx_row(y) * step))[idx_col(x)]);
668 template <
typename Ptr2D> __device__ __forceinline__ D at(
typename Ptr2D::index_type y,
typename Ptr2D::index_type x,
const Ptr2D& src)
const
670 return saturate_cast<D>(src(idx_row(y), idx_col(x)));
680 template <
typename Ptr2D,
typename B>
struct BorderReader
682 typedef typename B::result_type elem_type;
683 typedef typename Ptr2D::index_type index_type;
685 __host__ __device__ __forceinline__ BorderReader(
const Ptr2D& ptr_,
const B& b_) : ptr(ptr_), b(b_) {}
687 __device__ __forceinline__ elem_type operator ()(index_type y, index_type x)
const
689 return b.at(y, x, ptr);
698 template <
typename Ptr2D,
typename D>
struct BorderReader< Ptr2D, BrdConstant<D> >
700 typedef typename BrdConstant<D>::result_type elem_type;
701 typedef typename Ptr2D::index_type index_type;
703 __host__ __device__ __forceinline__ BorderReader(
const Ptr2D& src_,
const BrdConstant<D>& b) :
704 src(src_), height(b.height), width(b.width), val(b.val)
708 __device__ __forceinline__ D operator ()(index_type y, index_type x)
const
710 return (x >= 0 && x < width && y >= 0 && y < height) ? saturate_cast<D>(src(y, x)) : val;
CV_EXPORTS_W void max(InputArray src1, InputArray src2, OutputArray dst)
Calculates per-element maximum of two arrays or an array and a scalar.
CV_EXPORTS_W void min(InputArray src1, InputArray src2, OutputArray dst)
Calculates per-element minimum of two arrays or an array and a scalar.
softfloat abs(softfloat a)
Absolute value
Definition: softfloat.hpp:444
"black box" representation of the file storage associated with a file on disk.
Definition: aruco.hpp:75