mirror of
https://github.com/opencv/opencv.git
synced 2026-07-31 08:13:04 +04:00
Migrated goodFeaturesToTrack to features module.
This commit is contained in:
@@ -130,6 +130,91 @@ public:
|
||||
static void retainBest( std::vector<KeyPoint>& keypoints, int npoints );
|
||||
};
|
||||
|
||||
/** @brief Determines strong corners on an image.
|
||||
|
||||
The function finds the most prominent corners in the image or in the specified image region, as
|
||||
described in @cite Shi94
|
||||
|
||||
- Function calculates the corner quality measure at every source image pixel using the
|
||||
#cornerMinEigenVal or #cornerHarris .
|
||||
- Function performs a non-maximum suppression (the local maximums in *3 x 3* neighborhood are
|
||||
retained).
|
||||
- The corners with the minimal eigenvalue less than
|
||||
\f$\texttt{qualityLevel} \cdot \max_{x,y} qualityMeasureMap(x,y)\f$ are rejected.
|
||||
- The remaining corners are sorted by the quality measure in the descending order.
|
||||
- Function throws away each corner for which there is a stronger corner at a distance less than
|
||||
maxDistance.
|
||||
|
||||
The function can be used to initialize a point-based tracker of an object.
|
||||
|
||||
@note If the function is called with different values A and B of the parameter qualityLevel , and
|
||||
A \> B, the vector of returned corners with qualityLevel=A will be the prefix of the output vector
|
||||
with qualityLevel=B .
|
||||
|
||||
@param image Input 8-bit or floating-point 32-bit, single-channel image.
|
||||
@param corners Output vector of detected corners.
|
||||
@param maxCorners Maximum number of corners to return. If there are more corners than are found,
|
||||
the strongest of them is returned. `maxCorners <= 0` implies that no limit on the maximum is set
|
||||
and all detected corners are returned.
|
||||
@param qualityLevel Parameter characterizing the minimal accepted quality of image corners. The
|
||||
parameter value is multiplied by the best corner quality measure, which is the minimal eigenvalue
|
||||
(see #cornerMinEigenVal ) or the Harris function response (see #cornerHarris ). The corners with the
|
||||
quality measure less than the product are rejected. For example, if the best corner has the
|
||||
quality measure = 1500, and the qualityLevel=0.01 , then all the corners with the quality measure
|
||||
less than 15 are rejected.
|
||||
@param minDistance Minimum possible Euclidean distance between the returned corners.
|
||||
@param mask Optional region of interest. If the image is not empty (it needs to have the type
|
||||
CV_8UC1 and the same size as image ), it specifies the region in which the corners are detected.
|
||||
@param blockSize Size of an average block for computing a derivative covariation matrix over each
|
||||
pixel neighborhood. See cornerEigenValsAndVecs .
|
||||
@param useHarrisDetector Parameter indicating whether to use a Harris detector (see #cornerHarris)
|
||||
or #cornerMinEigenVal.
|
||||
@param k Free parameter of the Harris detector.
|
||||
|
||||
@sa cornerMinEigenVal, cornerHarris, calcOpticalFlowPyrLK, estimateRigidTransform,
|
||||
*/
|
||||
|
||||
CV_EXPORTS_W void goodFeaturesToTrack( InputArray image, OutputArray corners,
|
||||
int maxCorners, double qualityLevel, double minDistance,
|
||||
InputArray mask = noArray(), int blockSize = 3,
|
||||
bool useHarrisDetector = false, double k = 0.04 );
|
||||
|
||||
CV_EXPORTS_W void goodFeaturesToTrack( InputArray image, OutputArray corners,
|
||||
int maxCorners, double qualityLevel, double minDistance,
|
||||
InputArray mask, int blockSize,
|
||||
int gradientSize, bool useHarrisDetector = false,
|
||||
double k = 0.04 );
|
||||
|
||||
/** @brief Same as above, but returns also quality measure of the detected corners.
|
||||
|
||||
@param image Input 8-bit or floating-point 32-bit, single-channel image.
|
||||
@param corners Output vector of detected corners.
|
||||
@param maxCorners Maximum number of corners to return. If there are more corners than are found,
|
||||
the strongest of them is returned. `maxCorners <= 0` implies that no limit on the maximum is set
|
||||
and all detected corners are returned.
|
||||
@param qualityLevel Parameter characterizing the minimal accepted quality of image corners. The
|
||||
parameter value is multiplied by the best corner quality measure, which is the minimal eigenvalue
|
||||
(see #cornerMinEigenVal ) or the Harris function response (see #cornerHarris ). The corners with the
|
||||
quality measure less than the product are rejected. For example, if the best corner has the
|
||||
quality measure = 1500, and the qualityLevel=0.01 , then all the corners with the quality measure
|
||||
less than 15 are rejected.
|
||||
@param minDistance Minimum possible Euclidean distance between the returned corners.
|
||||
@param mask Region of interest. If the image is not empty (it needs to have the type
|
||||
CV_8UC1 and the same size as image ), it specifies the region in which the corners are detected.
|
||||
@param cornersQuality Output vector of quality measure of the detected corners.
|
||||
@param blockSize Size of an average block for computing a derivative covariation matrix over each
|
||||
pixel neighborhood. See cornerEigenValsAndVecs .
|
||||
@param gradientSize Aperture parameter for the Sobel operator used for derivatives computation.
|
||||
See cornerEigenValsAndVecs .
|
||||
@param useHarrisDetector Parameter indicating whether to use a Harris detector (see #cornerHarris)
|
||||
or #cornerMinEigenVal.
|
||||
@param k Free parameter of the Harris detector.
|
||||
*/
|
||||
CV_EXPORTS CV_WRAP_AS(goodFeaturesToTrackWithQuality) void goodFeaturesToTrack(
|
||||
InputArray image, OutputArray corners,
|
||||
int maxCorners, double qualityLevel, double minDistance,
|
||||
InputArray mask, OutputArray cornersQuality, int blockSize = 3,
|
||||
int gradientSize = 3, bool useHarrisDetector = false, double k = 0.04);
|
||||
|
||||
/************************************ Base Classes ************************************/
|
||||
|
||||
|
||||
@@ -14,5 +14,8 @@
|
||||
"jni_type": "jbyte",
|
||||
"suffix": "B"
|
||||
}
|
||||
},
|
||||
"func_arg_fix" : {
|
||||
"goodFeaturesToTrack" : { "corners" : {"ctype" : "vector_Point"} }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import org.opencv.core.Mat;
|
||||
import org.opencv.core.MatOfInt;
|
||||
import org.opencv.core.MatOfDMatch;
|
||||
import org.opencv.core.MatOfKeyPoint;
|
||||
import org.opencv.core.MatOfPoint;
|
||||
import org.opencv.core.MatOfPoint2f;
|
||||
import org.opencv.core.Point;
|
||||
import org.opencv.core.Range;
|
||||
@@ -19,6 +20,7 @@ import org.opencv.features.DescriptorMatcher;
|
||||
import org.opencv.features.Features;
|
||||
import org.opencv.core.KeyPoint;
|
||||
import org.opencv.imgcodecs.Imgcodecs;
|
||||
import org.opencv.imgproc.Imgproc;
|
||||
import org.opencv.test.OpenCVTestCase;
|
||||
import org.opencv.test.OpenCVTestRunner;
|
||||
import org.opencv.features.Feature2D;
|
||||
@@ -169,4 +171,25 @@ public class FeaturesTest extends OpenCVTestCase {
|
||||
|
||||
assertMatEqual(ref, outImg);
|
||||
}
|
||||
|
||||
public void testGoodFeaturesToTrackMatListOfPointIntDoubleDouble() {
|
||||
Mat src = gray0;
|
||||
Imgproc.rectangle(src, new Point(2, 2), new Point(8, 8), new Scalar(100), -1);
|
||||
MatOfPoint lp = new MatOfPoint();
|
||||
|
||||
Features.goodFeaturesToTrack(src, lp, 100, 0.01, 3);
|
||||
|
||||
assertEquals(4, lp.total());
|
||||
}
|
||||
|
||||
public void testGoodFeaturesToTrackMatListOfPointIntDoubleDoubleMatIntBooleanDouble() {
|
||||
Mat src = gray0;
|
||||
Imgproc.rectangle(src, new Point(2, 2), new Point(8, 8), new Scalar(100), -1);
|
||||
MatOfPoint lp = new MatOfPoint();
|
||||
|
||||
Features.goodFeaturesToTrack(src, lp, 100, 0.01, 3, gray1, 4, 3, true, 0);
|
||||
|
||||
assertEquals(4, lp.total());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
{
|
||||
"whitelist":
|
||||
{
|
||||
"": [
|
||||
"goodFeaturesToTrack"
|
||||
],
|
||||
"Feature2D": ["detect", "compute", "detectAndCompute", "descriptorSize", "descriptorType", "defaultNorm", "empty", "getDefaultName"],
|
||||
"ORB": ["create", "setMaxFeatures", "setScaleFactor", "setNLevels", "setEdgeThreshold", "setFastThreshold", "setFirstLevel", "setWTA_K", "setScoreType", "setPatchSize", "getFastThreshold", "getDefaultName"],
|
||||
"MSER": ["create", "detectRegions", "setDelta", "getDelta", "setMinArea", "getMinArea", "setMaxArea", "getMaxArea", "setPass2Only", "getPass2Only", "getDefaultName"],
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
"FastFeatureDetector" : { "DetectorType": "FastDetectorType" }
|
||||
},
|
||||
"func_arg_fix" : {
|
||||
"goodFeaturesToTrack" : { "corners" : {"ctype" : "vector_Point"} },
|
||||
"Feature2D": {
|
||||
"(void)compute:(NSArray<Mat*>*)images keypoints:(NSMutableArray<NSMutableArray<KeyPoint*>*>*)keypoints descriptors:(NSMutableArray<Mat*>*)descriptors" : { "compute" : {"name" : "compute2"} },
|
||||
"(void)detect:(NSArray<Mat*>*)images keypoints:(NSMutableArray<NSMutableArray<KeyPoint*>*>*)keypoints masks:(NSArray<Mat*>*)masks" : { "detect" : {"name" : "detect2"} }
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
//
|
||||
// FeaturesTest.swift
|
||||
//
|
||||
// Created by Alexander Smorkalov on 2026/13/04.
|
||||
//
|
||||
|
||||
import XCTest
|
||||
import OpenCV
|
||||
|
||||
class ImgprocTest: OpenCVTestCase {
|
||||
func testGoodFeaturesToTrackMatListOfPointIntDoubleDouble() {
|
||||
let src = gray0
|
||||
Imgproc.rectangle(img: src, pt1: Point(x: 2, y: 2), pt2: Point(x: 8, y: 8), color: Scalar(100), thickness: -1)
|
||||
var lp = [Point]()
|
||||
|
||||
Imgproc.goodFeaturesToTrack(image: src, corners: &lp, maxCorners: 100, qualityLevel: 0.01, minDistance: 3)
|
||||
|
||||
XCTAssertEqual(4, lp.count)
|
||||
}
|
||||
|
||||
func testGoodFeaturesToTrackMatListOfPointIntDoubleDoubleMatIntBooleanDouble() {
|
||||
let src = gray0
|
||||
Imgproc.rectangle(img: src, pt1: Point(x: 2, y: 2), pt2: Point(x: 8, y: 8), color: Scalar(100), thickness: -1)
|
||||
var lp = [Point]()
|
||||
|
||||
Imgproc.goodFeaturesToTrack(image: src, corners: &lp, maxCorners: 100, qualityLevel: 0.01, minDistance: 3, mask: gray1, blockSize: 4, gradientSize: 3, useHarrisDetector: true, k: 0)
|
||||
|
||||
XCTAssertEqual(4, lp.count)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
// Copyright (C) 2010-2012, Multicoreware, Inc., all rights reserved.
|
||||
// Copyright (C) 2010-2012, Institute Of Software Chinese Academy Of Science, all rights reserved.
|
||||
// Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "../perf_precomp.hpp"
|
||||
#include "opencv2/ts/ocl_perf.hpp"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
|
||||
namespace opencv_test {
|
||||
namespace ocl {
|
||||
|
||||
//////////////////////////// GoodFeaturesToTrack //////////////////////////
|
||||
|
||||
typedef tuple<String, double, bool> GoodFeaturesToTrackParams;
|
||||
typedef TestBaseWithParam<GoodFeaturesToTrackParams> GoodFeaturesToTrackFixture;
|
||||
|
||||
OCL_PERF_TEST_P(GoodFeaturesToTrackFixture, GoodFeaturesToTrack,
|
||||
::testing::Combine(OCL_PERF_ENUM(String("gpu/opticalflow/rubberwhale1.png")),
|
||||
OCL_PERF_ENUM(0.0, 3.0), Bool()))
|
||||
{
|
||||
GoodFeaturesToTrackParams params = GetParam();
|
||||
const String fileName = get<0>(params);
|
||||
const double minDistance = get<1>(params), qualityLevel = 0.01;
|
||||
const bool harrisDetector = get<2>(params);
|
||||
const int maxCorners = 1000;
|
||||
|
||||
Mat img = imread(getDataPath(fileName), cv::IMREAD_GRAYSCALE);
|
||||
ASSERT_FALSE(img.empty()) << "could not load " << fileName;
|
||||
|
||||
checkDeviceMaxMemoryAllocSize(img.size(), img.type());
|
||||
|
||||
UMat src(img.size(), img.type()), dst(1, maxCorners, CV_32FC2);
|
||||
img.copyTo(src);
|
||||
|
||||
declare.in(src, WARMUP_READ).out(dst);
|
||||
|
||||
OCL_TEST_CYCLE() cv::goodFeaturesToTrack(src, dst, maxCorners, qualityLevel,
|
||||
minDistance, noArray(), 3, 3, harrisDetector, 0.04);
|
||||
|
||||
SANITY_CHECK(dst);
|
||||
}
|
||||
|
||||
OCL_PERF_TEST_P(GoodFeaturesToTrackFixture, GoodFeaturesToTrackWithQuality,
|
||||
::testing::Combine(OCL_PERF_ENUM(String("gpu/opticalflow/rubberwhale1.png")),
|
||||
OCL_PERF_ENUM(3.0), Bool()))
|
||||
{
|
||||
GoodFeaturesToTrackParams params = GetParam();
|
||||
const String fileName = get<0>(params);
|
||||
const double minDistance = get<1>(params), qualityLevel = 0.01;
|
||||
const bool harrisDetector = get<2>(params);
|
||||
const int maxCorners = 1000;
|
||||
|
||||
Mat img = imread(getDataPath(fileName), cv::IMREAD_GRAYSCALE);
|
||||
ASSERT_FALSE(img.empty()) << "could not load " << fileName;
|
||||
|
||||
checkDeviceMaxMemoryAllocSize(img.size(), img.type());
|
||||
|
||||
UMat src(img.size(), img.type()), dst(1, maxCorners, CV_32FC2);
|
||||
img.copyTo(src);
|
||||
|
||||
std::vector<float> cornersQuality;
|
||||
|
||||
declare.in(src, WARMUP_READ).out(dst);
|
||||
|
||||
OCL_TEST_CYCLE() cv::goodFeaturesToTrack(src, dst, maxCorners, qualityLevel, minDistance,
|
||||
noArray(), cornersQuality, 3, 3, harrisDetector, 0.04);
|
||||
|
||||
SANITY_CHECK(dst);
|
||||
SANITY_CHECK(cornersQuality, 1e-6);
|
||||
}
|
||||
|
||||
} } // namespace opencv_test::ocl
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,77 @@
|
||||
// This file is part of OpenCV project.
|
||||
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
||||
// of this distribution and at http://opencv.org/license.html.
|
||||
#include "perf_precomp.hpp"
|
||||
|
||||
namespace opencv_test {
|
||||
|
||||
typedef tuple<string, int, double, int, int, bool> Image_MaxCorners_QualityLevel_MinDistance_BlockSize_gradientSize_UseHarris_t;
|
||||
typedef perf::TestBaseWithParam<Image_MaxCorners_QualityLevel_MinDistance_BlockSize_gradientSize_UseHarris_t> Image_MaxCorners_QualityLevel_MinDistance_BlockSize_gradientSize_UseHarris;
|
||||
|
||||
PERF_TEST_P(Image_MaxCorners_QualityLevel_MinDistance_BlockSize_gradientSize_UseHarris, goodFeaturesToTrack,
|
||||
testing::Combine(
|
||||
testing::Values( "stitching/a1.png", "cv/shared/pic5.png"),
|
||||
testing::Values( 100, 500 ),
|
||||
testing::Values( 0.1, 0.01 ),
|
||||
testing::Values( 3, 5 ),
|
||||
testing::Values( 3, 5 ),
|
||||
testing::Bool()
|
||||
)
|
||||
)
|
||||
{
|
||||
string filename = getDataPath(get<0>(GetParam()));
|
||||
int maxCorners = get<1>(GetParam());
|
||||
double qualityLevel = get<2>(GetParam());
|
||||
int blockSize = get<3>(GetParam());
|
||||
int gradientSize = get<4>(GetParam());
|
||||
bool useHarrisDetector = get<5>(GetParam());
|
||||
|
||||
Mat image = imread(filename, IMREAD_GRAYSCALE);
|
||||
if (image.empty())
|
||||
FAIL() << "Unable to load source image" << filename;
|
||||
|
||||
std::vector<Point2f> corners;
|
||||
|
||||
double minDistance = 1;
|
||||
TEST_CYCLE() goodFeaturesToTrack(image, corners, maxCorners, qualityLevel, minDistance, noArray(), blockSize, gradientSize, useHarrisDetector);
|
||||
|
||||
if (corners.size() > 50)
|
||||
corners.erase(corners.begin() + 50, corners.end());
|
||||
|
||||
SANITY_CHECK(corners);
|
||||
}
|
||||
|
||||
PERF_TEST_P(Image_MaxCorners_QualityLevel_MinDistance_BlockSize_gradientSize_UseHarris, goodFeaturesToTrackWithQuality,
|
||||
testing::Combine(
|
||||
testing::Values( "stitching/a1.png", "cv/shared/pic5.png"),
|
||||
testing::Values( 50 ),
|
||||
testing::Values( 0.01 ),
|
||||
testing::Values( 3 ),
|
||||
testing::Values( 3 ),
|
||||
testing::Bool()
|
||||
)
|
||||
)
|
||||
{
|
||||
string filename = getDataPath(get<0>(GetParam()));
|
||||
int maxCorners = get<1>(GetParam());
|
||||
double qualityLevel = get<2>(GetParam());
|
||||
int blockSize = get<3>(GetParam());
|
||||
int gradientSize = get<4>(GetParam());
|
||||
bool useHarrisDetector = get<5>(GetParam());
|
||||
double minDistance = 1;
|
||||
|
||||
Mat image = imread(filename, IMREAD_GRAYSCALE);
|
||||
if (image.empty())
|
||||
FAIL() << "Unable to load source image" << filename;
|
||||
|
||||
std::vector<Point2f> corners;
|
||||
std::vector<float> cornersQuality;
|
||||
|
||||
TEST_CYCLE() goodFeaturesToTrack(image, corners, maxCorners, qualityLevel, minDistance, noArray(),
|
||||
cornersQuality, blockSize, gradientSize, useHarrisDetector);
|
||||
|
||||
SANITY_CHECK(corners);
|
||||
SANITY_CHECK(cornersQuality, 1e-6);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
@@ -0,0 +1,458 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "precomp.hpp"
|
||||
#include "opencl_kernels_features.hpp"
|
||||
|
||||
#include <cstdio>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <functional>
|
||||
|
||||
namespace cv
|
||||
{
|
||||
|
||||
struct greaterThanPtr
|
||||
{
|
||||
bool operator () (const float * a, const float * b) const
|
||||
// Ensure a fully deterministic result of the sort
|
||||
{ return (*a > *b) ? true : (*a < *b) ? false : (a > b); }
|
||||
};
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
|
||||
struct Corner
|
||||
{
|
||||
float val;
|
||||
short y;
|
||||
short x;
|
||||
|
||||
bool operator < (const Corner & c) const
|
||||
// Ensure a fully deterministic result of the sort
|
||||
{ return (val > c.val) ? true : (val < c.val) ? false : (y > c.y) ? true : (y < c.y) ? false : (x > c.x); }
|
||||
};
|
||||
|
||||
static bool ocl_goodFeaturesToTrack( InputArray _image, OutputArray _corners,
|
||||
int maxCorners, double qualityLevel, double minDistance,
|
||||
InputArray _mask, OutputArray _cornersQuality, int blockSize, int gradientSize,
|
||||
bool useHarrisDetector, double harrisK)
|
||||
{
|
||||
UMat eig, maxEigenValue;
|
||||
if( useHarrisDetector )
|
||||
cornerHarris( _image, eig, blockSize, gradientSize, harrisK );
|
||||
else
|
||||
cornerMinEigenVal( _image, eig, blockSize, gradientSize );
|
||||
|
||||
Size imgsize = _image.size();
|
||||
size_t total, i, j, ncorners = 0, possibleCornersCount =
|
||||
std::max(1024, static_cast<int>(imgsize.area() * 0.1));
|
||||
bool haveMask = !_mask.empty();
|
||||
UMat corners_buffer(1, (int)possibleCornersCount + 1, CV_32FC2);
|
||||
CV_Assert(sizeof(Corner) == corners_buffer.elemSize());
|
||||
Mat tmpCorners;
|
||||
|
||||
// find threshold
|
||||
{
|
||||
CV_Assert(eig.type() == CV_32FC1);
|
||||
int dbsize = ocl::Device::getDefault().maxComputeUnits();
|
||||
size_t wgs = ocl::Device::getDefault().maxWorkGroupSize();
|
||||
|
||||
int wgs2_aligned = 1;
|
||||
while (wgs2_aligned < (int)wgs)
|
||||
wgs2_aligned <<= 1;
|
||||
wgs2_aligned >>= 1;
|
||||
|
||||
ocl::Kernel k("maxEigenVal", ocl::features::gftt_oclsrc,
|
||||
format("-D OP_MAX_EIGEN_VAL -D WGS=%d -D groupnum=%d -D WGS2_ALIGNED=%d%s",
|
||||
(int)wgs, dbsize, wgs2_aligned, haveMask ? " -D HAVE_MASK" : ""));
|
||||
if (k.empty())
|
||||
return false;
|
||||
|
||||
UMat mask = _mask.getUMat();
|
||||
maxEigenValue.create(1, dbsize, CV_32FC1);
|
||||
|
||||
ocl::KernelArg eigarg = ocl::KernelArg::ReadOnlyNoSize(eig),
|
||||
dbarg = ocl::KernelArg::PtrWriteOnly(maxEigenValue),
|
||||
maskarg = ocl::KernelArg::ReadOnlyNoSize(mask),
|
||||
cornersarg = ocl::KernelArg::PtrWriteOnly(corners_buffer);
|
||||
|
||||
if (haveMask)
|
||||
k.args(eigarg, eig.cols, (int)eig.total(), dbarg, maskarg);
|
||||
else
|
||||
k.args(eigarg, eig.cols, (int)eig.total(), dbarg);
|
||||
|
||||
size_t globalsize = dbsize * wgs;
|
||||
if (!k.run(1, &globalsize, &wgs, false))
|
||||
return false;
|
||||
|
||||
ocl::Kernel k2("maxEigenValTask", ocl::features::gftt_oclsrc,
|
||||
format("-D OP_MAX_EIGEN_VAL -D WGS=%zu -D WGS2_ALIGNED=%d -D groupnum=%d",
|
||||
wgs, wgs2_aligned, dbsize));
|
||||
if (k2.empty())
|
||||
return false;
|
||||
|
||||
k2.args(dbarg, (float)qualityLevel, cornersarg);
|
||||
|
||||
if (!k2.runTask(false))
|
||||
return false;
|
||||
}
|
||||
|
||||
// collect list of pointers to features - put them into temporary image
|
||||
{
|
||||
ocl::Kernel k("findCorners", ocl::features::gftt_oclsrc,
|
||||
format("-D OP_FIND_CORNERS%s", haveMask ? " -D HAVE_MASK" : ""));
|
||||
if (k.empty())
|
||||
return false;
|
||||
|
||||
ocl::KernelArg eigarg = ocl::KernelArg::ReadOnlyNoSize(eig),
|
||||
cornersarg = ocl::KernelArg::PtrWriteOnly(corners_buffer),
|
||||
thresholdarg = ocl::KernelArg::PtrReadOnly(maxEigenValue);
|
||||
|
||||
if (!haveMask)
|
||||
k.args(eigarg, cornersarg, eig.rows - 2, eig.cols - 2, thresholdarg,
|
||||
(int)possibleCornersCount);
|
||||
else
|
||||
{
|
||||
UMat mask = _mask.getUMat();
|
||||
k.args(eigarg, ocl::KernelArg::ReadOnlyNoSize(mask),
|
||||
cornersarg, eig.rows - 2, eig.cols - 2,
|
||||
thresholdarg, (int)possibleCornersCount);
|
||||
}
|
||||
|
||||
size_t globalsize[2] = { (size_t)eig.cols - 2, (size_t)eig.rows - 2 };
|
||||
if (!k.run(2, globalsize, NULL, false))
|
||||
return false;
|
||||
|
||||
tmpCorners = corners_buffer.getMat(ACCESS_RW);
|
||||
total = std::min<size_t>(tmpCorners.at<Vec2i>(0, 0)[0], possibleCornersCount);
|
||||
if (total == 0)
|
||||
{
|
||||
_corners.release();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Corner* corner_ptr = tmpCorners.ptr<Corner>() + 1;
|
||||
std::sort(corner_ptr, corner_ptr + total);
|
||||
|
||||
std::vector<Point2f> corners;
|
||||
std::vector<float> cornersQuality;
|
||||
corners.reserve(total);
|
||||
cornersQuality.reserve(total);
|
||||
|
||||
if (minDistance >= 1)
|
||||
{
|
||||
// Partition the image into larger grids
|
||||
int w = imgsize.width, h = imgsize.height;
|
||||
|
||||
const int cell_size = cvRound(minDistance);
|
||||
const int grid_width = (w + cell_size - 1) / cell_size;
|
||||
const int grid_height = (h + cell_size - 1) / cell_size;
|
||||
|
||||
std::vector<std::vector<Point2f> > grid(grid_width*grid_height);
|
||||
minDistance *= minDistance;
|
||||
|
||||
for( i = 0; i < total; i++ )
|
||||
{
|
||||
const Corner & c = corner_ptr[i];
|
||||
bool good = true;
|
||||
|
||||
int x_cell = c.x / cell_size;
|
||||
int y_cell = c.y / cell_size;
|
||||
|
||||
int x1 = x_cell - 1;
|
||||
int y1 = y_cell - 1;
|
||||
int x2 = x_cell + 1;
|
||||
int y2 = y_cell + 1;
|
||||
|
||||
// boundary check
|
||||
x1 = std::max(0, x1);
|
||||
y1 = std::max(0, y1);
|
||||
x2 = std::min(grid_width - 1, x2);
|
||||
y2 = std::min(grid_height - 1, y2);
|
||||
|
||||
for( int yy = y1; yy <= y2; yy++ )
|
||||
for( int xx = x1; xx <= x2; xx++ )
|
||||
{
|
||||
std::vector<Point2f> &m = grid[yy * grid_width + xx];
|
||||
|
||||
if( m.size() )
|
||||
{
|
||||
for(j = 0; j < m.size(); j++)
|
||||
{
|
||||
float dx = c.x - m[j].x;
|
||||
float dy = c.y - m[j].y;
|
||||
|
||||
if( dx*dx + dy*dy < minDistance )
|
||||
{
|
||||
good = false;
|
||||
goto break_out;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
break_out:
|
||||
|
||||
if (good)
|
||||
{
|
||||
grid[y_cell*grid_width + x_cell].push_back(Point2f((float)c.x, (float)c.y));
|
||||
|
||||
corners.push_back(Point2f((float)c.x, (float)c.y));
|
||||
cornersQuality.push_back(c.val);
|
||||
++ncorners;
|
||||
|
||||
if( maxCorners > 0 && (int)ncorners == maxCorners )
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for( i = 0; i < total; i++ )
|
||||
{
|
||||
const Corner & c = corner_ptr[i];
|
||||
|
||||
corners.push_back(Point2f((float)c.x, (float)c.y));
|
||||
cornersQuality.push_back(c.val);
|
||||
++ncorners;
|
||||
|
||||
if( maxCorners > 0 && (int)ncorners == maxCorners )
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Mat(corners).reshape(2, (int)ncorners).
|
||||
convertTo(_corners, _corners.fixedType() ? _corners.type() : CV_32F);
|
||||
if (_cornersQuality.needed()) {
|
||||
Mat(cornersQuality).reshape(1, (int)ncorners).
|
||||
convertTo(_cornersQuality, _cornersQuality.fixedType() ? _cornersQuality.type() : CV_32F);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
void cv::goodFeaturesToTrack( InputArray image, OutputArray corners,
|
||||
int maxCorners, double qualityLevel, double minDistance,
|
||||
InputArray mask, int blockSize, bool useHarrisDetector, double k )
|
||||
{
|
||||
return goodFeaturesToTrack(image, corners, maxCorners, qualityLevel, minDistance,
|
||||
mask, noArray(), blockSize, 3, useHarrisDetector, k);
|
||||
}
|
||||
|
||||
void cv::goodFeaturesToTrack( InputArray image, OutputArray corners,
|
||||
int maxCorners, double qualityLevel, double minDistance,
|
||||
InputArray mask, int blockSize, int gradientSize, bool useHarrisDetector, double k )
|
||||
{
|
||||
return goodFeaturesToTrack( image, corners, maxCorners, qualityLevel, minDistance,
|
||||
mask, noArray(), blockSize, gradientSize, useHarrisDetector, k );
|
||||
}
|
||||
|
||||
void cv::goodFeaturesToTrack( InputArray _image, OutputArray _corners,
|
||||
int maxCorners, double qualityLevel, double minDistance,
|
||||
InputArray _mask, OutputArray _cornersQuality, int blockSize, int gradientSize,
|
||||
bool useHarrisDetector, double harrisK )
|
||||
{
|
||||
CV_INSTRUMENT_REGION();
|
||||
|
||||
CV_Assert( qualityLevel > 0 && minDistance >= 0 && maxCorners >= 0 );
|
||||
CV_Assert( _mask.empty() || ((_mask.type() == CV_8UC1 || _mask.type() == CV_BoolC1) && _mask.sameSize(_image)) );
|
||||
|
||||
CV_OCL_RUN(_image.dims() <= 2 && _image.isUMat(),
|
||||
ocl_goodFeaturesToTrack(_image, _corners, maxCorners, qualityLevel, minDistance,
|
||||
_mask, _cornersQuality, blockSize, gradientSize, useHarrisDetector, harrisK))
|
||||
|
||||
Mat image = _image.getMat(), eig, tmp;
|
||||
if (image.empty())
|
||||
{
|
||||
_corners.release();
|
||||
_cornersQuality.release();
|
||||
return;
|
||||
}
|
||||
|
||||
if( useHarrisDetector )
|
||||
cornerHarris( image, eig, blockSize, gradientSize, harrisK );
|
||||
else
|
||||
cornerMinEigenVal( image, eig, blockSize, gradientSize );
|
||||
|
||||
double maxVal = 0;
|
||||
minMaxLoc( eig, 0, &maxVal, 0, 0, _mask );
|
||||
threshold( eig, eig, maxVal*qualityLevel, 0, THRESH_TOZERO );
|
||||
dilate( eig, tmp, Mat());
|
||||
|
||||
Size imgsize = image.size();
|
||||
std::vector<const float*> tmpCorners;
|
||||
|
||||
// collect list of pointers to features - put them into temporary image
|
||||
Mat mask = _mask.getMat();
|
||||
for( int y = 1; y < imgsize.height - 1; y++ )
|
||||
{
|
||||
const float* eig_data = (const float*)eig.ptr(y);
|
||||
const float* tmp_data = (const float*)tmp.ptr(y);
|
||||
const uchar* mask_data = mask.data ? mask.ptr(y) : 0;
|
||||
|
||||
for( int x = 1; x < imgsize.width - 1; x++ )
|
||||
{
|
||||
float val = eig_data[x];
|
||||
if( val != 0 && val == tmp_data[x] && (!mask_data || mask_data[x]) )
|
||||
tmpCorners.push_back(eig_data + x);
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<Point2f> corners;
|
||||
std::vector<float> cornersQuality;
|
||||
size_t i, j, total = tmpCorners.size(), ncorners = 0;
|
||||
|
||||
if (total == 0)
|
||||
{
|
||||
_corners.release();
|
||||
_cornersQuality.release();
|
||||
return;
|
||||
}
|
||||
|
||||
std::sort( tmpCorners.begin(), tmpCorners.end(), greaterThanPtr() );
|
||||
|
||||
if (minDistance >= 1)
|
||||
{
|
||||
// Partition the image into larger grids
|
||||
int w = image.cols;
|
||||
int h = image.rows;
|
||||
|
||||
const int cell_size = cvRound(minDistance);
|
||||
const int grid_width = (w + cell_size - 1) / cell_size;
|
||||
const int grid_height = (h + cell_size - 1) / cell_size;
|
||||
|
||||
std::vector<std::vector<Point2f> > grid(grid_width*grid_height);
|
||||
|
||||
minDistance *= minDistance;
|
||||
|
||||
for( i = 0; i < total; i++ )
|
||||
{
|
||||
int ofs = (int)((const uchar*)tmpCorners[i] - eig.ptr());
|
||||
int y = (int)(ofs / eig.step);
|
||||
int x = (int)((ofs - y*eig.step)/sizeof(float));
|
||||
|
||||
bool good = true;
|
||||
|
||||
int x_cell = x / cell_size;
|
||||
int y_cell = y / cell_size;
|
||||
|
||||
int x1 = x_cell - 1;
|
||||
int y1 = y_cell - 1;
|
||||
int x2 = x_cell + 1;
|
||||
int y2 = y_cell + 1;
|
||||
|
||||
// boundary check
|
||||
x1 = std::max(0, x1);
|
||||
y1 = std::max(0, y1);
|
||||
x2 = std::min(grid_width-1, x2);
|
||||
y2 = std::min(grid_height-1, y2);
|
||||
|
||||
for( int yy = y1; yy <= y2; yy++ )
|
||||
{
|
||||
for( int xx = x1; xx <= x2; xx++ )
|
||||
{
|
||||
std::vector <Point2f> &m = grid[yy*grid_width + xx];
|
||||
|
||||
if( m.size() )
|
||||
{
|
||||
for(j = 0; j < m.size(); j++)
|
||||
{
|
||||
float dx = x - m[j].x;
|
||||
float dy = y - m[j].y;
|
||||
|
||||
if( dx*dx + dy*dy < minDistance )
|
||||
{
|
||||
good = false;
|
||||
goto break_out;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
break_out:
|
||||
|
||||
if (good)
|
||||
{
|
||||
grid[y_cell*grid_width + x_cell].push_back(Point2f((float)x, (float)y));
|
||||
|
||||
cornersQuality.push_back(*tmpCorners[i]);
|
||||
|
||||
corners.push_back(Point2f((float)x, (float)y));
|
||||
++ncorners;
|
||||
|
||||
if( maxCorners > 0 && (int)ncorners == maxCorners )
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for( i = 0; i < total; i++ )
|
||||
{
|
||||
cornersQuality.push_back(*tmpCorners[i]);
|
||||
|
||||
int ofs = (int)((const uchar*)tmpCorners[i] - eig.ptr());
|
||||
int y = (int)(ofs / eig.step);
|
||||
int x = (int)((ofs - y*eig.step)/sizeof(float));
|
||||
|
||||
corners.push_back(Point2f((float)x, (float)y));
|
||||
++ncorners;
|
||||
|
||||
if( maxCorners > 0 && (int)ncorners == maxCorners )
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Mat(corners).reshape(2, (int)ncorners).
|
||||
convertTo(_corners, _corners.fixedType() ? _corners.type() : CV_32F);
|
||||
if (_cornersQuality.needed()) {
|
||||
Mat(cornersQuality).reshape(1, (int)ncorners).
|
||||
convertTo(_cornersQuality, _cornersQuality.fixedType() ? _cornersQuality.type() : CV_32F);
|
||||
}
|
||||
}
|
||||
|
||||
/* End of file. */
|
||||
@@ -0,0 +1,161 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2010-2012, Institute Of Software Chinese Academy Of Science, all rights reserved.
|
||||
// Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// @Authors
|
||||
// Zhang Ying, zhangying913@gmail.com
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors as is and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifdef OP_MAX_EIGEN_VAL
|
||||
|
||||
__kernel void maxEigenVal(__global const uchar * srcptr, int src_step, int src_offset, int cols,
|
||||
int total, __global uchar * dstptr
|
||||
#ifdef HAVE_MASK
|
||||
, __global const uchar * maskptr, int mask_step, int mask_offset
|
||||
#endif
|
||||
)
|
||||
{
|
||||
int lid = get_local_id(0);
|
||||
int gid = get_group_id(0);
|
||||
int id = get_global_id(0);
|
||||
|
||||
__local float localmem_max[WGS2_ALIGNED];
|
||||
float maxval = -FLT_MAX;
|
||||
|
||||
for (int grain = groupnum * WGS; id < total; id += grain)
|
||||
{
|
||||
int src_index = mad24(id / cols, src_step, mad24((id % cols), (int)sizeof(float), src_offset));
|
||||
#ifdef HAVE_MASK
|
||||
int mask_index = mad24(id / cols, mask_step, id % cols + mask_offset);
|
||||
if (maskptr[mask_index])
|
||||
#endif
|
||||
maxval = max(maxval, *(__global const float *)(srcptr + src_index));
|
||||
}
|
||||
|
||||
if (lid < WGS2_ALIGNED)
|
||||
localmem_max[lid] = maxval;
|
||||
barrier(CLK_LOCAL_MEM_FENCE);
|
||||
|
||||
if (lid >= WGS2_ALIGNED && total >= WGS2_ALIGNED)
|
||||
localmem_max[lid - WGS2_ALIGNED] = max(maxval, localmem_max[lid - WGS2_ALIGNED]);
|
||||
barrier(CLK_LOCAL_MEM_FENCE);
|
||||
|
||||
for (int lsize = WGS2_ALIGNED >> 1; lsize > 0; lsize >>= 1)
|
||||
{
|
||||
if (lid < lsize)
|
||||
{
|
||||
int lid2 = lsize + lid;
|
||||
localmem_max[lid] = max(localmem_max[lid], localmem_max[lid2]);
|
||||
}
|
||||
barrier(CLK_LOCAL_MEM_FENCE);
|
||||
}
|
||||
|
||||
if (lid == 0)
|
||||
*(__global float *)(dstptr + (int)sizeof(float) * gid) = localmem_max[0];
|
||||
}
|
||||
|
||||
__kernel void maxEigenValTask(__global float * dst, float qualityLevel,
|
||||
__global int * cornersptr)
|
||||
{
|
||||
float maxval = -FLT_MAX;
|
||||
|
||||
#pragma unroll
|
||||
for (int x = 0; x < groupnum; ++x)
|
||||
maxval = max(maxval, dst[x]);
|
||||
|
||||
dst[0] = maxval * qualityLevel;
|
||||
cornersptr[0] = 0;
|
||||
}
|
||||
|
||||
#elif OP_FIND_CORNERS
|
||||
|
||||
#define GET_SRC_32F(_y, _x) *(__global const float *)(eigptr + (_y) * eig_step + (_x) * (int)sizeof(float) )
|
||||
|
||||
__kernel void findCorners(__global const uchar * eigptr, int eig_step, int eig_offset,
|
||||
#ifdef HAVE_MASK
|
||||
__global const uchar * mask, int mask_step, int mask_offset,
|
||||
#endif
|
||||
__global uchar * cornersptr, int rows, int cols,
|
||||
__constant float * threshold, int max_corners)
|
||||
{
|
||||
int x = get_global_id(0);
|
||||
int y = get_global_id(1);
|
||||
|
||||
__global int* counter = (__global int*) cornersptr;
|
||||
__global float2 * corners = (__global float2 *)(cornersptr + (int)sizeof(float2));
|
||||
|
||||
if (y < rows && x < cols
|
||||
#ifdef HAVE_MASK
|
||||
&& mask[mad24(y, mask_step, x + mask_offset)]
|
||||
#endif
|
||||
)
|
||||
{
|
||||
++x, ++y;
|
||||
float val = GET_SRC_32F(y, x);
|
||||
|
||||
if (val > threshold[0])
|
||||
{
|
||||
float maxVal = val;
|
||||
maxVal = max(GET_SRC_32F(y - 1, x - 1), maxVal);
|
||||
maxVal = max(GET_SRC_32F(y - 1, x ), maxVal);
|
||||
maxVal = max(GET_SRC_32F(y - 1, x + 1), maxVal);
|
||||
|
||||
maxVal = max(GET_SRC_32F(y , x - 1), maxVal);
|
||||
maxVal = max(GET_SRC_32F(y , x + 1), maxVal);
|
||||
|
||||
maxVal = max(GET_SRC_32F(y + 1, x - 1), maxVal);
|
||||
maxVal = max(GET_SRC_32F(y + 1, x ), maxVal);
|
||||
maxVal = max(GET_SRC_32F(y + 1, x + 1), maxVal);
|
||||
|
||||
if (val == maxVal)
|
||||
{
|
||||
int ind = atomic_inc(counter);
|
||||
if (ind < max_corners)
|
||||
{
|
||||
// pack and store eigenvalue and its coordinates
|
||||
corners[ind].x = val;
|
||||
corners[ind].y = as_float(y | (x << 16));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,149 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
// Copyright (C) 2010-2012, Multicoreware, Inc., all rights reserved.
|
||||
// Copyright (C) 2010-2012, Institute Of Software Chinese Academy Of Science, all rights reserved.
|
||||
// Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "../test_precomp.hpp"
|
||||
#include "opencv2/ts/ocl_test.hpp"
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
|
||||
namespace opencv_test {
|
||||
namespace ocl {
|
||||
|
||||
//////////////////////////// GoodFeaturesToTrack //////////////////////////
|
||||
|
||||
|
||||
PARAM_TEST_CASE(GoodFeaturesToTrack, double, bool)
|
||||
{
|
||||
double minDistance;
|
||||
bool useRoi;
|
||||
|
||||
static const int maxCorners;
|
||||
static const double qualityLevel;
|
||||
|
||||
TEST_DECLARE_INPUT_PARAMETER(src);
|
||||
UMat points, upoints;
|
||||
std::vector<float> quality, uquality;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
minDistance = GET_PARAM(0);
|
||||
useRoi = GET_PARAM(1);
|
||||
}
|
||||
|
||||
void generateTestData()
|
||||
{
|
||||
Mat frame = readImage("../gpu/opticalflow/rubberwhale1.png", IMREAD_GRAYSCALE);
|
||||
ASSERT_FALSE(frame.empty()) << "could not load gpu/opticalflow/rubberwhale1.png";
|
||||
|
||||
Size roiSize = frame.size();
|
||||
Border srcBorder = randomBorder(0, useRoi ? 2 : 0);
|
||||
randomSubMat(src, src_roi, roiSize, srcBorder, frame.type(), 5, 256);
|
||||
src_roi.copyTo(frame);
|
||||
|
||||
UMAT_UPLOAD_INPUT_PARAMETER(src);
|
||||
}
|
||||
|
||||
void UMatToVector(const UMat & um, std::vector<Point2f> & v) const
|
||||
{
|
||||
v.resize(um.size().area());
|
||||
um.copyTo(Mat(um.size(), CV_32FC2, &v[0]));
|
||||
}
|
||||
};
|
||||
|
||||
const int GoodFeaturesToTrack::maxCorners = 1000;
|
||||
const double GoodFeaturesToTrack::qualityLevel = 0.01;
|
||||
|
||||
OCL_TEST_P(GoodFeaturesToTrack, Accuracy)
|
||||
{
|
||||
for (int j = 0; j < test_loop_times; ++j)
|
||||
{
|
||||
generateTestData();
|
||||
|
||||
std::vector<Point2f> upts, pts;
|
||||
|
||||
OCL_OFF(cv::goodFeaturesToTrack(src_roi, points, maxCorners, qualityLevel, minDistance, noArray(), quality));
|
||||
ASSERT_FALSE(points.empty());
|
||||
UMatToVector(points, pts);
|
||||
|
||||
OCL_ON(cv::goodFeaturesToTrack(usrc_roi, upoints, maxCorners, qualityLevel, minDistance, noArray(), uquality));
|
||||
ASSERT_FALSE(upoints.empty());
|
||||
UMatToVector(upoints, upts);
|
||||
|
||||
ASSERT_EQ(pts.size(), quality.size());
|
||||
ASSERT_EQ(upts.size(), uquality.size());
|
||||
ASSERT_EQ(upts.size(), pts.size());
|
||||
|
||||
int mistmatch = 0;
|
||||
for (size_t i = 0; i < pts.size(); ++i)
|
||||
{
|
||||
Point2i a = upts[i], b = pts[i];
|
||||
|
||||
bool eq = std::abs(a.x - b.x) < 1 && std::abs(a.y - b.y) < 1 &&
|
||||
std::abs(quality[i] - uquality[i]) <= 3.f * FLT_EPSILON * std::max(quality[i], uquality[i]);
|
||||
|
||||
if (!eq)
|
||||
++mistmatch;
|
||||
}
|
||||
|
||||
double bad_ratio = static_cast<double>(mistmatch) / pts.size();
|
||||
ASSERT_GE(1e-2, bad_ratio);
|
||||
}
|
||||
}
|
||||
|
||||
OCL_TEST_P(GoodFeaturesToTrack, EmptyCorners)
|
||||
{
|
||||
generateTestData();
|
||||
usrc_roi.setTo(Scalar::all(0));
|
||||
|
||||
OCL_ON(cv::goodFeaturesToTrack(usrc_roi, upoints, maxCorners, qualityLevel, minDistance, noArray(), uquality));
|
||||
|
||||
ASSERT_TRUE(upoints.empty());
|
||||
ASSERT_TRUE(uquality.empty());
|
||||
}
|
||||
|
||||
OCL_INSTANTIATE_TEST_CASE_P(Imgproc, GoodFeaturesToTrack,
|
||||
::testing::Combine(testing::Values(0.0, 3.0), Bool()));
|
||||
|
||||
} } // namespace opencv_test::ocl
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,550 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "test_precomp.hpp"
|
||||
|
||||
namespace opencv_test { namespace {
|
||||
|
||||
enum { MINEIGENVAL=0, HARRIS=1, EIGENVALSVECS=2 };
|
||||
|
||||
|
||||
#if 0 //set 1 to switch ON debug message
|
||||
#define TEST_MESSAGE( message ) std::cout << message;
|
||||
#define TEST_MESSAGEL( message, val) std::cout << message << val << std::endl;
|
||||
#else
|
||||
#define TEST_MESSAGE( message )
|
||||
#define TEST_MESSAGEL( message, val)
|
||||
#endif
|
||||
|
||||
/////////////////////ref//////////////////////
|
||||
|
||||
struct greaterThanPtr
|
||||
{
|
||||
bool operator () (const float * a, const float * b) const
|
||||
{ return *a > *b; }
|
||||
};
|
||||
|
||||
static void
|
||||
test_cornerEigenValsVecs( const Mat& src, Mat& eigenv, int block_size,
|
||||
int _aperture_size, double k, int mode, int borderType, const Scalar& _borderValue )
|
||||
{
|
||||
int i, j;
|
||||
Scalar borderValue = _borderValue;
|
||||
int aperture_size = _aperture_size < 0 ? 3 : _aperture_size;
|
||||
Point anchor( aperture_size/2, aperture_size/2 );
|
||||
|
||||
CV_Assert( src.type() == CV_8UC1 || src.type() == CV_32FC1 );
|
||||
CV_Assert( eigenv.type() == CV_32FC1 );
|
||||
CV_Assert( ( src.rows == eigenv.rows ) &&
|
||||
(((mode == MINEIGENVAL)||(mode == HARRIS)) && (src.cols == eigenv.cols)) );
|
||||
|
||||
int type = src.type();
|
||||
int ftype = CV_32FC1;
|
||||
double kernel_scale = 1;
|
||||
|
||||
Mat dx2, dy2, dxdy(src.size(), CV_32F), kernel;
|
||||
|
||||
kernel = cvtest::calcSobelKernel2D( 1, 0, _aperture_size );
|
||||
cvtest::filter2D( src, dx2, ftype, kernel*kernel_scale, anchor, 0, borderType, borderValue );
|
||||
kernel = cvtest::calcSobelKernel2D( 0, 1, _aperture_size );
|
||||
cvtest::filter2D( src, dy2, ftype, kernel*kernel_scale, anchor, 0, borderType,borderValue );
|
||||
|
||||
double denom = (1 << (aperture_size-1))*block_size;
|
||||
|
||||
if( _aperture_size < 0 )
|
||||
denom *= 2.;
|
||||
if(type != ftype )
|
||||
denom *= 255.;
|
||||
|
||||
denom = 1. / (denom * denom);
|
||||
|
||||
for( i = 0; i < src.rows; i++ )
|
||||
{
|
||||
float* dxdyp = dxdy.ptr<float>(i);
|
||||
float* dx2p = dx2.ptr<float>(i);
|
||||
float* dy2p = dy2.ptr<float>(i);
|
||||
|
||||
for( j = 0; j < src.cols; j++ )
|
||||
{
|
||||
double xval = dx2p[j], yval = dy2p[j];
|
||||
dxdyp[j] = (float)(xval*yval*denom);
|
||||
dx2p[j] = (float)(xval*xval*denom);
|
||||
dy2p[j] = (float)(yval*yval*denom);
|
||||
}
|
||||
}
|
||||
|
||||
kernel = Mat::ones(block_size, block_size, CV_32F);
|
||||
anchor = Point(block_size/2, block_size/2);
|
||||
|
||||
cvtest::filter2D( dx2, dx2, ftype, kernel, anchor, 0, borderType, borderValue );
|
||||
cvtest::filter2D( dy2, dy2, ftype, kernel, anchor, 0, borderType, borderValue );
|
||||
cvtest::filter2D( dxdy, dxdy, ftype, kernel, anchor, 0, borderType, borderValue );
|
||||
|
||||
if( mode == MINEIGENVAL )
|
||||
{
|
||||
for( i = 0; i < src.rows; i++ )
|
||||
{
|
||||
float* eigenvp = eigenv.ptr<float>(i);
|
||||
const float* dxdyp = dxdy.ptr<float>(i);
|
||||
const float* dx2p = dx2.ptr<float>(i);
|
||||
const float* dy2p = dy2.ptr<float>(i);
|
||||
|
||||
for( j = 0; j < src.cols; j++ )
|
||||
{
|
||||
double a = dx2p[j], b = dxdyp[j], c = dy2p[j];
|
||||
double d = sqrt( ( a - c )*( a - c ) + 4*b*b );
|
||||
eigenvp[j] = (float)( 0.5*(a + c - d));
|
||||
}
|
||||
}
|
||||
}
|
||||
else if( mode == HARRIS )
|
||||
{
|
||||
|
||||
for( i = 0; i < src.rows; i++ )
|
||||
{
|
||||
float* eigenvp = eigenv.ptr<float>(i);
|
||||
const float* dxdyp = dxdy.ptr<float>(i);
|
||||
const float* dx2p = dx2.ptr<float>(i);
|
||||
const float* dy2p = dy2.ptr<float>(i);
|
||||
|
||||
for( j = 0; j < src.cols; j++ )
|
||||
{
|
||||
double a = dx2p[j], b = dxdyp[j], c = dy2p[j];
|
||||
eigenvp[j] = (float)(a*c - b*b - k*(a + c)*(a + c));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
test_goodFeaturesToTrack( InputArray _image, OutputArray _corners,
|
||||
int maxCorners, double qualityLevel, double minDistance,
|
||||
InputArray _mask, OutputArray _cornersQuality,
|
||||
int blockSize, int gradientSize, bool useHarrisDetector, double harrisK)
|
||||
{
|
||||
|
||||
CV_Assert( qualityLevel > 0 && minDistance >= 0 && maxCorners >= 0 );
|
||||
CV_Assert( _mask.empty() || (_mask.type() == CV_8UC1 && _mask.sameSize(_image)) );
|
||||
|
||||
|
||||
Mat image = _image.getMat(), mask = _mask.getMat();
|
||||
int aperture_size = gradientSize;
|
||||
int borderType = BORDER_DEFAULT;
|
||||
|
||||
Mat eig, tmp, tt;
|
||||
|
||||
eig.create( image.size(), CV_32F );
|
||||
|
||||
if( useHarrisDetector )
|
||||
test_cornerEigenValsVecs( image, eig, blockSize, aperture_size, harrisK, HARRIS, borderType, 0 );
|
||||
else
|
||||
test_cornerEigenValsVecs( image, eig, blockSize, aperture_size, 0, MINEIGENVAL, borderType, 0 );
|
||||
|
||||
double maxVal = 0;
|
||||
|
||||
cvtest::minMaxIdx( eig, 0, &maxVal, 0, 0, mask );
|
||||
cvtest::threshold( eig, eig, (float)(maxVal*qualityLevel), 0.f,THRESH_TOZERO );
|
||||
cvtest::dilate( eig, tmp, Mat(),Point(-1,-1),borderType,0);
|
||||
|
||||
Size imgsize = image.size();
|
||||
|
||||
vector<const float*> tmpCorners;
|
||||
|
||||
// collect list of pointers to features - put them into temporary image
|
||||
for( int y = 1; y < imgsize.height - 1; y++ )
|
||||
{
|
||||
const float* eig_data = (const float*)eig.ptr(y);
|
||||
const float* tmp_data = (const float*)tmp.ptr(y);
|
||||
const uchar* mask_data = mask.data ? mask.ptr(y) : 0;
|
||||
|
||||
for( int x = 1; x < imgsize.width - 1; x++ )
|
||||
{
|
||||
float val = eig_data[x];
|
||||
if( val != 0 && val == tmp_data[x] && (!mask_data || mask_data[x]) )
|
||||
{
|
||||
tmpCorners.push_back(eig_data + x);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
vector<Point2f> corners;
|
||||
vector<float> cornersQuality;
|
||||
size_t i, j, total = tmpCorners.size(), ncorners = 0;
|
||||
|
||||
std::sort( tmpCorners.begin(), tmpCorners.end(), greaterThanPtr() );
|
||||
|
||||
if(minDistance >= 1)
|
||||
{
|
||||
// Partition the image into larger grids
|
||||
int w = image.cols;
|
||||
int h = image.rows;
|
||||
|
||||
const int cell_size = cvRound(minDistance);
|
||||
const int grid_width = (w + cell_size - 1) / cell_size;
|
||||
const int grid_height = (h + cell_size - 1) / cell_size;
|
||||
|
||||
std::vector<std::vector<Point2f> > grid(grid_width*grid_height);
|
||||
|
||||
minDistance *= minDistance;
|
||||
|
||||
for( i = 0; i < total; i++ )
|
||||
{
|
||||
int ofs = (int)((const uchar*)tmpCorners[i] - eig.data);
|
||||
int y = (int)(ofs / eig.step);
|
||||
int x = (int)((ofs - y*eig.step)/sizeof(float));
|
||||
|
||||
bool good = true;
|
||||
|
||||
int x_cell = x / cell_size;
|
||||
int y_cell = y / cell_size;
|
||||
|
||||
int x1 = x_cell - 1;
|
||||
int y1 = y_cell - 1;
|
||||
int x2 = x_cell + 1;
|
||||
int y2 = y_cell + 1;
|
||||
|
||||
// boundary check
|
||||
x1 = std::max(0, x1);
|
||||
y1 = std::max(0, y1);
|
||||
x2 = std::min(grid_width-1, x2);
|
||||
y2 = std::min(grid_height-1, y2);
|
||||
|
||||
for( int yy = y1; yy <= y2; yy++ )
|
||||
{
|
||||
for( int xx = x1; xx <= x2; xx++ )
|
||||
{
|
||||
vector <Point2f> &m = grid[yy*grid_width + xx];
|
||||
|
||||
if( m.size() )
|
||||
{
|
||||
for(j = 0; j < m.size(); j++)
|
||||
{
|
||||
float dx = x - m[j].x;
|
||||
float dy = y - m[j].y;
|
||||
|
||||
if( dx*dx + dy*dy < minDistance )
|
||||
{
|
||||
good = false;
|
||||
goto break_out;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
break_out:
|
||||
|
||||
if(good)
|
||||
{
|
||||
grid[y_cell*grid_width + x_cell].push_back(Point2f((float)x, (float)y));
|
||||
|
||||
cornersQuality.push_back(*tmpCorners[i]);
|
||||
|
||||
corners.push_back(Point2f((float)x, (float)y));
|
||||
++ncorners;
|
||||
|
||||
if( maxCorners > 0 && (int)ncorners == maxCorners )
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for( i = 0; i < total; i++ )
|
||||
{
|
||||
cornersQuality.push_back(*tmpCorners[i]);
|
||||
|
||||
int ofs = (int)((const uchar*)tmpCorners[i] - eig.data);
|
||||
int y = (int)(ofs / eig.step);
|
||||
int x = (int)((ofs - y*eig.step)/sizeof(float));
|
||||
|
||||
corners.push_back(Point2f((float)x, (float)y));
|
||||
++ncorners;
|
||||
|
||||
if( maxCorners > 0 && (int)ncorners == maxCorners )
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Mat(corners).convertTo(_corners, _corners.fixedType() ? _corners.type() : CV_32F);
|
||||
if (_cornersQuality.needed()) {
|
||||
Mat(cornersQuality).convertTo(_cornersQuality, _cornersQuality.fixedType() ? _cornersQuality.type() : CV_32F);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/////////////////end of ref code//////////////////////////
|
||||
|
||||
|
||||
|
||||
class CV_GoodFeatureToTTest : public cvtest::ArrayTest
|
||||
{
|
||||
public:
|
||||
CV_GoodFeatureToTTest();
|
||||
|
||||
protected:
|
||||
int prepare_test_case( int test_case_idx );
|
||||
void run_func();
|
||||
int validate_test_results( int test_case_idx );
|
||||
|
||||
Mat src, src_gray;
|
||||
Mat src_gray32f, src_gray8U;
|
||||
Mat mask;
|
||||
|
||||
int maxCorners;
|
||||
vector<Point2f> corners;
|
||||
vector<Point2f> Refcorners;
|
||||
vector<float> cornersQuality;
|
||||
vector<float> RefcornersQuality;
|
||||
double qualityLevel;
|
||||
double minDistance;
|
||||
int blockSize;
|
||||
int gradientSize;
|
||||
bool useHarrisDetector;
|
||||
double k;
|
||||
int SrcType;
|
||||
};
|
||||
|
||||
|
||||
CV_GoodFeatureToTTest::CV_GoodFeatureToTTest()
|
||||
{
|
||||
RNG& rng = ts->get_rng();
|
||||
maxCorners = rng.uniform( 50, 100 );
|
||||
qualityLevel = 0.01;
|
||||
minDistance = 10;
|
||||
blockSize = 3;
|
||||
gradientSize = 3;
|
||||
useHarrisDetector = false;
|
||||
k = 0.04;
|
||||
mask = Mat();
|
||||
test_case_count = 4;
|
||||
SrcType = 0;
|
||||
}
|
||||
|
||||
int CV_GoodFeatureToTTest::prepare_test_case( int test_case_idx )
|
||||
{
|
||||
const static int types[] = { CV_32FC1, CV_8UC1 };
|
||||
|
||||
cvtest::TS& tst = *cvtest::TS::ptr();
|
||||
src = imread(string(tst.get_data_path()) + "shared/fruits.png", IMREAD_COLOR);
|
||||
|
||||
CV_Assert(src.data != NULL);
|
||||
|
||||
cvtColor( src, src_gray, COLOR_BGR2GRAY );
|
||||
SrcType = types[test_case_idx & 0x1];
|
||||
useHarrisDetector = test_case_idx & 2 ? true : false;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
void CV_GoodFeatureToTTest::run_func()
|
||||
{
|
||||
int cn = src_gray.channels();
|
||||
|
||||
CV_Assert( cn == 1 );
|
||||
CV_Assert( ( CV_MAT_DEPTH(SrcType) == CV_32FC1 ) || ( CV_MAT_DEPTH(SrcType) == CV_8UC1 ));
|
||||
|
||||
TEST_MESSAGEL (" maxCorners = ", maxCorners)
|
||||
if (useHarrisDetector)
|
||||
{
|
||||
TEST_MESSAGE (" useHarrisDetector = true\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
TEST_MESSAGE (" useHarrisDetector = false\n");
|
||||
}
|
||||
|
||||
if( CV_MAT_DEPTH(SrcType) == CV_32FC1)
|
||||
{
|
||||
if (src_gray.depth() != CV_32FC1 ) src_gray.convertTo(src_gray32f, CV_32FC1);
|
||||
else src_gray32f = src_gray.clone();
|
||||
|
||||
TEST_MESSAGE ("goodFeaturesToTrack 32f\n")
|
||||
|
||||
goodFeaturesToTrack( src_gray32f,
|
||||
corners,
|
||||
maxCorners,
|
||||
qualityLevel,
|
||||
minDistance,
|
||||
Mat(),
|
||||
cornersQuality,
|
||||
blockSize,
|
||||
gradientSize,
|
||||
useHarrisDetector,
|
||||
k );
|
||||
}
|
||||
else
|
||||
{
|
||||
if (src_gray.depth() != CV_8UC1 ) src_gray.convertTo(src_gray8U, CV_8UC1);
|
||||
else src_gray8U = src_gray.clone();
|
||||
|
||||
TEST_MESSAGE ("goodFeaturesToTrack 8U\n")
|
||||
|
||||
goodFeaturesToTrack( src_gray8U,
|
||||
corners,
|
||||
maxCorners,
|
||||
qualityLevel,
|
||||
minDistance,
|
||||
Mat(),
|
||||
cornersQuality,
|
||||
blockSize,
|
||||
gradientSize,
|
||||
useHarrisDetector,
|
||||
k );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int CV_GoodFeatureToTTest::validate_test_results( int test_case_idx )
|
||||
{
|
||||
static const double eps = 2e-6;
|
||||
|
||||
if( CV_MAT_DEPTH(SrcType) == CV_32FC1 )
|
||||
{
|
||||
if (src_gray.depth() != CV_32FC1 ) src_gray.convertTo(src_gray32f, CV_32FC1);
|
||||
else src_gray32f = src_gray.clone();
|
||||
|
||||
TEST_MESSAGE ("test_goodFeaturesToTrack 32f\n")
|
||||
|
||||
test_goodFeaturesToTrack( src_gray32f,
|
||||
Refcorners,
|
||||
maxCorners,
|
||||
qualityLevel,
|
||||
minDistance,
|
||||
Mat(),
|
||||
RefcornersQuality,
|
||||
blockSize,
|
||||
gradientSize,
|
||||
useHarrisDetector,
|
||||
k );
|
||||
}
|
||||
else
|
||||
{
|
||||
if (src_gray.depth() != CV_8UC1 ) src_gray.convertTo(src_gray8U, CV_8UC1);
|
||||
else src_gray8U = src_gray.clone();
|
||||
|
||||
TEST_MESSAGE ("test_goodFeaturesToTrack 8U\n")
|
||||
|
||||
test_goodFeaturesToTrack( src_gray8U,
|
||||
Refcorners,
|
||||
maxCorners,
|
||||
qualityLevel,
|
||||
minDistance,
|
||||
Mat(),
|
||||
RefcornersQuality,
|
||||
blockSize,
|
||||
gradientSize,
|
||||
useHarrisDetector,
|
||||
k );
|
||||
}
|
||||
|
||||
double e = cv::norm(corners, Refcorners); // TODO cvtest
|
||||
|
||||
if (e > eps)
|
||||
{
|
||||
TEST_MESSAGEL ("Number of features: Refcorners = ", Refcorners.size())
|
||||
TEST_MESSAGEL (" TestCorners = ", corners.size())
|
||||
TEST_MESSAGE ("\n")
|
||||
|
||||
EXPECT_LE(e, eps); // never true
|
||||
ts->set_failed_test_info(cvtest::TS::FAIL_BAD_ACCURACY);
|
||||
|
||||
for(int i = 0; i < (int)std::min((unsigned int)(corners.size()), (unsigned int)(Refcorners.size())); i++){
|
||||
if ( (corners[i].x != Refcorners[i].x) || (corners[i].y != Refcorners[i].y))
|
||||
printf("i = %i X %2.2f Xref %2.2f Y %2.2f Yref %2.2f\n",i,corners[i].x,Refcorners[i].x,corners[i].y,Refcorners[i].y);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
TEST_MESSAGEL (" Refcorners = ", Refcorners.size())
|
||||
TEST_MESSAGEL (" TestCorners = ", corners.size())
|
||||
TEST_MESSAGE ("\n")
|
||||
|
||||
ts->set_failed_test_info(cvtest::TS::OK);
|
||||
}
|
||||
|
||||
e = cv::norm(cornersQuality, RefcornersQuality, NORM_RELATIVE | NORM_INF);
|
||||
|
||||
if (e > eps)
|
||||
{
|
||||
EXPECT_LE(e, eps); // never true
|
||||
ts->set_failed_test_info(cvtest::TS::FAIL_BAD_ACCURACY);
|
||||
|
||||
int min_size = (int)std::min(cornersQuality.size(), RefcornersQuality.size());
|
||||
for(int i = 0; i < min_size; i++) {
|
||||
if (std::abs(cornersQuality[i] - RefcornersQuality[i]) > eps * std::max(cornersQuality[i], RefcornersQuality[i]))
|
||||
printf("i = %i Quality %2.6f Quality ref %2.6f\n", i, cornersQuality[i], RefcornersQuality[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return BaseTest::validate_test_results(test_case_idx);
|
||||
|
||||
}
|
||||
|
||||
TEST(Imgproc_GoodFeatureToT, accuracy) { CV_GoodFeatureToTTest test; test.safe_run(); }
|
||||
|
||||
TEST(Imgproc_GoodFeatureToT, mask)
|
||||
{
|
||||
Mat gray = imread(cvtest::findDataFile("shared/baboon.png"), IMREAD_GRAYSCALE);
|
||||
ASSERT_FALSE(gray.empty());
|
||||
|
||||
cv::Rect roi(gray.cols/4, gray.rows/4, gray.cols/2, gray.rows/2);
|
||||
Mat mask = Mat::zeros(gray.size(), CV_8UC1);
|
||||
mask(roi).setTo(255);
|
||||
|
||||
Mat mask_bool = Mat::zeros(gray.size(), CV_BoolC1);
|
||||
mask_bool(roi).setTo(1);
|
||||
Mat gray_roi = gray(roi);
|
||||
|
||||
Mat corners_mask, corners_bool, corners_ref;
|
||||
vector<float> ref_quality;
|
||||
|
||||
test_goodFeaturesToTrack(gray, corners_ref, 100, 0.3, 3, mask, ref_quality, 3, 3, false, 0.04);
|
||||
cv::goodFeaturesToTrack(gray, corners_mask, 100, 0.3, 3, mask);
|
||||
cv::goodFeaturesToTrack(gray, corners_bool, 100, 0.3, 3, mask_bool);
|
||||
|
||||
EXPECT_MAT_NEAR(corners_mask, corners_ref.t(), 0.0);
|
||||
EXPECT_MAT_NEAR(corners_mask, corners_bool, 0.0);
|
||||
}
|
||||
|
||||
}} // namespace
|
||||
/* End of file. */
|
||||
@@ -5,6 +5,7 @@
|
||||
#define __OPENCV_TEST_PRECOMP_HPP__
|
||||
|
||||
#include "opencv2/ts.hpp"
|
||||
#include "opencv2/ts/ocl_test.hpp"
|
||||
#include "opencv2/features.hpp"
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user