Path: blob/master/modules/features2d/src/feature2d.cpp
16337 views
/*M///////////////////////////////////////////////////////////////////////////////////////1//2// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.3//4// By downloading, copying, installing or using the software you agree to this license.5// If you do not agree to this license, do not download, install,6// copy or use the software.7//8//9// License Agreement10// For Open Source Computer Vision Library11//12// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.13// Copyright (C) 2009, Willow Garage Inc., all rights reserved.14// Third party copyrights are property of their respective owners.15//16// Redistribution and use in source and binary forms, with or without modification,17// are permitted provided that the following conditions are met:18//19// * Redistribution's of source code must retain the above copyright notice,20// this list of conditions and the following disclaimer.21//22// * Redistribution's in binary form must reproduce the above copyright notice,23// this list of conditions and the following disclaimer in the documentation24// and/or other materials provided with the distribution.25//26// * The name of the copyright holders may not be used to endorse or promote products27// derived from this software without specific prior written permission.28//29// This software is provided by the copyright holders and contributors "as is" and30// any express or implied warranties, including, but not limited to, the implied31// warranties of merchantability and fitness for a particular purpose are disclaimed.32// In no event shall the Intel Corporation or contributors be liable for any direct,33// indirect, incidental, special, exemplary, or consequential damages34// (including, but not limited to, procurement of substitute goods or services;35// loss of use, data, or profits; or business interruption) however caused36// and on any theory of liability, whether in contract, strict liability,37// or tort (including negligence or otherwise) arising in any way out of38// the use of this software, even if advised of the possibility of such damage.39//40//M*/4142#include "precomp.hpp"4344namespace cv45{4647using std::vector;4849Feature2D::~Feature2D() {}5051/*52* Detect keypoints in an image.53* image The image.54* keypoints The detected keypoints.55* mask Mask specifying where to look for keypoints (optional). Must be a char56* matrix with non-zero values in the region of interest.57*/58void Feature2D::detect( InputArray image,59std::vector<KeyPoint>& keypoints,60InputArray mask )61{62CV_INSTRUMENT_REGION();6364if( image.empty() )65{66keypoints.clear();67return;68}69detectAndCompute(image, mask, keypoints, noArray(), false);70}717273void Feature2D::detect( InputArrayOfArrays _images,74std::vector<std::vector<KeyPoint> >& keypoints,75InputArrayOfArrays _masks )76{77CV_INSTRUMENT_REGION();7879vector<Mat> images, masks;8081_images.getMatVector(images);82size_t i, nimages = images.size();8384if( !_masks.empty() )85{86_masks.getMatVector(masks);87CV_Assert(masks.size() == nimages);88}8990keypoints.resize(nimages);9192for( i = 0; i < nimages; i++ )93{94detect(images[i], keypoints[i], masks.empty() ? Mat() : masks[i] );95}96}9798/*99* Compute the descriptors for a set of keypoints in an image.100* image The image.101* keypoints The input keypoints. Keypoints for which a descriptor cannot be computed are removed.102* descriptors Copmputed descriptors. Row i is the descriptor for keypoint i.103*/104void Feature2D::compute( InputArray image,105std::vector<KeyPoint>& keypoints,106OutputArray descriptors )107{108CV_INSTRUMENT_REGION();109110if( image.empty() )111{112descriptors.release();113return;114}115detectAndCompute(image, noArray(), keypoints, descriptors, true);116}117118void Feature2D::compute( InputArrayOfArrays _images,119std::vector<std::vector<KeyPoint> >& keypoints,120OutputArrayOfArrays _descriptors )121{122CV_INSTRUMENT_REGION();123124if( !_descriptors.needed() )125return;126127vector<Mat> images;128129_images.getMatVector(images);130size_t i, nimages = images.size();131132CV_Assert( keypoints.size() == nimages );133CV_Assert( _descriptors.kind() == _InputArray::STD_VECTOR_MAT );134135vector<Mat>& descriptors = *(vector<Mat>*)_descriptors.getObj();136descriptors.resize(nimages);137138for( i = 0; i < nimages; i++ )139{140compute(images[i], keypoints[i], descriptors[i]);141}142}143144145/* Detects keypoints and computes the descriptors */146void Feature2D::detectAndCompute( InputArray, InputArray,147std::vector<KeyPoint>&,148OutputArray,149bool )150{151CV_INSTRUMENT_REGION();152153CV_Error(Error::StsNotImplemented, "");154}155156void Feature2D::write( const String& fileName ) const157{158FileStorage fs(fileName, FileStorage::WRITE);159write(fs);160}161162void Feature2D::read( const String& fileName )163{164FileStorage fs(fileName, FileStorage::READ);165read(fs.root());166}167168void Feature2D::write( FileStorage&) const169{170}171172void Feature2D::read( const FileNode&)173{174}175176int Feature2D::descriptorSize() const177{178return 0;179}180181int Feature2D::descriptorType() const182{183return CV_32F;184}185186int Feature2D::defaultNorm() const187{188int tp = descriptorType();189return tp == CV_8U ? NORM_HAMMING : NORM_L2;190}191192// Return true if detector object is empty193bool Feature2D::empty() const194{195return true;196}197198String Feature2D::getDefaultName() const199{200return "Feature2D";201}202203}204205206