Skip to content

Commit 2e30217

Browse files
committed
use functions instead of class for the new kernels; add algo hint; use accurate algo in asift
1 parent 45e21f7 commit 2e30217

File tree

5 files changed

+1903
-1478
lines changed

5 files changed

+1903
-1478
lines changed

modules/features2d/src/affine_feature.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ class skewedDetectAndCompute : public ParallelLoopBody
261261
h = rect.height; w = rect.width;
262262
pose = Matx23f(c, -s, -(float)rect.x,
263263
s, c, -(float)rect.y);
264-
warpAffine(image, rotImage, pose, Size(w, h), INTER_LINEAR, BORDER_REPLICATE);
264+
warpAffine(image, rotImage, pose, Size(w, h), INTER_LINEAR, BORDER_REPLICATE, Scalar(), cv::ALGO_HINT_ACCURATE);
265265
}
266266
if( tilt == 1 )
267267
warpedImage = rotImage;
@@ -275,7 +275,7 @@ class skewedDetectAndCompute : public ParallelLoopBody
275275
pose(0, 2) /= tilt;
276276
}
277277
if( phi != 0 || tilt != 1 )
278-
warpAffine(mask0, warpedMask, pose, warpedImage.size(), INTER_NEAREST);
278+
warpAffine(mask0, warpedMask, pose, warpedImage.size(), INTER_NEAREST, BORDER_CONSTANT, Scalar(), cv::ALGO_HINT_ACCURATE);
279279
else
280280
warpedMask = mask0;
281281
}

modules/features2d/test/test_affine_feature.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ TEST(Features2d_AFFINE_FEATURE, regression)
8282
const float badCountsRatio = 0.01f;
8383
const float badDescriptorDist = 1.0f;
8484
const float maxBadKeypointsRatio = 0.15f;
85-
const float maxBadDescriptorRatio = 0.41f;
85+
const float maxBadDescriptorRatio = 0.15f;
8686

8787
// read keypoints
8888
vector<KeyPoint> validKeypoints;

modules/imgproc/include/opencv2/imgproc.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2474,14 +2474,16 @@ flag #WARP_INVERSE_MAP that means that M is the inverse transformation (
24742474
borderMode=#BORDER_TRANSPARENT, it means that the pixels in the destination image corresponding to
24752475
the "outliers" in the source image are not modified by the function.
24762476
@param borderValue value used in case of a constant border; by default, it is 0.
2477+
@param hint Implementation modfication flags. See #AlgorithmHint
24772478
24782479
@sa warpPerspective, resize, remap, getRectSubPix, transform
24792480
*/
24802481
CV_EXPORTS_W void warpAffine( InputArray src, OutputArray dst,
24812482
InputArray M, Size dsize,
24822483
int flags = INTER_LINEAR,
24832484
int borderMode = BORDER_CONSTANT,
2484-
const Scalar& borderValue = Scalar());
2485+
const Scalar& borderValue = Scalar(),
2486+
AlgorithmHint hint = cv::ALGO_HINT_DEFAULT);
24852487

24862488
/** @example samples/cpp/snippets/warpPerspective_demo.cpp
24872489
An example program shows using cv::getPerspectiveTransform and cv::warpPerspective for image warping

modules/imgproc/src/imgwarp.cpp

Lines changed: 62 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2574,20 +2574,68 @@ static bool ipp_warpAffine( InputArray _src, OutputArray _dst, int interpolation
25742574

25752575
namespace hal {
25762576

2577-
void warpAffine(int src_type,
2578-
const uchar * src_data, size_t src_step, int src_width, int src_height,
2579-
uchar * dst_data, size_t dst_step, int dst_width, int dst_height,
2580-
const double M[6], int interpolation, int borderType, const double borderValue[4])
2577+
static void warpAffine(int src_type,
2578+
const uchar * src_data, size_t src_step, int src_width, int src_height,
2579+
uchar * dst_data, size_t dst_step, int dst_width, int dst_height,
2580+
const double M[6], int interpolation, int borderType, const double borderValue[4], AlgorithmHint hint)
25812581
{
25822582
CALL_HAL(warpAffine, cv_hal_warpAffine, src_type, src_data, src_step, src_width, src_height, dst_data, dst_step, dst_width, dst_height, M, interpolation, borderType, borderValue);
25832583

25842584
Mat src(Size(src_width, src_height), src_type, const_cast<uchar*>(src_data), src_step);
25852585
Mat dst(Size(dst_width, dst_height), src_type, dst_data, dst_step);
25862586

2587-
if (interpolation == INTER_LINEAR &&
2588-
(dst.channels() == 1 || dst.channels() == 3 || dst.channels() == 4) &&
2589-
(dst.depth() == CV_8U || dst.depth() == CV_16U || dst.depth() == CV_32F)) {
2590-
CV_CPU_DISPATCH(warpAffineSimdInvoker, (dst, src, M, interpolation, borderType, borderValue), CV_CPU_DISPATCH_MODES_ALL);
2587+
if (interpolation == INTER_LINEAR) {
2588+
switch (src_type) {
2589+
case CV_8UC1: {
2590+
if (hint == cv::ALGO_HINT_APPROX) {
2591+
CV_CPU_DISPATCH(warpAffineLinearApproxInvoker_8UC1, (src_data, src_step, src_height, src_width, dst_data, dst_step, dst_height, dst_width, M, borderType, borderValue), CV_CPU_DISPATCH_MODES_ALL);
2592+
} else {
2593+
CV_CPU_DISPATCH(warpAffineLinearInvoker_8UC1, (src_data, src_step, src_height, src_width, dst_data, dst_step, dst_height, dst_width, M, borderType, borderValue), CV_CPU_DISPATCH_MODES_ALL);
2594+
}
2595+
break;
2596+
}
2597+
case CV_8UC3: {
2598+
if (hint == cv::ALGO_HINT_APPROX) {
2599+
CV_CPU_DISPATCH(warpAffineLinearApproxInvoker_8UC3, (src_data, src_step, src_height, src_width, dst_data, dst_step, dst_height, dst_width, M, borderType, borderValue), CV_CPU_DISPATCH_MODES_ALL);
2600+
} else {
2601+
CV_CPU_DISPATCH(warpAffineLinearInvoker_8UC3, (src_data, src_step, src_height, src_width, dst_data, dst_step, dst_height, dst_width, M, borderType, borderValue), CV_CPU_DISPATCH_MODES_ALL);
2602+
}
2603+
break;
2604+
}
2605+
case CV_8UC4: {
2606+
if (hint == cv::ALGO_HINT_APPROX) {
2607+
CV_CPU_DISPATCH(warpAffineLinearApproxInvoker_8UC4, (src_data, src_step, src_height, src_width, dst_data, dst_step, dst_height, dst_width, M, borderType, borderValue), CV_CPU_DISPATCH_MODES_ALL);
2608+
} else {
2609+
CV_CPU_DISPATCH(warpAffineLinearInvoker_8UC4, (src_data, src_step, src_height, src_width, dst_data, dst_step, dst_height, dst_width, M, borderType, borderValue), CV_CPU_DISPATCH_MODES_ALL);
2610+
}
2611+
break;
2612+
}
2613+
case CV_16UC1: {
2614+
CV_CPU_DISPATCH(warpAffineLinearInvoker_16UC1, ((const uint16_t*)src_data, src_step, src_height, src_width, (uint16_t*)dst_data, dst_step, dst_height, dst_width, M, borderType, borderValue), CV_CPU_DISPATCH_MODES_ALL);
2615+
break;
2616+
}
2617+
case CV_16UC3: {
2618+
CV_CPU_DISPATCH(warpAffineLinearInvoker_16UC3, ((const uint16_t*)src_data, src_step, src_height, src_width, (uint16_t*)dst_data, dst_step, dst_height, dst_width, M, borderType, borderValue), CV_CPU_DISPATCH_MODES_ALL);
2619+
break;
2620+
}
2621+
case CV_16UC4: {
2622+
CV_CPU_DISPATCH(warpAffineLinearInvoker_16UC4, ((const uint16_t*)src_data, src_step, src_height, src_width, (uint16_t*)dst_data, dst_step, dst_height, dst_width, M, borderType, borderValue), CV_CPU_DISPATCH_MODES_ALL);
2623+
break;
2624+
}
2625+
case CV_32FC1: {
2626+
CV_CPU_DISPATCH(warpAffineLinearInvoker_32FC1, ((const float*)src_data, src_step, src_height, src_width, (float*)dst_data, dst_step, dst_height, dst_width, M, borderType, borderValue), CV_CPU_DISPATCH_MODES_ALL);
2627+
break;
2628+
}
2629+
case CV_32FC3: {
2630+
CV_CPU_DISPATCH(warpAffineLinearInvoker_32FC3, ((const float*)src_data, src_step, src_height, src_width, (float*)dst_data, dst_step, dst_height, dst_width, M, borderType, borderValue), CV_CPU_DISPATCH_MODES_ALL);
2631+
break;
2632+
}
2633+
case CV_32FC4: {
2634+
CV_CPU_DISPATCH(warpAffineLinearInvoker_32FC4, ((const float*)src_data, src_step, src_height, src_width, (float*)dst_data, dst_step, dst_height, dst_width, M, borderType, borderValue), CV_CPU_DISPATCH_MODES_ALL);
2635+
break;
2636+
}
2637+
// no default
2638+
}
25912639
}
25922640

25932641
int x;
@@ -2706,10 +2754,14 @@ void warpAffineBlockline(int *adelta, int *bdelta, short* xy, short* alpha, int
27062754

27072755
void cv::warpAffine( InputArray _src, OutputArray _dst,
27082756
InputArray _M0, Size dsize,
2709-
int flags, int borderType, const Scalar& borderValue )
2757+
int flags, int borderType, const Scalar& borderValue,
2758+
AlgorithmHint hint )
27102759
{
27112760
CV_INSTRUMENT_REGION();
27122761

2762+
if (hint == cv::ALGO_HINT_DEFAULT)
2763+
hint = cv::getDefaultAlgorithmHint();
2764+
27132765
int interpolation = flags & INTER_MAX;
27142766
CV_Assert( _src.channels() <= 4 || (interpolation != INTER_LANCZOS4 &&
27152767
interpolation != INTER_CUBIC) );
@@ -2817,7 +2869,7 @@ void cv::warpAffine( InputArray _src, OutputArray _dst,
28172869
#endif
28182870

28192871
hal::warpAffine(src.type(), src.data, src.step, src.cols, src.rows, dst.data, dst.step, dst.cols, dst.rows,
2820-
M, interpolation, borderType, borderValue.val);
2872+
M, interpolation, borderType, borderValue.val, hint);
28212873
}
28222874

28232875

0 commit comments

Comments
 (0)