1 /* Original code has been submitted by Liu Liu. Here is the copyright.
2 ----------------------------------------------------------------------------------
3 * An OpenCV Implementation of SURF
4 * Further Information Refer to "SURF: Speed-Up Robust Feature"
6 * liuliu.1987+opencv@gmail.com
8 * There are still serveral lacks for this experimental implementation:
9 * 1.The interpolation of sub-pixel mentioned in article was not implemented yet;
10 * 2.A comparision with original libSurf.so shows that the hessian detector is not a 100% match to their implementation;
11 * 3.Due to above reasons, I recommanded the original one for study and reuse;
13 * However, the speed of this implementation is something comparable to original one.
15 * Copyright© 2008, Liu Liu All rights reserved.
17 * Redistribution and use in source and binary forms, with or
18 * without modification, are permitted provided that the following
20 * Redistributions of source code must retain the above
21 * copyright notice, this list of conditions and the following
23 * Redistributions in binary form must reproduce the above
24 * copyright notice, this list of conditions and the following
25 * disclaimer in the documentation and/or other materials
26 * provided with the distribution.
27 * The name of Contributor may not be used to endorse or
28 * promote products derived from this software without
29 * specific prior written permission.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
32 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
33 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
34 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
35 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
36 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
37 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
38 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
39 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
40 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
41 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
42 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
46 #include "precomp.hpp"
52 CV_IMPL CvSURFParams cvSURFParams(double threshold, int extended)
55 params.hessianThreshold = threshold;
56 params.extended = extended;
59 params.nOctaveLayers = 2;
64 cvExtractSURF( const CvArr* _img, const CvArr* _mask,
65 CvSeq** _keypoints, CvSeq** _descriptors,
66 CvMemStorage* storage, CvSURFParams params,
67 int useProvidedKeyPts)
69 Mat img = cvarrToMat(_img), mask;
71 mask = cvarrToMat(_mask);
72 std::vector<KeyPoint> kpt;
75 Ptr<Feature2D> surf = Algorithm::create<Feature2D>("Feature2D.SURF");
77 CV_Error(CV_StsNotImplemented, "OpenCV was built without SURF support");
79 surf->set("hessianThreshold", params.hessianThreshold);
80 surf->set("nOctaves", params.nOctaves);
81 surf->set("nOctaveLayers", params.nOctaveLayers);
82 surf->set("upright", params.upright != 0);
83 surf->set("extended", params.extended != 0);
85 surf->operator()(img, mask, kpt, _descriptors ? _OutputArray(descr) : (OutputArray)noArray(),
86 useProvidedKeyPts != 0);
89 *_keypoints = cvCreateSeq(0, sizeof(CvSeq), sizeof(CvSURFPoint), storage);
92 *_descriptors = cvCreateSeq(0, sizeof(CvSeq), surf->descriptorSize() * CV_ELEM_SIZE(surf->descriptorType()), storage);
94 for( size_t i = 0; i < kpt.size(); i++ )
98 CvSURFPoint pt = cvSURFPoint(kpt[i].pt, kpt[i].class_id, cvRound(kpt[i].size), kpt[i].angle, kpt[i].response);
99 cvSeqPush(*_keypoints, &pt);
102 cvSeqPush(*_descriptors, descr.ptr((int)i));
107 cvGetStarKeypoints( const CvArr* _img, CvMemStorage* storage,
108 CvStarDetectorParams params )
110 Ptr<StarDetector> star(new StarDetector(params.maxSize, params.responseThreshold,
111 params.lineThresholdProjected,
112 params.lineThresholdBinarized,
113 params.suppressNonmaxSize));
114 std::vector<KeyPoint> kpts;
115 star->detect(cvarrToMat(_img), kpts, Mat());
117 CvSeq* seq = cvCreateSeq(0, sizeof(CvSeq), sizeof(CvStarKeypoint), storage);
118 for( size_t i = 0; i < kpts.size(); i++ )
120 CvStarKeypoint kpt = cvStarKeypoint(kpts[i].pt, cvRound(kpts[i].size), kpts[i].response);
121 cvSeqPush(seq, &kpt);