mirror of
https://github.com/opencv/opencv.git
synced 2024-11-24 11:10:21 +08:00
Merge branch 'master' into gpu-cuda-rename
Conflicts: modules/core/include/opencv2/core/cuda.hpp modules/cudacodec/src/thread.cpp modules/cudacodec/src/thread.hpp modules/superres/perf/perf_superres.cpp modules/superres/src/btv_l1_cuda.cpp modules/superres/src/optical_flow.cpp modules/videostab/src/global_motion.cpp modules/videostab/src/inpainting.cpp samples/cpp/stitching_detailed.cpp samples/cpp/videostab.cpp samples/gpu/stereo_multi.cpp
This commit is contained in:
parent
f46b7fcf86
commit
0c7663eb3b
@ -957,7 +957,7 @@ void CvCascadeBoostTree::write( FileStorage &fs, const Mat& featureMap )
|
||||
int subsetN = (maxCatCount + 31)/32;
|
||||
queue<CvDTreeNode*> internalNodesQueue;
|
||||
int size = (int)pow( 2.f, (float)ensemble->get_params().max_depth);
|
||||
Ptr<float> leafVals = new float[size];
|
||||
std::vector<float> leafVals(size);
|
||||
int leafValIdx = 0;
|
||||
int internalNodeIdx = 1;
|
||||
CvDTreeNode* tempNode;
|
||||
|
@ -159,10 +159,10 @@ bool CvCascadeClassifier::train( const string _cascadeDirName,
|
||||
cascadeParams = _cascadeParams;
|
||||
featureParams = CvFeatureParams::create(cascadeParams.featureType);
|
||||
featureParams->init(_featureParams);
|
||||
stageParams = new CvCascadeBoostParams;
|
||||
stageParams = makePtr<CvCascadeBoostParams>();
|
||||
*stageParams = _stageParams;
|
||||
featureEvaluator = CvFeatureEvaluator::create(cascadeParams.featureType);
|
||||
featureEvaluator->init( (CvFeatureParams*)featureParams, numPos + numNeg, cascadeParams.winSize );
|
||||
featureEvaluator->init( featureParams, numPos + numNeg, cascadeParams.winSize );
|
||||
stageClassifiers.reserve( numStages );
|
||||
}
|
||||
cout << "PARAMETERS:" << endl;
|
||||
@ -206,10 +206,10 @@ bool CvCascadeClassifier::train( const string _cascadeDirName,
|
||||
break;
|
||||
}
|
||||
|
||||
CvCascadeBoost* tempStage = new CvCascadeBoost;
|
||||
bool isStageTrained = tempStage->train( (CvFeatureEvaluator*)featureEvaluator,
|
||||
Ptr<CvCascadeBoost> tempStage = makePtr<CvCascadeBoost>();
|
||||
bool isStageTrained = tempStage->train( featureEvaluator,
|
||||
curNumSamples, _precalcValBufSize, _precalcIdxBufSize,
|
||||
*((CvCascadeBoostParams*)stageParams) );
|
||||
*stageParams );
|
||||
cout << "END>" << endl;
|
||||
|
||||
if(!isStageTrained)
|
||||
@ -325,7 +325,7 @@ void CvCascadeClassifier::writeParams( FileStorage &fs ) const
|
||||
|
||||
void CvCascadeClassifier::writeFeatures( FileStorage &fs, const Mat& featureMap ) const
|
||||
{
|
||||
((CvFeatureEvaluator*)((Ptr<CvFeatureEvaluator>)featureEvaluator))->writeFeatures( fs, featureMap );
|
||||
featureEvaluator->writeFeatures( fs, featureMap );
|
||||
}
|
||||
|
||||
void CvCascadeClassifier::writeStages( FileStorage &fs, const Mat& featureMap ) const
|
||||
@ -339,7 +339,7 @@ void CvCascadeClassifier::writeStages( FileStorage &fs, const Mat& featureMap )
|
||||
sprintf( cmnt, "stage %d", i );
|
||||
cvWriteComment( fs.fs, cmnt, 0 );
|
||||
fs << "{";
|
||||
((CvCascadeBoost*)((Ptr<CvCascadeBoost>)*it))->write( fs, featureMap );
|
||||
(*it)->write( fs, featureMap );
|
||||
fs << "}";
|
||||
}
|
||||
fs << "]";
|
||||
@ -350,7 +350,7 @@ bool CvCascadeClassifier::readParams( const FileNode &node )
|
||||
if ( !node.isMap() || !cascadeParams.read( node ) )
|
||||
return false;
|
||||
|
||||
stageParams = new CvCascadeBoostParams;
|
||||
stageParams = makePtr<CvCascadeBoostParams>();
|
||||
FileNode rnode = node[CC_STAGE_PARAMS];
|
||||
if ( !stageParams->read( rnode ) )
|
||||
return false;
|
||||
@ -371,12 +371,9 @@ bool CvCascadeClassifier::readStages( const FileNode &node)
|
||||
FileNodeIterator it = rnode.begin();
|
||||
for( int i = 0; i < min( (int)rnode.size(), numStages ); i++, it++ )
|
||||
{
|
||||
CvCascadeBoost* tempStage = new CvCascadeBoost;
|
||||
if ( !tempStage->read( *it, (CvFeatureEvaluator *)featureEvaluator, *((CvCascadeBoostParams*)stageParams) ) )
|
||||
{
|
||||
delete tempStage;
|
||||
Ptr<CvCascadeBoost> tempStage = makePtr<CvCascadeBoost>();
|
||||
if ( !tempStage->read( *it, featureEvaluator, *stageParams) )
|
||||
return false;
|
||||
}
|
||||
stageClassifiers.push_back(tempStage);
|
||||
}
|
||||
return true;
|
||||
@ -453,7 +450,7 @@ void CvCascadeClassifier::save( const string filename, bool baseFormat )
|
||||
|
||||
fs << "{";
|
||||
fs << ICV_HAAR_FEATURE_NAME << "{";
|
||||
((CvHaarEvaluator*)((CvFeatureEvaluator*)featureEvaluator))->writeFeature( fs, tempNode->split->var_idx );
|
||||
((CvHaarEvaluator*)featureEvaluator.get())->writeFeature( fs, tempNode->split->var_idx );
|
||||
fs << "}";
|
||||
|
||||
fs << ICV_HAAR_THRESHOLD_NAME << tempNode->split->ord.c;
|
||||
@ -499,7 +496,7 @@ bool CvCascadeClassifier::load( const string cascadeDirName )
|
||||
if ( !readParams( node ) )
|
||||
return false;
|
||||
featureEvaluator = CvFeatureEvaluator::create(cascadeParams.featureType);
|
||||
featureEvaluator->init( ((CvFeatureParams*)featureParams), numPos + numNeg, cascadeParams.winSize );
|
||||
featureEvaluator->init( featureParams, numPos + numNeg, cascadeParams.winSize );
|
||||
fs.release();
|
||||
|
||||
char buf[10];
|
||||
@ -510,11 +507,10 @@ bool CvCascadeClassifier::load( const string cascadeDirName )
|
||||
node = fs.getFirstTopLevelNode();
|
||||
if ( !fs.isOpened() )
|
||||
break;
|
||||
CvCascadeBoost *tempStage = new CvCascadeBoost;
|
||||
Ptr<CvCascadeBoost> tempStage = makePtr<CvCascadeBoost>();
|
||||
|
||||
if ( !tempStage->read( node, (CvFeatureEvaluator*)featureEvaluator, *((CvCascadeBoostParams*)stageParams )) )
|
||||
if ( !tempStage->read( node, featureEvaluator, *stageParams ))
|
||||
{
|
||||
delete tempStage;
|
||||
fs.release();
|
||||
break;
|
||||
}
|
||||
@ -531,7 +527,7 @@ void CvCascadeClassifier::getUsedFeaturesIdxMap( Mat& featureMap )
|
||||
|
||||
for( vector< Ptr<CvCascadeBoost> >::const_iterator it = stageClassifiers.begin();
|
||||
it != stageClassifiers.end(); it++ )
|
||||
((CvCascadeBoost*)((Ptr<CvCascadeBoost>)(*it)))->markUsedFeaturesInMap( featureMap );
|
||||
(*it)->markUsedFeaturesInMap( featureMap );
|
||||
|
||||
for( int fi = 0, idx = 0; fi < varCount; fi++ )
|
||||
if ( featureMap.at<int>(0, fi) >= 0 )
|
||||
|
@ -18,9 +18,9 @@ int main( int argc, char* argv[] )
|
||||
|
||||
CvCascadeParams cascadeParams;
|
||||
CvCascadeBoostParams stageParams;
|
||||
Ptr<CvFeatureParams> featureParams[] = { Ptr<CvFeatureParams>(new CvHaarFeatureParams),
|
||||
Ptr<CvFeatureParams>(new CvLBPFeatureParams),
|
||||
Ptr<CvFeatureParams>(new CvHOGFeatureParams)
|
||||
Ptr<CvFeatureParams> featureParams[] = { makePtr<CvHaarFeatureParams>(),
|
||||
makePtr<CvLBPFeatureParams>(),
|
||||
makePtr<CvHOGFeatureParams>()
|
||||
};
|
||||
int fc = sizeof(featureParams)/sizeof(featureParams[0]);
|
||||
if( argc == 1 )
|
||||
|
@ -114,19 +114,34 @@ kernel void horizontalAnticausalFilter(
|
||||
global float * optr = output +
|
||||
mad24(gid + 1, elements_per_row, - 1 + out_offset / 4);
|
||||
|
||||
float4 result = (float4)(0), out_v4;
|
||||
float4 result_v4 = (float4)(0), out_v4;
|
||||
float result = 0;
|
||||
// we assume elements_per_row is multple of 4
|
||||
for(int i = 0; i < elements_per_row / 4; ++i, optr -= 4)
|
||||
for(int i = 0; i < 4; ++ i, -- optr)
|
||||
{
|
||||
if(i < elements_per_row - cols)
|
||||
{
|
||||
*optr = result;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = *optr + _a * result;
|
||||
*optr = result;
|
||||
}
|
||||
}
|
||||
result_v4.x = result;
|
||||
optr -= 3;
|
||||
for(int i = 1; i < elements_per_row / 4; ++i, optr -= 4)
|
||||
{
|
||||
// shift left, `offset` is type `size_t` so it cannot be negative
|
||||
out_v4 = vload4(0, optr - 3);
|
||||
out_v4 = vload4(0, optr);
|
||||
|
||||
result.w = out_v4.w + _a * result.x;
|
||||
result.z = out_v4.z + _a * result.w;
|
||||
result.y = out_v4.y + _a * result.z;
|
||||
result.x = out_v4.x + _a * result.y;
|
||||
result_v4.w = out_v4.w + _a * result_v4.x;
|
||||
result_v4.z = out_v4.z + _a * result_v4.w;
|
||||
result_v4.y = out_v4.y + _a * result_v4.z;
|
||||
result_v4.x = out_v4.x + _a * result_v4.y;
|
||||
|
||||
vstore4(result, 0, optr - 3);
|
||||
vstore4(result_v4, 0, optr);
|
||||
}
|
||||
}
|
||||
|
||||
@ -207,18 +222,34 @@ kernel void horizontalAnticausalFilter_Irregular(
|
||||
buffer + mad24(rows - gid, elements_per_row, -1 + buffer_offset / 4);
|
||||
|
||||
float4 buf_v4, out_v4, res_v4 = (float4)(0);
|
||||
|
||||
for(int i = 0; i < elements_per_row / 4; ++i, optr -= 4, bptr -= 4)
|
||||
float result = 0;
|
||||
// we assume elements_per_row is multple of 4
|
||||
for(int i = 0; i < 4; ++ i, -- optr, -- bptr)
|
||||
{
|
||||
buf_v4 = vload4(0, bptr - 3);
|
||||
out_v4 = vload4(0, optr - 3);
|
||||
if(i < elements_per_row - cols)
|
||||
{
|
||||
*optr = result;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = *optr + *bptr * result;
|
||||
*optr = result;
|
||||
}
|
||||
}
|
||||
res_v4.x = result;
|
||||
optr -= 3;
|
||||
bptr -= 3;
|
||||
for(int i = 0; i < elements_per_row / 4 - 1; ++i, optr -= 4, bptr -= 4)
|
||||
{
|
||||
buf_v4 = vload4(0, bptr);
|
||||
out_v4 = vload4(0, optr);
|
||||
|
||||
res_v4.w = out_v4.w + buf_v4.w * res_v4.x;
|
||||
res_v4.z = out_v4.z + buf_v4.z * res_v4.w;
|
||||
res_v4.y = out_v4.y + buf_v4.y * res_v4.z;
|
||||
res_v4.x = out_v4.x + buf_v4.x * res_v4.y;
|
||||
|
||||
vstore4(res_v4, 0, optr - 3);
|
||||
vstore4(res_v4, 0, optr);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -295,8 +295,10 @@ private:
|
||||
};
|
||||
|
||||
// smart pointers allocation :
|
||||
Ptr<Retina> createRetina(Size inputSize){ return new RetinaImpl(inputSize); }
|
||||
Ptr<Retina> createRetina(Size inputSize, const bool colorMode, int colorSamplingMethod, const bool useRetinaLogSampling, const double reductionFactor, const double samplingStrenght){return new RetinaImpl(inputSize, colorMode, colorSamplingMethod, useRetinaLogSampling, reductionFactor, samplingStrenght);}
|
||||
Ptr<Retina> createRetina(Size inputSize){ return makePtr<RetinaImpl>(inputSize); }
|
||||
Ptr<Retina> createRetina(Size inputSize, const bool colorMode, int colorSamplingMethod, const bool useRetinaLogSampling, const double reductionFactor, const double samplingStrenght){
|
||||
return makePtr<RetinaImpl>(inputSize, colorMode, colorSamplingMethod, useRetinaLogSampling, reductionFactor, samplingStrenght);
|
||||
}
|
||||
|
||||
|
||||
// RetinaImpl code
|
||||
|
@ -1149,7 +1149,7 @@ void RetinaColor::_initColorSampling()
|
||||
// computing photoreceptors local density
|
||||
MAKE_OCLMAT_SLICES(_RGBmosaic, 3);
|
||||
MAKE_OCLMAT_SLICES(_colorLocalDensity, 3);
|
||||
|
||||
_colorLocalDensity.setTo(0);
|
||||
_spatiotemporalLPfilter(_RGBmosaic_slices[0], _colorLocalDensity_slices[0]);
|
||||
_spatiotemporalLPfilter(_RGBmosaic_slices[1], _colorLocalDensity_slices[1]);
|
||||
_spatiotemporalLPfilter(_RGBmosaic_slices[2], _colorLocalDensity_slices[2]);
|
||||
@ -1639,10 +1639,10 @@ void RetinaFilter::_processRetinaParvoMagnoMapping()
|
||||
}
|
||||
} /* namespace ocl */
|
||||
|
||||
Ptr<Retina> createRetina_OCL(Size getInputSize){ return new ocl::RetinaOCLImpl(getInputSize); }
|
||||
Ptr<Retina> createRetina_OCL(Size getInputSize){ return makePtr<ocl::RetinaOCLImpl>(getInputSize); }
|
||||
Ptr<Retina> createRetina_OCL(Size getInputSize, const bool colorMode, int colorSamplingMethod, const bool useRetinaLogSampling, const double reductionFactor, const double samplingStrenght)
|
||||
{
|
||||
return new ocl::RetinaOCLImpl(getInputSize, colorMode, colorSamplingMethod, useRetinaLogSampling, reductionFactor, samplingStrenght);
|
||||
return makePtr<ocl::RetinaOCLImpl>(getInputSize, colorMode, colorSamplingMethod, useRetinaLogSampling, reductionFactor, samplingStrenght);
|
||||
}
|
||||
|
||||
} /* namespace bioinspired */
|
||||
|
@ -114,9 +114,9 @@ public:
|
||||
_imageOutput.resize(nbPixels*3);
|
||||
_temp2.resize(nbPixels);
|
||||
// allocate the main filter with 2 setup sets properties (one for each low pass filter
|
||||
_multiuseFilter = new BasicRetinaFilter(imageInput.height, imageInput.width, 2);
|
||||
_multiuseFilter = makePtr<BasicRetinaFilter>(imageInput.height, imageInput.width, 2);
|
||||
// allocate the color manager (multiplexer/demultiplexer
|
||||
_colorEngine = new RetinaColor(imageInput.height, imageInput.width);
|
||||
_colorEngine = makePtr<RetinaColor>(imageInput.height, imageInput.width);
|
||||
// setup filter behaviors with default values
|
||||
setup();
|
||||
}
|
||||
@ -309,7 +309,7 @@ bool _convertCvMat2ValarrayBuffer(InputArray inputMat, std::valarray<float> &out
|
||||
|
||||
CV_EXPORTS Ptr<RetinaFastToneMapping> createRetinaFastToneMapping(Size inputSize)
|
||||
{
|
||||
return new RetinaFastToneMappingImpl(inputSize);
|
||||
return makePtr<RetinaFastToneMappingImpl>(inputSize);
|
||||
}
|
||||
|
||||
}// end of namespace bioinspired
|
||||
|
@ -49,7 +49,7 @@
|
||||
#include "opencv2/imgproc.hpp"
|
||||
#include "opencv2/highgui.hpp"
|
||||
|
||||
#if defined(HAVE_OPENCV_OCL) && defined(HAVE_OPENCL)
|
||||
#if defined(HAVE_OPENCV_OCL)
|
||||
|
||||
#include "opencv2/ocl.hpp"
|
||||
#define RETINA_ITERATIONS 5
|
||||
|
@ -515,7 +515,7 @@ findCirclesGrid
|
||||
-------------------
|
||||
Finds centers in the grid of circles.
|
||||
|
||||
.. ocv:function:: bool findCirclesGrid( InputArray image, Size patternSize, OutputArray centers, int flags=CALIB_CB_SYMMETRIC_GRID, const Ptr<FeatureDetector> &blobDetector = new SimpleBlobDetector() )
|
||||
.. ocv:function:: bool findCirclesGrid( InputArray image, Size patternSize, OutputArray centers, int flags=CALIB_CB_SYMMETRIC_GRID, const Ptr<FeatureDetector> &blobDetector = makePtr<SimpleBlobDetector>() )
|
||||
|
||||
.. ocv:pyfunction:: cv2.findCirclesGrid(image, patternSize[, centers[, flags[, blobDetector]]]) -> retval, centers
|
||||
|
||||
|
@ -180,7 +180,7 @@ CV_EXPORTS_W void drawChessboardCorners( InputOutputArray image, Size patternSiz
|
||||
//! finds circles' grid pattern of the specified size in the image
|
||||
CV_EXPORTS_W bool findCirclesGrid( InputArray image, Size patternSize,
|
||||
OutputArray centers, int flags = CALIB_CB_SYMMETRIC_GRID,
|
||||
const Ptr<FeatureDetector> &blobDetector = new SimpleBlobDetector());
|
||||
const Ptr<FeatureDetector> &blobDetector = makePtr<SimpleBlobDetector>());
|
||||
|
||||
//! finds intrinsic and extrinsic camera parameters from several fews of a known calibration pattern.
|
||||
CV_EXPORTS_W double calibrateCamera( InputArrayOfArrays objectPoints,
|
||||
|
@ -130,7 +130,7 @@ PERF_TEST_P(PointsNum, DISABLED_SolvePnPRansac, testing::Values(4, 3*9, 7*13))
|
||||
|
||||
#ifdef HAVE_TBB
|
||||
// limit concurrency to get determenistic result
|
||||
cv::Ptr<tbb::task_scheduler_init> one_thread = new tbb::task_scheduler_init(1);
|
||||
tbb::task_scheduler_init one_thread(1);
|
||||
#endif
|
||||
|
||||
TEST_CYCLE()
|
||||
|
@ -271,8 +271,8 @@ int cvFindChessboardCorners( const void* arr, CvSize pattern_size,
|
||||
if( !out_corners )
|
||||
CV_Error( CV_StsNullPtr, "Null pointer to corners" );
|
||||
|
||||
storage = cvCreateMemStorage(0);
|
||||
thresh_img = cvCreateMat( img->rows, img->cols, CV_8UC1 );
|
||||
storage.reset(cvCreateMemStorage(0));
|
||||
thresh_img.reset(cvCreateMat( img->rows, img->cols, CV_8UC1 ));
|
||||
|
||||
#ifdef DEBUG_CHESSBOARD
|
||||
dbg_img = cvCreateImage(cvGetSize(img), IPL_DEPTH_8U, 3 );
|
||||
@ -284,7 +284,7 @@ int cvFindChessboardCorners( const void* arr, CvSize pattern_size,
|
||||
{
|
||||
// equalize the input image histogram -
|
||||
// that should make the contrast between "black" and "white" areas big enough
|
||||
norm_img = cvCreateMat( img->rows, img->cols, CV_8UC1 );
|
||||
norm_img.reset(cvCreateMat( img->rows, img->cols, CV_8UC1 ));
|
||||
|
||||
if( CV_MAT_CN(img->type) != 1 )
|
||||
{
|
||||
@ -541,12 +541,12 @@ int cvFindChessboardCorners( const void* arr, CvSize pattern_size,
|
||||
cv::Ptr<CvMat> gray;
|
||||
if( CV_MAT_CN(img->type) != 1 )
|
||||
{
|
||||
gray = cvCreateMat(img->rows, img->cols, CV_8UC1);
|
||||
gray.reset(cvCreateMat(img->rows, img->cols, CV_8UC1));
|
||||
cvCvtColor(img, gray, CV_BGR2GRAY);
|
||||
}
|
||||
else
|
||||
{
|
||||
gray = cvCloneMat(img);
|
||||
gray.reset(cvCloneMat(img));
|
||||
}
|
||||
int wsize = 2;
|
||||
cvFindCornerSubPix( gray, out_corners, pattern_size.width*pattern_size.height,
|
||||
@ -627,7 +627,7 @@ icvOrderFoundConnectedQuads( int quad_count, CvCBQuad **quads,
|
||||
int *all_count, CvCBQuad **all_quads, CvCBCorner **corners,
|
||||
CvSize pattern_size, CvMemStorage* storage )
|
||||
{
|
||||
cv::Ptr<CvMemStorage> temp_storage = cvCreateChildMemStorage( storage );
|
||||
cv::Ptr<CvMemStorage> temp_storage(cvCreateChildMemStorage( storage ));
|
||||
CvSeq* stack = cvCreateSeq( 0, sizeof(*stack), sizeof(void*), temp_storage );
|
||||
|
||||
// first find an interior quad
|
||||
@ -1109,7 +1109,7 @@ icvCleanFoundConnectedQuads( int quad_count, CvCBQuad **quad_group, CvSize patte
|
||||
|
||||
// create an array of quadrangle centers
|
||||
cv::AutoBuffer<CvPoint2D32f> centers( quad_count );
|
||||
cv::Ptr<CvMemStorage> temp_storage = cvCreateMemStorage(0);
|
||||
cv::Ptr<CvMemStorage> temp_storage(cvCreateMemStorage(0));
|
||||
|
||||
for( i = 0; i < quad_count; i++ )
|
||||
{
|
||||
@ -1205,7 +1205,7 @@ static int
|
||||
icvFindConnectedQuads( CvCBQuad *quad, int quad_count, CvCBQuad **out_group,
|
||||
int group_idx, CvMemStorage* storage )
|
||||
{
|
||||
cv::Ptr<CvMemStorage> temp_storage = cvCreateChildMemStorage( storage );
|
||||
cv::Ptr<CvMemStorage> temp_storage(cvCreateChildMemStorage( storage ));
|
||||
CvSeq* stack = cvCreateSeq( 0, sizeof(*stack), sizeof(void*), temp_storage );
|
||||
int i, count = 0;
|
||||
|
||||
@ -1674,7 +1674,7 @@ icvGenerateQuads( CvCBQuad **out_quads, CvCBCorner **out_corners,
|
||||
min_size = 25; //cvRound( image->cols * image->rows * .03 * 0.01 * 0.92 );
|
||||
|
||||
// create temporary storage for contours and the sequence of pointers to found quadrangles
|
||||
temp_storage = cvCreateChildMemStorage( storage );
|
||||
temp_storage.reset(cvCreateChildMemStorage( storage ));
|
||||
root = cvCreateSeq( 0, sizeof(CvSeq), sizeof(CvSeq*), temp_storage );
|
||||
|
||||
// initialize contour retrieving routine
|
||||
|
@ -568,7 +568,7 @@ CV_IMPL void cvProjectPoints2( const CvMat* objectPoints,
|
||||
(objectPoints->rows == count && CV_MAT_CN(objectPoints->type)*objectPoints->cols == 3) ||
|
||||
(objectPoints->rows == 3 && CV_MAT_CN(objectPoints->type) == 1 && objectPoints->cols == count)))
|
||||
{
|
||||
matM = cvCreateMat( objectPoints->rows, objectPoints->cols, CV_MAKETYPE(CV_64F,CV_MAT_CN(objectPoints->type)) );
|
||||
matM.reset(cvCreateMat( objectPoints->rows, objectPoints->cols, CV_MAKETYPE(CV_64F,CV_MAT_CN(objectPoints->type)) ));
|
||||
cvConvert(objectPoints, matM);
|
||||
}
|
||||
else
|
||||
@ -584,7 +584,7 @@ CV_IMPL void cvProjectPoints2( const CvMat* objectPoints,
|
||||
(imagePoints->rows == count && CV_MAT_CN(imagePoints->type)*imagePoints->cols == 2) ||
|
||||
(imagePoints->rows == 2 && CV_MAT_CN(imagePoints->type) == 1 && imagePoints->cols == count)))
|
||||
{
|
||||
_m = cvCreateMat( imagePoints->rows, imagePoints->cols, CV_MAKETYPE(CV_64F,CV_MAT_CN(imagePoints->type)) );
|
||||
_m.reset(cvCreateMat( imagePoints->rows, imagePoints->cols, CV_MAKETYPE(CV_64F,CV_MAT_CN(imagePoints->type)) ));
|
||||
cvConvert(imagePoints, _m);
|
||||
}
|
||||
else
|
||||
@ -664,10 +664,10 @@ CV_IMPL void cvProjectPoints2( const CvMat* objectPoints,
|
||||
|
||||
if( CV_MAT_TYPE(dpdr->type) == CV_64FC1 )
|
||||
{
|
||||
_dpdr = cvCloneMat(dpdr);
|
||||
_dpdr.reset(cvCloneMat(dpdr));
|
||||
}
|
||||
else
|
||||
_dpdr = cvCreateMat( 2*count, 3, CV_64FC1 );
|
||||
_dpdr.reset(cvCreateMat( 2*count, 3, CV_64FC1 ));
|
||||
dpdr_p = _dpdr->data.db;
|
||||
dpdr_step = _dpdr->step/sizeof(dpdr_p[0]);
|
||||
}
|
||||
@ -682,10 +682,10 @@ CV_IMPL void cvProjectPoints2( const CvMat* objectPoints,
|
||||
|
||||
if( CV_MAT_TYPE(dpdt->type) == CV_64FC1 )
|
||||
{
|
||||
_dpdt = cvCloneMat(dpdt);
|
||||
_dpdt.reset(cvCloneMat(dpdt));
|
||||
}
|
||||
else
|
||||
_dpdt = cvCreateMat( 2*count, 3, CV_64FC1 );
|
||||
_dpdt.reset(cvCreateMat( 2*count, 3, CV_64FC1 ));
|
||||
dpdt_p = _dpdt->data.db;
|
||||
dpdt_step = _dpdt->step/sizeof(dpdt_p[0]);
|
||||
}
|
||||
@ -699,10 +699,10 @@ CV_IMPL void cvProjectPoints2( const CvMat* objectPoints,
|
||||
|
||||
if( CV_MAT_TYPE(dpdf->type) == CV_64FC1 )
|
||||
{
|
||||
_dpdf = cvCloneMat(dpdf);
|
||||
_dpdf.reset(cvCloneMat(dpdf));
|
||||
}
|
||||
else
|
||||
_dpdf = cvCreateMat( 2*count, 2, CV_64FC1 );
|
||||
_dpdf.reset(cvCreateMat( 2*count, 2, CV_64FC1 ));
|
||||
dpdf_p = _dpdf->data.db;
|
||||
dpdf_step = _dpdf->step/sizeof(dpdf_p[0]);
|
||||
}
|
||||
@ -716,10 +716,10 @@ CV_IMPL void cvProjectPoints2( const CvMat* objectPoints,
|
||||
|
||||
if( CV_MAT_TYPE(dpdc->type) == CV_64FC1 )
|
||||
{
|
||||
_dpdc = cvCloneMat(dpdc);
|
||||
_dpdc.reset(cvCloneMat(dpdc));
|
||||
}
|
||||
else
|
||||
_dpdc = cvCreateMat( 2*count, 2, CV_64FC1 );
|
||||
_dpdc.reset(cvCreateMat( 2*count, 2, CV_64FC1 ));
|
||||
dpdc_p = _dpdc->data.db;
|
||||
dpdc_step = _dpdc->step/sizeof(dpdc_p[0]);
|
||||
}
|
||||
@ -736,10 +736,10 @@ CV_IMPL void cvProjectPoints2( const CvMat* objectPoints,
|
||||
|
||||
if( CV_MAT_TYPE(dpdk->type) == CV_64FC1 )
|
||||
{
|
||||
_dpdk = cvCloneMat(dpdk);
|
||||
_dpdk.reset(cvCloneMat(dpdk));
|
||||
}
|
||||
else
|
||||
_dpdk = cvCreateMat( dpdk->rows, dpdk->cols, CV_64FC1 );
|
||||
_dpdk.reset(cvCreateMat( dpdk->rows, dpdk->cols, CV_64FC1 ));
|
||||
dpdk_p = _dpdk->data.db;
|
||||
dpdk_step = _dpdk->step/sizeof(dpdk_p[0]);
|
||||
}
|
||||
@ -950,8 +950,8 @@ CV_IMPL void cvFindExtrinsicCameraParams2( const CvMat* objectPoints,
|
||||
CV_IS_MAT(A) && CV_IS_MAT(rvec) && CV_IS_MAT(tvec) );
|
||||
|
||||
count = MAX(objectPoints->cols, objectPoints->rows);
|
||||
matM = cvCreateMat( 1, count, CV_64FC3 );
|
||||
_m = cvCreateMat( 1, count, CV_64FC2 );
|
||||
matM.reset(cvCreateMat( 1, count, CV_64FC3 ));
|
||||
_m.reset(cvCreateMat( 1, count, CV_64FC2 ));
|
||||
|
||||
cvConvertPointsHomogeneous( objectPoints, matM );
|
||||
cvConvertPointsHomogeneous( imagePoints, _m );
|
||||
@ -963,8 +963,8 @@ CV_IMPL void cvFindExtrinsicCameraParams2( const CvMat* objectPoints,
|
||||
CV_Assert( (CV_MAT_DEPTH(tvec->type) == CV_64F || CV_MAT_DEPTH(tvec->type) == CV_32F) &&
|
||||
(tvec->rows == 1 || tvec->cols == 1) && tvec->rows*tvec->cols*CV_MAT_CN(tvec->type) == 3 );
|
||||
|
||||
_mn = cvCreateMat( 1, count, CV_64FC2 );
|
||||
_Mxy = cvCreateMat( 1, count, CV_64FC2 );
|
||||
_mn.reset(cvCreateMat( 1, count, CV_64FC2 ));
|
||||
_Mxy.reset(cvCreateMat( 1, count, CV_64FC2 ));
|
||||
|
||||
// normalize image points
|
||||
// (unapply the intrinsic matrix transformation and distortion)
|
||||
@ -1055,7 +1055,7 @@ CV_IMPL void cvFindExtrinsicCameraParams2( const CvMat* objectPoints,
|
||||
CvPoint3D64f* M = (CvPoint3D64f*)matM->data.db;
|
||||
CvPoint2D64f* mn = (CvPoint2D64f*)_mn->data.db;
|
||||
|
||||
matL = cvCreateMat( 2*count, 12, CV_64F );
|
||||
matL.reset(cvCreateMat( 2*count, 12, CV_64F ));
|
||||
L = matL->data.db;
|
||||
|
||||
for( i = 0; i < count; i++, L += 24 )
|
||||
@ -1162,11 +1162,11 @@ CV_IMPL void cvInitIntrinsicParams2D( const CvMat* objectPoints,
|
||||
if( objectPoints->rows != 1 || imagePoints->rows != 1 )
|
||||
CV_Error( CV_StsBadSize, "object points and image points must be a single-row matrices" );
|
||||
|
||||
matA = cvCreateMat( 2*nimages, 2, CV_64F );
|
||||
_b = cvCreateMat( 2*nimages, 1, CV_64F );
|
||||
matA.reset(cvCreateMat( 2*nimages, 2, CV_64F ));
|
||||
_b.reset(cvCreateMat( 2*nimages, 1, CV_64F ));
|
||||
a[2] = (imageSize.width - 1)*0.5;
|
||||
a[5] = (imageSize.height - 1)*0.5;
|
||||
_allH = cvCreateMat( nimages, 9, CV_64F );
|
||||
_allH.reset(cvCreateMat( nimages, 9, CV_64F ));
|
||||
|
||||
// extract vanishing points in order to obtain initial value for the focal length
|
||||
for( i = 0, pos = 0; i < nimages; i++, pos += ni )
|
||||
@ -1310,16 +1310,16 @@ CV_IMPL double cvCalibrateCamera2( const CvMat* objectPoints,
|
||||
total += ni;
|
||||
}
|
||||
|
||||
matM = cvCreateMat( 1, total, CV_64FC3 );
|
||||
_m = cvCreateMat( 1, total, CV_64FC2 );
|
||||
matM.reset(cvCreateMat( 1, total, CV_64FC3 ));
|
||||
_m.reset(cvCreateMat( 1, total, CV_64FC2 ));
|
||||
|
||||
cvConvertPointsHomogeneous( objectPoints, matM );
|
||||
cvConvertPointsHomogeneous( imagePoints, _m );
|
||||
|
||||
nparams = NINTRINSIC + nimages*6;
|
||||
_Ji = cvCreateMat( maxPoints*2, NINTRINSIC, CV_64FC1 );
|
||||
_Je = cvCreateMat( maxPoints*2, 6, CV_64FC1 );
|
||||
_err = cvCreateMat( maxPoints*2, 1, CV_64FC1 );
|
||||
_Ji.reset(cvCreateMat( maxPoints*2, NINTRINSIC, CV_64FC1 ));
|
||||
_Je.reset(cvCreateMat( maxPoints*2, 6, CV_64FC1 ));
|
||||
_err.reset(cvCreateMat( maxPoints*2, 1, CV_64FC1 ));
|
||||
cvZero( _Ji );
|
||||
|
||||
_k = cvMat( distCoeffs->rows, distCoeffs->cols, CV_MAKETYPE(CV_64F,CV_MAT_CN(distCoeffs->type)), k);
|
||||
@ -1662,7 +1662,7 @@ double cvStereoCalibrate( const CvMat* _objectPoints, const CvMat* _imagePoints1
|
||||
CV_MAT_TYPE(_npoints->type) == CV_32SC1 );
|
||||
|
||||
nimages = _npoints->cols + _npoints->rows - 1;
|
||||
npoints = cvCreateMat( _npoints->rows, _npoints->cols, _npoints->type );
|
||||
npoints.reset(cvCreateMat( _npoints->rows, _npoints->cols, _npoints->type ));
|
||||
cvCopy( _npoints, npoints );
|
||||
|
||||
for( i = 0, pointsTotal = 0; i < nimages; i++ )
|
||||
@ -1671,8 +1671,8 @@ double cvStereoCalibrate( const CvMat* _objectPoints, const CvMat* _imagePoints1
|
||||
pointsTotal += npoints->data.i[i];
|
||||
}
|
||||
|
||||
objectPoints = cvCreateMat( _objectPoints->rows, _objectPoints->cols,
|
||||
CV_64FC(CV_MAT_CN(_objectPoints->type)));
|
||||
objectPoints.reset(cvCreateMat( _objectPoints->rows, _objectPoints->cols,
|
||||
CV_64FC(CV_MAT_CN(_objectPoints->type))));
|
||||
cvConvert( _objectPoints, objectPoints );
|
||||
cvReshape( objectPoints, objectPoints, 3, 1 );
|
||||
|
||||
@ -1691,7 +1691,7 @@ double cvStereoCalibrate( const CvMat* _objectPoints, const CvMat* _imagePoints1
|
||||
K[k] = cvMat(3,3,CV_64F,A[k]);
|
||||
Dist[k] = cvMat(1,8,CV_64F,dk[k]);
|
||||
|
||||
imagePoints[k] = cvCreateMat( points->rows, points->cols, CV_64FC(CV_MAT_CN(points->type)));
|
||||
imagePoints[k].reset(cvCreateMat( points->rows, points->cols, CV_64FC(CV_MAT_CN(points->type))));
|
||||
cvConvert( points, imagePoints[k] );
|
||||
cvReshape( imagePoints[k], imagePoints[k], 2, 1 );
|
||||
|
||||
@ -1729,10 +1729,10 @@ double cvStereoCalibrate( const CvMat* _objectPoints, const CvMat* _imagePoints1
|
||||
|
||||
recomputeIntrinsics = (flags & CV_CALIB_FIX_INTRINSIC) == 0;
|
||||
|
||||
err = cvCreateMat( maxPoints*2, 1, CV_64F );
|
||||
Je = cvCreateMat( maxPoints*2, 6, CV_64F );
|
||||
J_LR = cvCreateMat( maxPoints*2, 6, CV_64F );
|
||||
Ji = cvCreateMat( maxPoints*2, NINTRINSIC, CV_64F );
|
||||
err.reset(cvCreateMat( maxPoints*2, 1, CV_64F ));
|
||||
Je.reset(cvCreateMat( maxPoints*2, 6, CV_64F ));
|
||||
J_LR.reset(cvCreateMat( maxPoints*2, 6, CV_64F ));
|
||||
Ji.reset(cvCreateMat( maxPoints*2, NINTRINSIC, CV_64F ));
|
||||
cvZero( Ji );
|
||||
|
||||
// we optimize for the inter-camera R(3),t(3), then, optionally,
|
||||
@ -1740,7 +1740,7 @@ double cvStereoCalibrate( const CvMat* _objectPoints, const CvMat* _imagePoints1
|
||||
nparams = 6*(nimages+1) + (recomputeIntrinsics ? NINTRINSIC*2 : 0);
|
||||
|
||||
// storage for initial [om(R){i}|t{i}] (in order to compute the median for each component)
|
||||
RT0 = cvCreateMat( 6, nimages, CV_64F );
|
||||
RT0.reset(cvCreateMat( 6, nimages, CV_64F ));
|
||||
|
||||
solver.init( nparams, 0, termCrit );
|
||||
if( recomputeIntrinsics )
|
||||
@ -2080,7 +2080,7 @@ icvGetRectangles( const CvMat* cameraMatrix, const CvMat* distCoeffs,
|
||||
{
|
||||
const int N = 9;
|
||||
int x, y, k;
|
||||
cv::Ptr<CvMat> _pts = cvCreateMat(1, N*N, CV_32FC2);
|
||||
cv::Ptr<CvMat> _pts(cvCreateMat(1, N*N, CV_32FC2));
|
||||
CvPoint2D32f* pts = (CvPoint2D32f*)(_pts->data.ptr);
|
||||
|
||||
for( y = k = 0; y < N; y++ )
|
||||
@ -2439,10 +2439,10 @@ CV_IMPL int cvStereoRectifyUncalibrated(
|
||||
|
||||
npoints = _points1->rows * _points1->cols * CV_MAT_CN(_points1->type) / 2;
|
||||
|
||||
_m1 = cvCreateMat( _points1->rows, _points1->cols, CV_64FC(CV_MAT_CN(_points1->type)) );
|
||||
_m2 = cvCreateMat( _points2->rows, _points2->cols, CV_64FC(CV_MAT_CN(_points2->type)) );
|
||||
_lines1 = cvCreateMat( 1, npoints, CV_64FC3 );
|
||||
_lines2 = cvCreateMat( 1, npoints, CV_64FC3 );
|
||||
_m1.reset(cvCreateMat( _points1->rows, _points1->cols, CV_64FC(CV_MAT_CN(_points1->type)) ));
|
||||
_m2.reset(cvCreateMat( _points2->rows, _points2->cols, CV_64FC(CV_MAT_CN(_points2->type)) ));
|
||||
_lines1.reset(cvCreateMat( 1, npoints, CV_64FC3 ));
|
||||
_lines2.reset(cvCreateMat( 1, npoints, CV_64FC3 ));
|
||||
|
||||
cvConvert( F0, &F );
|
||||
|
||||
|
@ -53,7 +53,6 @@ using cv::Ptr;
|
||||
|
||||
CvLevMarq::CvLevMarq()
|
||||
{
|
||||
mask = prevParam = param = J = err = JtJ = JtJN = JtErr = JtJV = JtJW = Ptr<CvMat>();
|
||||
lambdaLg10 = 0; state = DONE;
|
||||
criteria = cvTermCriteria(0,0,0);
|
||||
iters = 0;
|
||||
@ -62,7 +61,6 @@ CvLevMarq::CvLevMarq()
|
||||
|
||||
CvLevMarq::CvLevMarq( int nparams, int nerrs, CvTermCriteria criteria0, bool _completeSymmFlag )
|
||||
{
|
||||
mask = prevParam = param = J = err = JtJ = JtJN = JtErr = JtJV = JtJW = Ptr<CvMat>();
|
||||
init(nparams, nerrs, criteria0, _completeSymmFlag);
|
||||
}
|
||||
|
||||
@ -89,19 +87,19 @@ void CvLevMarq::init( int nparams, int nerrs, CvTermCriteria criteria0, bool _co
|
||||
{
|
||||
if( !param || param->rows != nparams || nerrs != (err ? err->rows : 0) )
|
||||
clear();
|
||||
mask = cvCreateMat( nparams, 1, CV_8U );
|
||||
mask.reset(cvCreateMat( nparams, 1, CV_8U ));
|
||||
cvSet(mask, cvScalarAll(1));
|
||||
prevParam = cvCreateMat( nparams, 1, CV_64F );
|
||||
param = cvCreateMat( nparams, 1, CV_64F );
|
||||
JtJ = cvCreateMat( nparams, nparams, CV_64F );
|
||||
JtJN = cvCreateMat( nparams, nparams, CV_64F );
|
||||
JtJV = cvCreateMat( nparams, nparams, CV_64F );
|
||||
JtJW = cvCreateMat( nparams, 1, CV_64F );
|
||||
JtErr = cvCreateMat( nparams, 1, CV_64F );
|
||||
prevParam.reset(cvCreateMat( nparams, 1, CV_64F ));
|
||||
param.reset(cvCreateMat( nparams, 1, CV_64F ));
|
||||
JtJ.reset(cvCreateMat( nparams, nparams, CV_64F ));
|
||||
JtJN.reset(cvCreateMat( nparams, nparams, CV_64F ));
|
||||
JtJV.reset(cvCreateMat( nparams, nparams, CV_64F ));
|
||||
JtJW.reset(cvCreateMat( nparams, 1, CV_64F ));
|
||||
JtErr.reset(cvCreateMat( nparams, 1, CV_64F ));
|
||||
if( nerrs > 0 )
|
||||
{
|
||||
J = cvCreateMat( nerrs, nparams, CV_64F );
|
||||
err = cvCreateMat( nerrs, 1, CV_64F );
|
||||
J.reset(cvCreateMat( nerrs, nparams, CV_64F ));
|
||||
err.reset(cvCreateMat( nerrs, 1, CV_64F ));
|
||||
}
|
||||
prevErrNorm = DBL_MAX;
|
||||
lambdaLg10 = -3;
|
||||
@ -196,7 +194,7 @@ bool CvLevMarq::updateAlt( const CvMat*& _param, CvMat*& _JtJ, CvMat*& _JtErr, d
|
||||
{
|
||||
double change;
|
||||
|
||||
CV_Assert( err.empty() );
|
||||
CV_Assert( !err );
|
||||
if( state == DONE )
|
||||
{
|
||||
_param = param;
|
||||
|
@ -436,9 +436,9 @@ cv::Mat cv::findEssentialMat( InputArray _points1, InputArray _points2, double f
|
||||
|
||||
Mat E;
|
||||
if( method == RANSAC )
|
||||
createRANSACPointSetRegistrator(new EMEstimatorCallback, 5, threshold, prob)->run(points1, points2, E, _mask);
|
||||
createRANSACPointSetRegistrator(makePtr<EMEstimatorCallback>(), 5, threshold, prob)->run(points1, points2, E, _mask);
|
||||
else
|
||||
createLMeDSPointSetRegistrator(new EMEstimatorCallback, 5, prob)->run(points1, points2, E, _mask);
|
||||
createLMeDSPointSetRegistrator(makePtr<EMEstimatorCallback>(), 5, prob)->run(points1, points2, E, _mask);
|
||||
|
||||
return E;
|
||||
}
|
||||
|
@ -307,7 +307,7 @@ cv::Mat cv::findHomography( InputArray _points1, InputArray _points2,
|
||||
if( ransacReprojThreshold <= 0 )
|
||||
ransacReprojThreshold = defaultRANSACReprojThreshold;
|
||||
|
||||
Ptr<PointSetRegistrator::Callback> cb = new HomographyEstimatorCallback;
|
||||
Ptr<PointSetRegistrator::Callback> cb = makePtr<HomographyEstimatorCallback>();
|
||||
|
||||
if( method == 0 || npoints == 4 )
|
||||
{
|
||||
@ -334,7 +334,7 @@ cv::Mat cv::findHomography( InputArray _points1, InputArray _points2,
|
||||
if( method == RANSAC || method == LMEDS )
|
||||
cb->runKernel( src, dst, H );
|
||||
Mat H8(8, 1, CV_64F, H.ptr<double>());
|
||||
createLMSolver(new HomographyRefineCallback(src, dst), 10)->run(H8);
|
||||
createLMSolver(makePtr<HomographyRefineCallback>(src, dst), 10)->run(H8);
|
||||
}
|
||||
}
|
||||
|
||||
@ -686,7 +686,7 @@ cv::Mat cv::findFundamentalMat( InputArray _points1, InputArray _points2,
|
||||
if( npoints < 7 )
|
||||
return Mat();
|
||||
|
||||
Ptr<PointSetRegistrator::Callback> cb = new FMEstimatorCallback;
|
||||
Ptr<PointSetRegistrator::Callback> cb = makePtr<FMEstimatorCallback>();
|
||||
int result;
|
||||
|
||||
if( npoints == 7 || method == FM_8POINT )
|
||||
|
@ -95,7 +95,7 @@ public:
|
||||
int ptype = param0.type();
|
||||
|
||||
CV_Assert( (param0.cols == 1 || param0.rows == 1) && (ptype == CV_32F || ptype == CV_64F));
|
||||
CV_Assert( !cb.empty() );
|
||||
CV_Assert( cb );
|
||||
|
||||
int lx = param0.rows + param0.cols - 1;
|
||||
param0.convertTo(x, CV_64F);
|
||||
@ -220,7 +220,7 @@ CV_INIT_ALGORITHM(LMSolverImpl, "LMSolver",
|
||||
Ptr<LMSolver> createLMSolver(const Ptr<LMSolver::Callback>& cb, int maxIters)
|
||||
{
|
||||
CV_Assert( !LMSolverImpl_info_auto.name().empty() );
|
||||
return new LMSolverImpl(cb, maxIters);
|
||||
return makePtr<LMSolverImpl>(cb, maxIters);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -171,7 +171,7 @@ public:
|
||||
|
||||
RNG rng((uint64)-1);
|
||||
|
||||
CV_Assert( !cb.empty() );
|
||||
CV_Assert( cb );
|
||||
CV_Assert( confidence > 0 && confidence < 1 );
|
||||
|
||||
CV_Assert( count >= 0 && count2 == count );
|
||||
@ -288,7 +288,7 @@ public:
|
||||
|
||||
RNG rng((uint64)-1);
|
||||
|
||||
CV_Assert( !cb.empty() );
|
||||
CV_Assert( cb );
|
||||
CV_Assert( confidence > 0 && confidence < 1 );
|
||||
|
||||
CV_Assert( count >= 0 && count2 == count );
|
||||
@ -397,7 +397,8 @@ Ptr<PointSetRegistrator> createRANSACPointSetRegistrator(const Ptr<PointSetRegis
|
||||
double _confidence, int _maxIters)
|
||||
{
|
||||
CV_Assert( !RANSACPointSetRegistrator_info_auto.name().empty() );
|
||||
return new RANSACPointSetRegistrator(_cb, _modelPoints, _threshold, _confidence, _maxIters);
|
||||
return Ptr<PointSetRegistrator>(
|
||||
new RANSACPointSetRegistrator(_cb, _modelPoints, _threshold, _confidence, _maxIters));
|
||||
}
|
||||
|
||||
|
||||
@ -405,7 +406,8 @@ Ptr<PointSetRegistrator> createLMeDSPointSetRegistrator(const Ptr<PointSetRegist
|
||||
int _modelPoints, double _confidence, int _maxIters)
|
||||
{
|
||||
CV_Assert( !LMeDSPointSetRegistrator_info_auto.name().empty() );
|
||||
return new LMeDSPointSetRegistrator(_cb, _modelPoints, _confidence, _maxIters);
|
||||
return Ptr<PointSetRegistrator>(
|
||||
new LMeDSPointSetRegistrator(_cb, _modelPoints, _confidence, _maxIters));
|
||||
}
|
||||
|
||||
class Affine3DEstimatorCallback : public PointSetRegistrator::Callback
|
||||
@ -532,5 +534,5 @@ int cv::estimateAffine3D(InputArray _from, InputArray _to,
|
||||
param1 = param1 <= 0 ? 3 : param1;
|
||||
param2 = (param2 < epsilon) ? 0.99 : (param2 > 1 - epsilon) ? 0.99 : param2;
|
||||
|
||||
return createRANSACPointSetRegistrator(new Affine3DEstimatorCallback, 4, param1, param2)->run(dFrom, dTo, _out, _inliers);
|
||||
return createRANSACPointSetRegistrator(makePtr<Affine3DEstimatorCallback>(), 4, param1, param2)->run(dFrom, dTo, _out, _inliers);
|
||||
}
|
||||
|
@ -991,7 +991,7 @@ const char* StereoBMImpl::name_ = "StereoMatcher.BM";
|
||||
|
||||
cv::Ptr<cv::StereoBM> cv::createStereoBM(int _numDisparities, int _SADWindowSize)
|
||||
{
|
||||
return new StereoBMImpl(_numDisparities, _SADWindowSize);
|
||||
return makePtr<StereoBMImpl>(_numDisparities, _SADWindowSize);
|
||||
}
|
||||
|
||||
/* End of file. */
|
||||
|
@ -947,11 +947,12 @@ Ptr<StereoSGBM> createStereoSGBM(int minDisparity, int numDisparities, int SADWi
|
||||
int speckleWindowSize, int speckleRange,
|
||||
int mode)
|
||||
{
|
||||
return new StereoSGBMImpl(minDisparity, numDisparities, SADWindowSize,
|
||||
return Ptr<StereoSGBM>(
|
||||
new StereoSGBMImpl(minDisparity, numDisparities, SADWindowSize,
|
||||
P1, P2, disp12MaxDiff,
|
||||
preFilterCap, uniquenessRatio,
|
||||
speckleWindowSize, speckleRange,
|
||||
mode);
|
||||
mode));
|
||||
}
|
||||
|
||||
Rect getValidDisparityROI( Rect roi1, Rect roi2,
|
||||
|
@ -240,32 +240,32 @@ cvCorrectMatches(CvMat *F_, CvMat *points1_, CvMat *points2_, CvMat *new_points1
|
||||
}
|
||||
|
||||
// Make sure F uses double precision
|
||||
F = cvCreateMat(3,3,CV_64FC1);
|
||||
F.reset(cvCreateMat(3,3,CV_64FC1));
|
||||
cvConvert(F_, F);
|
||||
|
||||
// Make sure points1 uses double precision
|
||||
points1 = cvCreateMat(points1_->rows,points1_->cols,CV_64FC2);
|
||||
points1.reset(cvCreateMat(points1_->rows,points1_->cols,CV_64FC2));
|
||||
cvConvert(points1_, points1);
|
||||
|
||||
// Make sure points2 uses double precision
|
||||
points2 = cvCreateMat(points2_->rows,points2_->cols,CV_64FC2);
|
||||
points2.reset(cvCreateMat(points2_->rows,points2_->cols,CV_64FC2));
|
||||
cvConvert(points2_, points2);
|
||||
|
||||
tmp33 = cvCreateMat(3,3,CV_64FC1);
|
||||
tmp31 = cvCreateMat(3,1,CV_64FC1), tmp31_2 = cvCreateMat(3,1,CV_64FC1);
|
||||
T1i = cvCreateMat(3,3,CV_64FC1), T2i = cvCreateMat(3,3,CV_64FC1);
|
||||
R1 = cvCreateMat(3,3,CV_64FC1), R2 = cvCreateMat(3,3,CV_64FC1);
|
||||
TFT = cvCreateMat(3,3,CV_64FC1), TFTt = cvCreateMat(3,3,CV_64FC1), RTFTR = cvCreateMat(3,3,CV_64FC1);
|
||||
U = cvCreateMat(3,3,CV_64FC1);
|
||||
S = cvCreateMat(3,3,CV_64FC1);
|
||||
V = cvCreateMat(3,3,CV_64FC1);
|
||||
e1 = cvCreateMat(3,1,CV_64FC1), e2 = cvCreateMat(3,1,CV_64FC1);
|
||||
tmp33.reset(cvCreateMat(3,3,CV_64FC1));
|
||||
tmp31.reset(cvCreateMat(3,1,CV_64FC1)), tmp31_2.reset(cvCreateMat(3,1,CV_64FC1));
|
||||
T1i.reset(cvCreateMat(3,3,CV_64FC1)), T2i.reset(cvCreateMat(3,3,CV_64FC1));
|
||||
R1.reset(cvCreateMat(3,3,CV_64FC1)), R2.reset(cvCreateMat(3,3,CV_64FC1));
|
||||
TFT.reset(cvCreateMat(3,3,CV_64FC1)), TFTt.reset(cvCreateMat(3,3,CV_64FC1)), RTFTR.reset(cvCreateMat(3,3,CV_64FC1));
|
||||
U.reset(cvCreateMat(3,3,CV_64FC1));
|
||||
S.reset(cvCreateMat(3,3,CV_64FC1));
|
||||
V.reset(cvCreateMat(3,3,CV_64FC1));
|
||||
e1.reset(cvCreateMat(3,1,CV_64FC1)), e2.reset(cvCreateMat(3,1,CV_64FC1));
|
||||
|
||||
double x1, y1, x2, y2;
|
||||
double scale;
|
||||
double f1, f2, a, b, c, d;
|
||||
polynomial = cvCreateMat(1,7,CV_64FC1);
|
||||
result = cvCreateMat(1,6,CV_64FC2);
|
||||
polynomial.reset(cvCreateMat(1,7,CV_64FC1));
|
||||
result.reset(cvCreateMat(1,6,CV_64FC2));
|
||||
double t_min, s_val, t, s;
|
||||
for (int p = 0; p < points1->cols; ++p) {
|
||||
// Replace F by T2-t * F * T1-t
|
||||
|
@ -276,7 +276,7 @@ TEST(DISABLED_Calib3d_SolvePnPRansac, concurrency)
|
||||
{
|
||||
// limit concurrency to get determenistic result
|
||||
cv::theRNG().state = 20121010;
|
||||
cv::Ptr<tbb::task_scheduler_init> one_thread = new tbb::task_scheduler_init(1);
|
||||
tbb::task_scheduler_init one_thread(1);
|
||||
solvePnPRansac(object, image, camera_mat, dist_coef, rvec1, tvec1);
|
||||
}
|
||||
|
||||
@ -295,7 +295,7 @@ TEST(DISABLED_Calib3d_SolvePnPRansac, concurrency)
|
||||
{
|
||||
// single thread again
|
||||
cv::theRNG().state = 20121010;
|
||||
cv::Ptr<tbb::task_scheduler_init> one_thread = new tbb::task_scheduler_init(1);
|
||||
tbb::task_scheduler_init one_thread(1);
|
||||
solvePnPRansac(object, image, camera_mat, dist_coef, rvec2, tvec2);
|
||||
}
|
||||
|
||||
|
@ -128,7 +128,7 @@ cv::DetectionBasedTracker::SeparateDetectionWork::SeparateDetectionWork(Detectio
|
||||
stateThread(STATE_THREAD_STOPPED),
|
||||
timeWhenDetectingThreadStartedWork(-1)
|
||||
{
|
||||
CV_Assert(!_detector.empty());
|
||||
CV_Assert(_detector);
|
||||
|
||||
cascadeInThread = _detector;
|
||||
|
||||
@ -462,11 +462,11 @@ cv::DetectionBasedTracker::DetectionBasedTracker(cv::Ptr<IDetector> mainDetector
|
||||
cascadeForTracking(trackingDetector)
|
||||
{
|
||||
CV_Assert( (params.maxTrackLifetime >= 0)
|
||||
// && (!mainDetector.empty())
|
||||
&& (!trackingDetector.empty()) );
|
||||
// && mainDetector
|
||||
&& trackingDetector );
|
||||
|
||||
if (!mainDetector.empty()) {
|
||||
separateDetectionWork = new SeparateDetectionWork(*this, mainDetector);
|
||||
if (mainDetector) {
|
||||
separateDetectionWork.reset(new SeparateDetectionWork(*this, mainDetector));
|
||||
}
|
||||
|
||||
weightsPositionsSmoothing.push_back(1);
|
||||
@ -483,7 +483,7 @@ void DetectionBasedTracker::process(const Mat& imageGray)
|
||||
{
|
||||
CV_Assert(imageGray.type()==CV_8UC1);
|
||||
|
||||
if ( (!separateDetectionWork.empty()) && (!separateDetectionWork->isWorking()) ) {
|
||||
if ( separateDetectionWork && !separateDetectionWork->isWorking() ) {
|
||||
separateDetectionWork->run();
|
||||
}
|
||||
|
||||
@ -501,7 +501,7 @@ void DetectionBasedTracker::process(const Mat& imageGray)
|
||||
|
||||
std::vector<Rect> rectsWhereRegions;
|
||||
bool shouldHandleResult=false;
|
||||
if (!separateDetectionWork.empty()) {
|
||||
if (separateDetectionWork) {
|
||||
shouldHandleResult = separateDetectionWork->communicateWithDetectingThread(imageGray, rectsWhereRegions);
|
||||
}
|
||||
|
||||
@ -589,7 +589,7 @@ void cv::DetectionBasedTracker::getObjects(std::vector<ExtObject>& result) const
|
||||
|
||||
bool cv::DetectionBasedTracker::run()
|
||||
{
|
||||
if (!separateDetectionWork.empty()) {
|
||||
if (separateDetectionWork) {
|
||||
return separateDetectionWork->run();
|
||||
}
|
||||
return false;
|
||||
@ -597,14 +597,14 @@ bool cv::DetectionBasedTracker::run()
|
||||
|
||||
void cv::DetectionBasedTracker::stop()
|
||||
{
|
||||
if (!separateDetectionWork.empty()) {
|
||||
if (separateDetectionWork) {
|
||||
separateDetectionWork->stop();
|
||||
}
|
||||
}
|
||||
|
||||
void cv::DetectionBasedTracker::resetTracking()
|
||||
{
|
||||
if (!separateDetectionWork.empty()) {
|
||||
if (separateDetectionWork) {
|
||||
separateDetectionWork->resetTracking();
|
||||
}
|
||||
trackedObjects.clear();
|
||||
@ -876,11 +876,11 @@ bool cv::DetectionBasedTracker::setParameters(const Parameters& params)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!separateDetectionWork.empty()) {
|
||||
if (separateDetectionWork) {
|
||||
separateDetectionWork->lock();
|
||||
}
|
||||
parameters=params;
|
||||
if (!separateDetectionWork.empty()) {
|
||||
if (separateDetectionWork) {
|
||||
separateDetectionWork->unlock();
|
||||
}
|
||||
return true;
|
||||
|
@ -851,18 +851,18 @@ int LBPH::predict(InputArray _src) const {
|
||||
|
||||
Ptr<FaceRecognizer> createEigenFaceRecognizer(int num_components, double threshold)
|
||||
{
|
||||
return new Eigenfaces(num_components, threshold);
|
||||
return makePtr<Eigenfaces>(num_components, threshold);
|
||||
}
|
||||
|
||||
Ptr<FaceRecognizer> createFisherFaceRecognizer(int num_components, double threshold)
|
||||
{
|
||||
return new Fisherfaces(num_components, threshold);
|
||||
return makePtr<Fisherfaces>(num_components, threshold);
|
||||
}
|
||||
|
||||
Ptr<FaceRecognizer> createLBPHFaceRecognizer(int radius, int neighbors,
|
||||
int grid_x, int grid_y, double threshold)
|
||||
{
|
||||
return new LBPH(radius, neighbors, grid_x, grid_y, threshold);
|
||||
return makePtr<LBPH>(radius, neighbors, grid_x, grid_y, threshold);
|
||||
}
|
||||
|
||||
CV_INIT_ALGORITHM(Eigenfaces, "FaceRecognizer.Eigenfaces",
|
||||
@ -894,7 +894,7 @@ CV_INIT_ALGORITHM(LBPH, "FaceRecognizer.LBPH",
|
||||
|
||||
bool initModule_contrib()
|
||||
{
|
||||
Ptr<Algorithm> efaces = createEigenfaces_hidden(), ffaces = createFisherfaces_hidden(), lbph = createLBPH_hidden();
|
||||
Ptr<Algorithm> efaces = createEigenfaces_ptr_hidden(), ffaces = createFisherfaces_ptr_hidden(), lbph = createLBPH_ptr_hidden();
|
||||
return efaces->info() != 0 && ffaces->info() != 0 && lbph->info() != 0;
|
||||
}
|
||||
|
||||
|
@ -54,7 +54,7 @@ CvFeatureTracker::CvFeatureTracker(CvFeatureTrackerParams _params) :
|
||||
{
|
||||
case CvFeatureTrackerParams::SIFT:
|
||||
dd = Algorithm::create<Feature2D>("Feature2D.SIFT");
|
||||
if( dd.empty() )
|
||||
if( !dd )
|
||||
CV_Error(CV_StsNotImplemented, "OpenCV has been compiled without SIFT support");
|
||||
dd->set("nOctaveLayers", 5);
|
||||
dd->set("contrastThreshold", 0.04);
|
||||
@ -62,7 +62,7 @@ CvFeatureTracker::CvFeatureTracker(CvFeatureTrackerParams _params) :
|
||||
break;
|
||||
case CvFeatureTrackerParams::SURF:
|
||||
dd = Algorithm::create<Feature2D>("Feature2D.SURF");
|
||||
if( dd.empty() )
|
||||
if( !dd )
|
||||
CV_Error(CV_StsNotImplemented, "OpenCV has been compiled without SURF support");
|
||||
dd->set("hessianThreshold", 400);
|
||||
dd->set("nOctaves", 3);
|
||||
@ -73,7 +73,7 @@ CvFeatureTracker::CvFeatureTracker(CvFeatureTrackerParams _params) :
|
||||
break;
|
||||
}
|
||||
|
||||
matcher = new BFMatcher(NORM_L2);
|
||||
matcher = makePtr<BFMatcher>(int(NORM_L2));
|
||||
}
|
||||
|
||||
CvFeatureTracker::~CvFeatureTracker()
|
||||
|
@ -638,6 +638,48 @@ The keypoint constructors
|
||||
:param _class_id: object id
|
||||
|
||||
|
||||
KeyPoint::convert
|
||||
--------------------
|
||||
|
||||
This method converts vector of keypoints to vector of points or the reverse, where each keypoint is assigned the same size and the same orientation.
|
||||
|
||||
.. ocv:function:: void KeyPoint::convert(const std::vector<KeyPoint>& keypoints, std::vector<Point2f>& points2f, const std::vector<int>& keypointIndexes=std::vector<int>())
|
||||
|
||||
.. ocv:function:: void KeyPoint::convert(const std::vector<Point2f>& points2f, std::vector<KeyPoint>& keypoints, float size=1, float response=1, int octave=0, int class_id=-1)
|
||||
|
||||
.. ocv:pyfunction:: cv2.KeyPoint_convert(keypoints[, keypointIndexes]) -> points2f
|
||||
|
||||
.. ocv:pyfunction:: cv2.KeyPoint_convert(points2f[, size[, response[, octave[, class_id]]]]) -> keypoints
|
||||
|
||||
:param keypoints: Keypoints obtained from any feature detection algorithm like SIFT/SURF/ORB
|
||||
|
||||
:param points2f: Array of (x,y) coordinates of each keypoint
|
||||
|
||||
:param keypointIndexes: Array of indexes of keypoints to be converted to points. (Acts like a mask to convert only specified keypoints)
|
||||
|
||||
:param _size: keypoint diameter
|
||||
|
||||
:param _response: keypoint detector response on the keypoint (that is, strength of the keypoint)
|
||||
|
||||
:param _octave: pyramid octave in which the keypoint has been detected
|
||||
|
||||
:param _class_id: object id
|
||||
|
||||
|
||||
KeyPoint::overlap
|
||||
--------------------
|
||||
|
||||
This method computes overlap for pair of keypoints. Overlap is the ratio between area of keypoint regions' intersection and area of keypoint regions' union (considering keypoint region as circle). If they don't overlap, we get zero. If they coincide at same location with same size, we get 1.
|
||||
|
||||
.. ocv:function:: float KeyPoint::overlap(const KeyPoint& kp1, const KeyPoint& kp2)
|
||||
|
||||
.. ocv:pyfunction:: cv2.KeyPoint_overlap(kp1, kp2) -> retval
|
||||
|
||||
:param kp1: First keypoint
|
||||
|
||||
:param kp2: Second keypoint
|
||||
|
||||
|
||||
DMatch
|
||||
------
|
||||
.. ocv:class:: DMatch
|
||||
@ -668,187 +710,328 @@ train descriptor index, train image index, and distance between descriptors. ::
|
||||
};
|
||||
|
||||
|
||||
|
||||
.. _Ptr:
|
||||
|
||||
Ptr
|
||||
---
|
||||
.. ocv:class:: Ptr
|
||||
|
||||
Template class for smart reference-counting pointers ::
|
||||
Template class for smart pointers with shared ownership. ::
|
||||
|
||||
template<typename _Tp> class Ptr
|
||||
template<typename T>
|
||||
struct Ptr
|
||||
{
|
||||
public:
|
||||
// default constructor
|
||||
typedef T element_type;
|
||||
|
||||
Ptr();
|
||||
// constructor that wraps the object pointer
|
||||
Ptr(_Tp* _obj);
|
||||
// destructor: calls release()
|
||||
|
||||
template<typename Y>
|
||||
explicit Ptr(Y* p);
|
||||
template<typename Y, typename D>
|
||||
Ptr(Y* p, D d);
|
||||
|
||||
Ptr(const Ptr& o);
|
||||
template<typename Y>
|
||||
Ptr(const Ptr<Y>& o);
|
||||
template<typename Y>
|
||||
Ptr(const Ptr<Y>& o, T* p);
|
||||
|
||||
~Ptr();
|
||||
// copy constructor; increments ptr's reference counter
|
||||
Ptr(const Ptr& ptr);
|
||||
// assignment operator; decrements own reference counter
|
||||
// (with release()) and increments ptr's reference counter
|
||||
Ptr& operator = (const Ptr& ptr);
|
||||
// increments reference counter
|
||||
void addref();
|
||||
// decrements reference counter; when it becomes 0,
|
||||
// delete_obj() is called
|
||||
|
||||
Ptr& operator = (const Ptr& o);
|
||||
template<typename Y>
|
||||
Ptr& operator = (const Ptr<Y>& o);
|
||||
|
||||
void release();
|
||||
// user-specified custom object deletion operation.
|
||||
// by default, "delete obj;" is called
|
||||
void delete_obj();
|
||||
// returns true if obj == 0;
|
||||
|
||||
template<typename Y>
|
||||
void reset(Y* p);
|
||||
template<typename Y, typename D>
|
||||
void reset(Y* p, D d);
|
||||
|
||||
void swap(Ptr& o);
|
||||
|
||||
T* get() const;
|
||||
|
||||
T& operator * () const;
|
||||
T* operator -> () const;
|
||||
operator T* () const;
|
||||
|
||||
bool empty() const;
|
||||
|
||||
// provide access to the object fields and methods
|
||||
_Tp* operator -> ();
|
||||
const _Tp* operator -> () const;
|
||||
|
||||
// return the underlying object pointer;
|
||||
// thanks to the methods, the Ptr<_Tp> can be
|
||||
// used instead of _Tp*
|
||||
operator _Tp* ();
|
||||
operator const _Tp*() const;
|
||||
protected:
|
||||
// the encapsulated object pointer
|
||||
_Tp* obj;
|
||||
// the associated reference counter
|
||||
int* refcount;
|
||||
template<typename Y>
|
||||
Ptr<Y> staticCast() const;
|
||||
template<typename Y>
|
||||
Ptr<Y> constCast() const;
|
||||
template<typename Y>
|
||||
Ptr<Y> dynamicCast() const;
|
||||
};
|
||||
|
||||
|
||||
The ``Ptr<_Tp>`` class is a template class that wraps pointers of the corresponding type. It is
|
||||
similar to ``shared_ptr`` that is part of the Boost library
|
||||
(http://www.boost.org/doc/libs/1_40_0/libs/smart_ptr/shared_ptr.htm) and also part of the
|
||||
`C++0x <http://en.wikipedia.org/wiki/C++0x>`_ standard.
|
||||
A ``Ptr<T>`` pretends to be a pointer to an object of type T.
|
||||
Unlike an ordinary pointer, however, the object will be automatically
|
||||
cleaned up once all ``Ptr`` instances pointing to it are destroyed.
|
||||
|
||||
This class provides the following options:
|
||||
``Ptr`` is similar to ``boost::shared_ptr`` that is part of the Boost library
|
||||
(http://www.boost.org/doc/libs/release/libs/smart_ptr/shared_ptr.htm)
|
||||
and ``std::shared_ptr`` from the `C++11 <http://en.wikipedia.org/wiki/C++11>`_ standard.
|
||||
|
||||
This class provides the following advantages:
|
||||
|
||||
*
|
||||
Default constructor, copy constructor, and assignment operator for an arbitrary C++ class
|
||||
or a C structure. For some objects, like files, windows, mutexes, sockets, and others, a copy
|
||||
or C structure. For some objects, like files, windows, mutexes, sockets, and others, a copy
|
||||
constructor or an assignment operator are difficult to define. For some other objects, like
|
||||
complex classifiers in OpenCV, copy constructors are absent and not easy to implement. Finally,
|
||||
some of complex OpenCV and your own data structures may be written in C.
|
||||
However, copy constructors and default constructors can simplify programming a lot.Besides,
|
||||
they are often required (for example, by STL containers). By wrapping a pointer to such a
|
||||
complex object ``TObj`` to ``Ptr<TObj>``, you automatically get all of the necessary
|
||||
However, copy constructors and default constructors can simplify programming a lot. Besides,
|
||||
they are often required (for example, by STL containers). By using a ``Ptr`` to such an
|
||||
object instead of the object itself, you automatically get all of the necessary
|
||||
constructors and the assignment operator.
|
||||
|
||||
*
|
||||
*O(1)* complexity of the above-mentioned operations. While some structures, like ``std::vector``,
|
||||
provide a copy constructor and an assignment operator, the operations may take a considerable
|
||||
amount of time if the data structures are large. But if the structures are put into ``Ptr<>``,
|
||||
amount of time if the data structures are large. But if the structures are put into a ``Ptr``,
|
||||
the overhead is small and independent of the data size.
|
||||
|
||||
*
|
||||
Automatic destruction, even for C structures. See the example below with ``FILE*``.
|
||||
Automatic and customizable cleanup, even for C structures. See the example below with ``FILE*``.
|
||||
|
||||
*
|
||||
Heterogeneous collections of objects. The standard STL and most other C++ and OpenCV containers
|
||||
can store only objects of the same type and the same size. The classical solution to store objects
|
||||
of different types in the same container is to store pointers to the base class ``base_class_t*``
|
||||
instead but then you loose the automatic memory management. Again, by using ``Ptr<base_class_t>()``
|
||||
instead of the raw pointers, you can solve the problem.
|
||||
of different types in the same container is to store pointers to the base class (``Base*``)
|
||||
instead but then you lose the automatic memory management. Again, by using ``Ptr<Base>``
|
||||
instead of raw pointers, you can solve the problem.
|
||||
|
||||
The ``Ptr`` class treats the wrapped object as a black box. The reference counter is allocated and
|
||||
managed separately. The only thing the pointer class needs to know about the object is how to
|
||||
deallocate it. This knowledge is encapsulated in the ``Ptr::delete_obj()`` method that is called when
|
||||
the reference counter becomes 0. If the object is a C++ class instance, no additional coding is
|
||||
needed, because the default implementation of this method calls ``delete obj;``. However, if the
|
||||
object is deallocated in a different way, the specialized method should be created. For example,
|
||||
if you want to wrap ``FILE``, the ``delete_obj`` may be implemented as follows: ::
|
||||
A ``Ptr`` is said to *own* a pointer - that is, for each ``Ptr`` there is a pointer that will be deleted
|
||||
once all ``Ptr`` instances that own it are destroyed. The owned pointer may be null, in which case nothing is deleted.
|
||||
Each ``Ptr`` also *stores* a pointer. The stored pointer is the pointer the ``Ptr`` pretends to be;
|
||||
that is, the one you get when you use :ocv:func:`Ptr::get` or the conversion to ``T*``. It's usually
|
||||
the same as the owned pointer, but if you use casts or the general shared-ownership constructor, the two may diverge:
|
||||
the ``Ptr`` will still own the original pointer, but will itself point to something else.
|
||||
|
||||
template<> inline void Ptr<FILE>::delete_obj()
|
||||
{
|
||||
fclose(obj); // no need to clear the pointer afterwards,
|
||||
// it is done externally.
|
||||
}
|
||||
...
|
||||
The owned pointer is treated as a black box. The only thing ``Ptr`` needs to know about it is how to
|
||||
delete it. This knowledge is encapsulated in the *deleter* - an auxiliary object that is associated
|
||||
with the owned pointer and shared between all ``Ptr`` instances that own it. The default deleter is
|
||||
an instance of ``DefaultDeleter``, which uses the standard C++ ``delete`` operator; as such it
|
||||
will work with any pointer allocated with the standard ``new`` operator.
|
||||
|
||||
// now use it:
|
||||
Ptr<FILE> f(fopen("myfile.txt", "r"));
|
||||
if(f.empty())
|
||||
throw ...;
|
||||
However, if the pointer must be deleted in a different way, you must specify a custom deleter upon
|
||||
``Ptr`` construction. A deleter is simply a callable object that accepts the pointer as its sole argument.
|
||||
For example, if you want to wrap ``FILE``, you may do so as follows::
|
||||
|
||||
Ptr<FILE> f(fopen("myfile.txt", "w"), fclose);
|
||||
if(!f) throw ...;
|
||||
fprintf(f, ....);
|
||||
...
|
||||
// the file will be closed automatically by the Ptr<FILE> destructor.
|
||||
// the file will be closed automatically by f's destructor.
|
||||
|
||||
Alternatively, if you want all pointers of a particular type to be deleted the same way,
|
||||
you can specialize ``DefaultDeleter<T>::operator()`` for that type, like this::
|
||||
|
||||
.. note:: The reference increment/decrement operations are implemented as atomic operations,
|
||||
and therefore it is normally safe to use the classes in multi-threaded applications.
|
||||
The same is true for :ocv:class:`Mat` and other C++ OpenCV classes that operate on
|
||||
the reference counters.
|
||||
namespace cv {
|
||||
template<> void DefaultDeleter<FILE>::operator ()(FILE * obj) const
|
||||
{
|
||||
fclose(obj);
|
||||
}
|
||||
}
|
||||
|
||||
Ptr::Ptr
|
||||
--------
|
||||
Various Ptr constructors.
|
||||
For convenience, the following types from the OpenCV C API already have such a specialization
|
||||
that calls the appropriate release function:
|
||||
|
||||
* ``CvCapture``
|
||||
* :ocv:struct:`CvDTreeSplit`
|
||||
* :ocv:struct:`CvFileStorage`
|
||||
* ``CvHaarClassifierCascade``
|
||||
* :ocv:struct:`CvMat`
|
||||
* :ocv:struct:`CvMatND`
|
||||
* :ocv:struct:`CvMemStorage`
|
||||
* :ocv:struct:`CvSparseMat`
|
||||
* ``CvVideoWriter``
|
||||
* :ocv:struct:`IplImage`
|
||||
|
||||
.. note:: The shared ownership mechanism is implemented with reference counting. As such,
|
||||
cyclic ownership (e.g. when object ``a`` contains a ``Ptr`` to object ``b``, which
|
||||
contains a ``Ptr`` to object ``a``) will lead to all involved objects never being
|
||||
cleaned up. Avoid such situations.
|
||||
|
||||
.. note:: It is safe to concurrently read (but not write) a ``Ptr`` instance from multiple threads
|
||||
and therefore it is normally safe to use it in multi-threaded applications.
|
||||
The same is true for :ocv:class:`Mat` and other C++ OpenCV classes that use internal
|
||||
reference counts.
|
||||
|
||||
Ptr::Ptr (null)
|
||||
------------------
|
||||
|
||||
.. ocv:function:: Ptr::Ptr()
|
||||
.. ocv:function:: Ptr::Ptr(_Tp* _obj)
|
||||
.. ocv:function:: Ptr::Ptr(const Ptr& ptr)
|
||||
|
||||
:param _obj: Object for copy.
|
||||
:param ptr: Object for copy.
|
||||
The default constructor creates a null ``Ptr`` - one that owns and stores a null pointer.
|
||||
|
||||
Ptr::Ptr (assuming ownership)
|
||||
-----------------------------
|
||||
|
||||
.. ocv:function:: template<typename Y> Ptr::Ptr(Y* p)
|
||||
.. ocv:function:: template<typename Y, typename D> Ptr::Ptr(Y* p, D d)
|
||||
|
||||
:param d: Deleter to use for the owned pointer.
|
||||
:param p: Pointer to own.
|
||||
|
||||
If ``p`` is null, these are equivalent to the default constructor.
|
||||
|
||||
Otherwise, these constructors assume ownership of ``p`` - that is, the created ``Ptr`` owns
|
||||
and stores ``p`` and assumes it is the sole owner of it. Don't use them if ``p`` is already
|
||||
owned by another ``Ptr``, or else ``p`` will get deleted twice.
|
||||
|
||||
With the first constructor, ``DefaultDeleter<Y>()`` becomes the associated deleter (so ``p``
|
||||
will eventually be deleted with the standard ``delete`` operator). ``Y`` must be a complete
|
||||
type at the point of invocation.
|
||||
|
||||
With the second constructor, ``d`` becomes the associated deleter.
|
||||
|
||||
``Y*`` must be convertible to ``T*``.
|
||||
|
||||
.. note:: It is often easier to use :ocv:func:`makePtr` instead.
|
||||
|
||||
Ptr::Ptr (sharing ownership)
|
||||
----------------------------
|
||||
|
||||
.. ocv:function:: Ptr::Ptr(const Ptr& o)
|
||||
.. ocv:function:: template<typename Y> Ptr::Ptr(const Ptr<Y>& o)
|
||||
.. ocv:function:: template<typename Y> Ptr::Ptr(const Ptr<Y>& o, T* p)
|
||||
|
||||
:param o: ``Ptr`` to share ownership with.
|
||||
:param p: Pointer to store.
|
||||
|
||||
These constructors create a ``Ptr`` that shares ownership with another ``Ptr`` - that is,
|
||||
own the same pointer as ``o``.
|
||||
|
||||
With the first two, the same pointer is stored, as well; for the second, ``Y*`` must be convertible to ``T*``.
|
||||
|
||||
With the third, ``p`` is stored, and ``Y`` may be any type. This constructor allows to have completely
|
||||
unrelated owned and stored pointers, and should be used with care to avoid confusion. A relatively
|
||||
benign use is to create a non-owning ``Ptr``, like this::
|
||||
|
||||
ptr = Ptr<T>(Ptr<T>(), dont_delete_me); // owns nothing; will not delete the pointer.
|
||||
|
||||
Ptr::~Ptr
|
||||
---------
|
||||
The Ptr destructor.
|
||||
|
||||
.. ocv:function:: Ptr::~Ptr()
|
||||
|
||||
The destructor is equivalent to calling :ocv:func:`Ptr::release`.
|
||||
|
||||
Ptr::operator =
|
||||
----------------
|
||||
Assignment operator.
|
||||
|
||||
.. ocv:function:: Ptr& Ptr::operator = (const Ptr& ptr)
|
||||
.. ocv:function:: Ptr& Ptr::operator = (const Ptr& o)
|
||||
.. ocv:function:: template<typename Y> Ptr& Ptr::operator = (const Ptr<Y>& o)
|
||||
|
||||
:param ptr: Object for assignment.
|
||||
:param o: ``Ptr`` to share ownership with.
|
||||
|
||||
Decrements own reference counter (with ``release()``) and increments ptr's reference counter.
|
||||
Assignment replaces the current ``Ptr`` instance with one that owns and stores same
|
||||
pointers as ``o`` and then destroys the old instance.
|
||||
|
||||
Ptr::addref
|
||||
-----------
|
||||
Increments reference counter.
|
||||
|
||||
.. ocv:function:: void Ptr::addref()
|
||||
|
||||
Ptr::release
|
||||
------------
|
||||
Decrements reference counter; when it becomes 0, ``delete_obj()`` is called.
|
||||
|
||||
.. ocv:function:: void Ptr::release()
|
||||
|
||||
Ptr::delete_obj
|
||||
---------------
|
||||
User-specified custom object deletion operation. By default, ``delete obj;`` is called.
|
||||
If no other ``Ptr`` instance owns the owned pointer, deletes it with the associated deleter.
|
||||
Then sets both the owned and the stored pointers to ``NULL``.
|
||||
|
||||
.. ocv:function:: void Ptr::delete_obj()
|
||||
|
||||
Ptr::reset
|
||||
----------
|
||||
|
||||
.. ocv:function:: template<typename Y> void Ptr::reset(Y* p)
|
||||
.. ocv:function:: template<typename Y, typename D> void Ptr::reset(Y* p, D d)
|
||||
|
||||
:param d: Deleter to use for the owned pointer.
|
||||
:param p: Pointer to own.
|
||||
|
||||
``ptr.reset(...)`` is equivalent to ``ptr = Ptr<T>(...)``.
|
||||
|
||||
Ptr::swap
|
||||
---------
|
||||
|
||||
.. ocv:function:: void Ptr::swap(Ptr& o)
|
||||
|
||||
:param o: ``Ptr`` to swap with.
|
||||
|
||||
Swaps the owned and stored pointers (and deleters, if any) of this and ``o``.
|
||||
|
||||
Ptr::get
|
||||
--------
|
||||
|
||||
.. ocv:function:: T* Ptr::get() const
|
||||
|
||||
Returns the stored pointer.
|
||||
|
||||
Ptr pointer emulation
|
||||
---------------------
|
||||
|
||||
.. ocv:function:: T& Ptr::operator * () const
|
||||
.. ocv:function:: T* Ptr::operator -> () const
|
||||
.. ocv:function:: Ptr::operator T* () const
|
||||
|
||||
These operators are what allows ``Ptr`` to pretend to be a pointer.
|
||||
|
||||
If ``ptr`` is a ``Ptr<T>``, then ``*ptr`` is equivalent to ``*ptr.get()``
|
||||
and ``ptr->foo`` is equivalent to ``ptr.get()->foo``. In addition, ``ptr``
|
||||
is implicitly convertible to ``T*``, and such conversion is equivalent to
|
||||
``ptr.get()``. As a corollary, ``if (ptr)`` is equivalent to ``if (ptr.get())``.
|
||||
In other words, a ``Ptr`` behaves as if it was its own stored pointer.
|
||||
|
||||
Ptr::empty
|
||||
----------
|
||||
Returns true if obj == 0;
|
||||
|
||||
bool empty() const;
|
||||
.. ocv:function:: bool Ptr::empty() const
|
||||
|
||||
Ptr::operator ->
|
||||
----------------
|
||||
Provide access to the object fields and methods.
|
||||
``ptr.empty()`` is equivalent to ``!ptr.get()``.
|
||||
|
||||
.. ocv:function:: template<typename _Tp> _Tp* Ptr::operator -> ()
|
||||
.. ocv:function:: template<typename _Tp> const _Tp* Ptr::operator -> () const
|
||||
Ptr casts
|
||||
---------
|
||||
|
||||
.. ocv:function:: template<typename Y> Ptr<Y> Ptr::staticCast() const
|
||||
.. ocv:function:: template<typename Y> Ptr<Y> Ptr::constCast() const
|
||||
.. ocv:function:: template<typename Y> Ptr<Y> Ptr::dynamicCast() const
|
||||
|
||||
Ptr::operator _Tp*
|
||||
------------------
|
||||
Returns the underlying object pointer. Thanks to the methods, the ``Ptr<_Tp>`` can be used instead
|
||||
of ``_Tp*``.
|
||||
If ``ptr`` is a ``Ptr``, then ``ptr.fooCast<Y>()`` is equivalent to
|
||||
``Ptr<Y>(ptr, foo_cast<Y>(ptr.get()))``. That is, these functions create
|
||||
a new ``Ptr`` with the same owned pointer and a cast stored pointer.
|
||||
|
||||
.. ocv:function:: template<typename _Tp> Ptr::operator _Tp* ()
|
||||
.. ocv:function:: template<typename _Tp> Ptr::operator const _Tp*() const
|
||||
Ptr global swap
|
||||
---------------
|
||||
|
||||
.. ocv:function:: template<typename T> void swap(Ptr<T>& ptr1, Ptr<T>& ptr2)
|
||||
|
||||
Equivalent to ``ptr1.swap(ptr2)``. Provided to help write generic algorithms.
|
||||
|
||||
Ptr comparisons
|
||||
---------------
|
||||
|
||||
.. ocv:function:: template<typename T> bool operator == (const Ptr<T>& ptr1, const Ptr<T>& ptr2)
|
||||
.. ocv:function:: template<typename T> bool operator != (const Ptr<T>& ptr1, const Ptr<T>& ptr2)
|
||||
|
||||
Return whether ``ptr1.get()`` and ``ptr2.get()`` are equal and not equal, respectively.
|
||||
|
||||
makePtr
|
||||
-------
|
||||
|
||||
.. ocv:function:: template<typename T> Ptr<T> makePtr()
|
||||
.. ocv:function:: template<typename T, typename A1> Ptr<T> makePtr(const A1& a1)
|
||||
.. ocv:function:: template<typename T, typename A1, typename A2> Ptr<T> makePtr(const A1& a1, const A2& a2)
|
||||
.. ocv:function:: template<typename T, typename A1, typename A2, typename A3> Ptr<T> makePtr(const A1& a1, const A2& a2, const A3& a3)
|
||||
|
||||
(and so on...)
|
||||
|
||||
``makePtr<T>(...)`` is equivalent to ``Ptr<T>(new T(...))``. It is shorter than the latter, and
|
||||
it's marginally safer than using a constructor or :ocv:func:`Ptr::reset`, since it ensures that
|
||||
the owned pointer is new and thus not owned by any other ``Ptr`` instance.
|
||||
|
||||
Unfortunately, perfect forwarding is impossible to implement in C++03, and so ``makePtr`` is limited
|
||||
to constructors of ``T`` that have up to 10 arguments, none of which are non-const references.
|
||||
|
||||
Mat
|
||||
---
|
||||
@ -2925,7 +3108,7 @@ Creates algorithm instance by name
|
||||
|
||||
:param name: The algorithm name, one of the names returned by ``Algorithm::getList()``.
|
||||
|
||||
This static method creates a new instance of the specified algorithm. If there is no such algorithm, the method will silently return null pointer (that can be checked by ``Ptr::empty()`` method). Also, you should specify the particular ``Algorithm`` subclass as ``_Tp`` (or simply ``Algorithm`` if you do not know it at that point). ::
|
||||
This static method creates a new instance of the specified algorithm. If there is no such algorithm, the method will silently return a null pointer. Also, you should specify the particular ``Algorithm`` subclass as ``_Tp`` (or simply ``Algorithm`` if you do not know it at that point). ::
|
||||
|
||||
Ptr<BackgroundSubtractor> bgfg = Algorithm::create<BackgroundSubtractor>("BackgroundSubtractor.MOG2");
|
||||
|
||||
|
@ -83,17 +83,22 @@ First of all, ``std::vector``, ``Mat``, and other data structures used by the fu
|
||||
// matrix will be deallocated, since it is not referenced by anyone
|
||||
C = C.clone();
|
||||
|
||||
You see that the use of ``Mat`` and other basic structures is simple. But what about high-level classes or even user data types created without taking automatic memory management into account? For them, OpenCV offers the ``Ptr<>`` template class that is similar to ``std::shared_ptr`` from C++ TR1. So, instead of using plain pointers::
|
||||
You see that the use of ``Mat`` and other basic structures is simple. But what about high-level classes or even user
|
||||
data types created without taking automatic memory management into account? For them, OpenCV offers the :ocv:class:`Ptr`
|
||||
template class that is similar to ``std::shared_ptr`` from C++11. So, instead of using plain pointers::
|
||||
|
||||
T* ptr = new T(...);
|
||||
|
||||
you can use::
|
||||
|
||||
Ptr<T> ptr = new T(...);
|
||||
Ptr<T> ptr(new T(...));
|
||||
|
||||
That is, ``Ptr<T> ptr`` encapsulates a pointer to a ``T`` instance and a reference counter associated with the pointer. See the
|
||||
:ocv:class:`Ptr`
|
||||
description for details.
|
||||
or::
|
||||
|
||||
Ptr<T> ptr = makePtr<T>(...);
|
||||
|
||||
``Ptr<T>`` encapsulates a pointer to a ``T`` instance and a reference counter associated with the pointer. See the
|
||||
:ocv:class:`Ptr` description for details.
|
||||
|
||||
.. _AutomaticAllocation:
|
||||
|
||||
|
@ -1882,13 +1882,13 @@ CV_EXPORTS void insertImageCOI(InputArray coiimg, CvArr* arr, int coi=-1);
|
||||
|
||||
|
||||
|
||||
//////// specializied implementations of Ptr::delete_obj() for classic OpenCV types ////////
|
||||
////// specialized implementations of DefaultDeleter::operator() for classic OpenCV types //////
|
||||
|
||||
template<> CV_EXPORTS void Ptr<CvMat>::delete_obj();
|
||||
template<> CV_EXPORTS void Ptr<IplImage>::delete_obj();
|
||||
template<> CV_EXPORTS void Ptr<CvMatND>::delete_obj();
|
||||
template<> CV_EXPORTS void Ptr<CvSparseMat>::delete_obj();
|
||||
template<> CV_EXPORTS void Ptr<CvMemStorage>::delete_obj();
|
||||
template<> CV_EXPORTS void DefaultDeleter<CvMat>::operator ()(CvMat* obj) const;
|
||||
template<> CV_EXPORTS void DefaultDeleter<IplImage>::operator ()(IplImage* obj) const;
|
||||
template<> CV_EXPORTS void DefaultDeleter<CvMatND>::operator ()(CvMatND* obj) const;
|
||||
template<> CV_EXPORTS void DefaultDeleter<CvSparseMat>::operator ()(CvSparseMat* obj) const;
|
||||
template<> CV_EXPORTS void DefaultDeleter<CvMemStorage>::operator ()(CvMemStorage* obj) const;
|
||||
|
||||
////////////// convenient wrappers for operating old-style dynamic structures //////////////
|
||||
|
||||
|
@ -666,12 +666,6 @@ CV_EXPORTS void printShortCudaDeviceInfo(int device);
|
||||
|
||||
}} // namespace cv { namespace cuda {
|
||||
|
||||
namespace cv {
|
||||
|
||||
template <> CV_EXPORTS void Ptr<cv::cuda::Stream::Impl>::delete_obj();
|
||||
template <> CV_EXPORTS void Ptr<cv::cuda::Event::Impl>::delete_obj();
|
||||
|
||||
}
|
||||
|
||||
#include "opencv2/core/cuda.inl.hpp"
|
||||
|
||||
|
@ -158,69 +158,176 @@ public:
|
||||
size_type max_size() const { return cv::max(static_cast<_Tp>(-1)/sizeof(_Tp), 1); }
|
||||
};
|
||||
|
||||
|
||||
|
||||
//////////////////// generic_type ref-counting pointer class for C/C++ objects ////////////////////////
|
||||
|
||||
/*!
|
||||
Smart pointer to dynamically allocated objects.
|
||||
|
||||
This is template pointer-wrapping class that stores the associated reference counter along with the
|
||||
object pointer. The class is similar to std::smart_ptr<> from the recent addons to the C++ standard,
|
||||
but is shorter to write :) and self-contained (i.e. does add any dependency on the compiler or an external library).
|
||||
|
||||
Basically, you can use "Ptr<MyObjectType> ptr" (or faster "const Ptr<MyObjectType>& ptr" for read-only access)
|
||||
everywhere instead of "MyObjectType* ptr", where MyObjectType is some C structure or a C++ class.
|
||||
To make it all work, you need to specialize Ptr<>::delete_obj(), like:
|
||||
|
||||
\code
|
||||
template<> CV_EXPORTS void Ptr<MyObjectType>::delete_obj() { call_destructor_func(obj); }
|
||||
\endcode
|
||||
|
||||
\note{if MyObjectType is a C++ class with a destructor, you do not need to specialize delete_obj(),
|
||||
since the default implementation calls "delete obj;"}
|
||||
|
||||
\note{Another good property of the class is that the operations on the reference counter are atomic,
|
||||
i.e. it is safe to use the class in multi-threaded applications}
|
||||
*/
|
||||
template<typename _Tp> class Ptr
|
||||
namespace detail
|
||||
{
|
||||
public:
|
||||
//! empty constructor
|
||||
Ptr();
|
||||
//! take ownership of the pointer. The associated reference counter is allocated and set to 1
|
||||
Ptr(_Tp* _obj);
|
||||
//! calls release()
|
||||
~Ptr();
|
||||
//! copy constructor. Copies the members and calls addref()
|
||||
Ptr(const Ptr& ptr);
|
||||
template<typename _Tp2> Ptr(const Ptr<_Tp2>& ptr);
|
||||
//! copy operator. Calls ptr.addref() and release() before copying the members
|
||||
Ptr& operator = (const Ptr& ptr);
|
||||
//! increments the reference counter
|
||||
void addref();
|
||||
//! decrements the reference counter. If it reaches 0, delete_obj() is called
|
||||
void release();
|
||||
//! deletes the object. Override if needed
|
||||
void delete_obj();
|
||||
//! returns true iff obj==NULL
|
||||
bool empty() const;
|
||||
|
||||
//! cast pointer to another type
|
||||
template<typename _Tp2> Ptr<_Tp2> ptr();
|
||||
template<typename _Tp2> const Ptr<_Tp2> ptr() const;
|
||||
// Metafunction to avoid taking a reference to void.
|
||||
template<typename T>
|
||||
struct RefOrVoid { typedef T& type; };
|
||||
|
||||
//! helper operators making "Ptr<T> ptr" use very similar to "T* ptr".
|
||||
_Tp* operator -> ();
|
||||
const _Tp* operator -> () const;
|
||||
template<>
|
||||
struct RefOrVoid<void>{ typedef void type; };
|
||||
|
||||
operator _Tp* ();
|
||||
operator const _Tp*() const;
|
||||
template<>
|
||||
struct RefOrVoid<const void>{ typedef const void type; };
|
||||
|
||||
_Tp* obj; //< the object pointer.
|
||||
int* refcount; //< the associated reference counter
|
||||
template<>
|
||||
struct RefOrVoid<volatile void>{ typedef volatile void type; };
|
||||
|
||||
template<>
|
||||
struct RefOrVoid<const volatile void>{ typedef const volatile void type; };
|
||||
|
||||
// This class would be private to Ptr, if it didn't have to be a non-template.
|
||||
struct PtrOwner;
|
||||
|
||||
}
|
||||
|
||||
template<typename Y>
|
||||
struct DefaultDeleter
|
||||
{
|
||||
void operator () (Y* p) const;
|
||||
};
|
||||
|
||||
/*
|
||||
A smart shared pointer class with reference counting.
|
||||
|
||||
A Ptr<T> stores a pointer and owns a (potentially different) pointer.
|
||||
The stored pointer has type T and is the one returned by get() et al,
|
||||
while the owned pointer can have any type and is the one deleted
|
||||
when there are no more Ptrs that own it. You can't directly obtain the
|
||||
owned pointer.
|
||||
|
||||
The interface of this class is mostly a subset of that of C++11's
|
||||
std::shared_ptr.
|
||||
*/
|
||||
template<typename T>
|
||||
struct Ptr
|
||||
{
|
||||
/* Generic programming support. */
|
||||
typedef T element_type;
|
||||
|
||||
/* Ptr that owns NULL and stores NULL. */
|
||||
Ptr();
|
||||
|
||||
/* Ptr that owns p and stores p. The owned pointer will be deleted with
|
||||
DefaultDeleter<Y>. Y must be a complete type and Y* must be
|
||||
convertible to T*. */
|
||||
template<typename Y>
|
||||
explicit Ptr(Y* p);
|
||||
|
||||
/* Ptr that owns p and stores p. The owned pointer will be deleted by
|
||||
calling d(p). Y* must be convertible to T*. */
|
||||
template<typename Y, typename D>
|
||||
Ptr(Y* p, D d);
|
||||
|
||||
/* Same as the constructor below; it exists to suppress the generation
|
||||
of the implicit copy constructor. */
|
||||
Ptr(const Ptr& o);
|
||||
|
||||
/* Ptr that owns the same pointer as o and stores the same pointer as o,
|
||||
converted to T*. Naturally, Y* must be convertible to T*. */
|
||||
template<typename Y>
|
||||
Ptr(const Ptr<Y>& o);
|
||||
|
||||
/* Ptr that owns same pointer as o, and stores p. Useful for casts and
|
||||
creating non-owning Ptrs. */
|
||||
template<typename Y>
|
||||
Ptr(const Ptr<Y>& o, T* p);
|
||||
|
||||
/* Equivalent to release(). */
|
||||
~Ptr();
|
||||
|
||||
/* Same as assignment below; exists to suppress the generation of the
|
||||
implicit assignment operator. */
|
||||
Ptr& operator = (const Ptr& o);
|
||||
|
||||
template<typename Y>
|
||||
Ptr& operator = (const Ptr<Y>& o);
|
||||
|
||||
/* Resets both the owned and stored pointers to NULL. Deletes the owned
|
||||
pointer with the associated deleter if it's not owned by any other
|
||||
Ptr and is non-zero. It's called reset() in std::shared_ptr; here
|
||||
it is release() for compatibility with old OpenCV versions. */
|
||||
void release();
|
||||
|
||||
/* Equivalent to assigning from Ptr<T>(p). */
|
||||
template<typename Y>
|
||||
void reset(Y* p);
|
||||
|
||||
/* Equivalent to assigning from Ptr<T>(p, d). */
|
||||
template<typename Y, typename D>
|
||||
void reset(Y* p, D d);
|
||||
|
||||
/* Swaps the stored and owned pointers of this and o. */
|
||||
void swap(Ptr& o);
|
||||
|
||||
/* Returns the stored pointer. */
|
||||
T* get() const;
|
||||
|
||||
/* Ordinary pointer emulation. */
|
||||
typename detail::RefOrVoid<T>::type operator * () const;
|
||||
T* operator -> () const;
|
||||
|
||||
/* Equivalent to get(). */
|
||||
operator T* () const;
|
||||
|
||||
/* Equivalent to !*this. */
|
||||
bool empty() const;
|
||||
|
||||
/* Returns a Ptr that owns the same pointer as this, and stores the same
|
||||
pointer as this, except converted via static_cast to Y*. */
|
||||
template<typename Y>
|
||||
Ptr<Y> staticCast() const;
|
||||
|
||||
/* Ditto for const_cast. */
|
||||
template<typename Y>
|
||||
Ptr<Y> constCast() const;
|
||||
|
||||
/* Ditto for dynamic_cast. */
|
||||
template<typename Y>
|
||||
Ptr<Y> dynamicCast() const;
|
||||
|
||||
private:
|
||||
detail::PtrOwner* owner;
|
||||
T* stored;
|
||||
|
||||
template<typename Y>
|
||||
friend struct Ptr; // have to do this for the cross-type copy constructor
|
||||
};
|
||||
|
||||
/* Overload of the generic swap. */
|
||||
template<typename T>
|
||||
void swap(Ptr<T>& ptr1, Ptr<T>& ptr2);
|
||||
|
||||
/* Obvious comparisons. */
|
||||
template<typename T>
|
||||
bool operator == (const Ptr<T>& ptr1, const Ptr<T>& ptr2);
|
||||
template<typename T>
|
||||
bool operator != (const Ptr<T>& ptr1, const Ptr<T>& ptr2);
|
||||
|
||||
/* Convenience creation functions. In the far future, there may be variadic templates here. */
|
||||
template<typename T>
|
||||
Ptr<T> makePtr();
|
||||
template<typename T, typename A1>
|
||||
Ptr<T> makePtr(const A1& a1);
|
||||
template<typename T, typename A1, typename A2>
|
||||
Ptr<T> makePtr(const A1& a1, const A2& a2);
|
||||
template<typename T, typename A1, typename A2, typename A3>
|
||||
Ptr<T> makePtr(const A1& a1, const A2& a2, const A3& a3);
|
||||
template<typename T, typename A1, typename A2, typename A3, typename A4>
|
||||
Ptr<T> makePtr(const A1& a1, const A2& a2, const A3& a3, const A4& a4);
|
||||
template<typename T, typename A1, typename A2, typename A3, typename A4, typename A5>
|
||||
Ptr<T> makePtr(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5);
|
||||
template<typename T, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6>
|
||||
Ptr<T> makePtr(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6);
|
||||
template<typename T, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7>
|
||||
Ptr<T> makePtr(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7);
|
||||
template<typename T, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8>
|
||||
Ptr<T> makePtr(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8);
|
||||
template<typename T, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8, typename A9>
|
||||
Ptr<T> makePtr(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9);
|
||||
template<typename T, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8, typename A9, typename A10>
|
||||
Ptr<T> makePtr(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9, const A10& a10);
|
||||
|
||||
|
||||
//////////////////////////////// string class ////////////////////////////////
|
||||
@ -324,176 +431,6 @@ private:
|
||||
};
|
||||
|
||||
|
||||
|
||||
/////////////////////////// cv::Ptr implementation ///////////////////////////
|
||||
|
||||
template<typename _Tp> inline
|
||||
Ptr<_Tp>::Ptr()
|
||||
: obj(0), refcount(0) {}
|
||||
|
||||
template<typename _Tp> inline
|
||||
Ptr<_Tp>::Ptr(_Tp* _obj)
|
||||
: obj(_obj)
|
||||
{
|
||||
if(obj)
|
||||
{
|
||||
refcount = (int*)fastMalloc(sizeof(*refcount));
|
||||
*refcount = 1;
|
||||
}
|
||||
else
|
||||
refcount = 0;
|
||||
}
|
||||
|
||||
template<typename _Tp> template<typename _Tp2>
|
||||
Ptr<_Tp>::Ptr(const Ptr<_Tp2>& p)
|
||||
: obj(0), refcount(0)
|
||||
{
|
||||
if (p.empty())
|
||||
return;
|
||||
|
||||
_Tp* p_casted = dynamic_cast<_Tp*>(p.obj);
|
||||
if (!p_casted)
|
||||
return;
|
||||
|
||||
obj = p_casted;
|
||||
refcount = p.refcount;
|
||||
addref();
|
||||
}
|
||||
|
||||
template<typename _Tp> inline
|
||||
Ptr<_Tp>::~Ptr()
|
||||
{
|
||||
release();
|
||||
}
|
||||
|
||||
template<typename _Tp> inline
|
||||
void Ptr<_Tp>::addref()
|
||||
{
|
||||
if( refcount )
|
||||
CV_XADD(refcount, 1);
|
||||
}
|
||||
|
||||
template<typename _Tp> inline
|
||||
void Ptr<_Tp>::release()
|
||||
{
|
||||
if( refcount && CV_XADD(refcount, -1) == 1 )
|
||||
{
|
||||
delete_obj();
|
||||
fastFree(refcount);
|
||||
}
|
||||
refcount = 0;
|
||||
obj = 0;
|
||||
}
|
||||
|
||||
template<typename _Tp> inline
|
||||
void Ptr<_Tp>::delete_obj()
|
||||
{
|
||||
if( obj )
|
||||
delete obj;
|
||||
}
|
||||
|
||||
template<typename _Tp> inline
|
||||
Ptr<_Tp>::Ptr(const Ptr<_Tp>& _ptr)
|
||||
{
|
||||
obj = _ptr.obj;
|
||||
refcount = _ptr.refcount;
|
||||
addref();
|
||||
}
|
||||
|
||||
template<typename _Tp> inline
|
||||
Ptr<_Tp>& Ptr<_Tp>::operator = (const Ptr<_Tp>& _ptr)
|
||||
{
|
||||
int* _refcount = _ptr.refcount;
|
||||
if( _refcount )
|
||||
CV_XADD(_refcount, 1);
|
||||
release();
|
||||
obj = _ptr.obj;
|
||||
refcount = _refcount;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename _Tp> inline
|
||||
_Tp* Ptr<_Tp>::operator -> ()
|
||||
{
|
||||
return obj;
|
||||
}
|
||||
|
||||
template<typename _Tp> inline
|
||||
const _Tp* Ptr<_Tp>::operator -> () const
|
||||
{
|
||||
return obj;
|
||||
}
|
||||
|
||||
template<typename _Tp> inline
|
||||
Ptr<_Tp>::operator _Tp* ()
|
||||
{
|
||||
return obj;
|
||||
}
|
||||
|
||||
template<typename _Tp> inline
|
||||
Ptr<_Tp>::operator const _Tp*() const
|
||||
{
|
||||
return obj;
|
||||
}
|
||||
|
||||
template<typename _Tp> inline
|
||||
bool Ptr<_Tp>::empty() const
|
||||
{
|
||||
return obj == 0;
|
||||
}
|
||||
|
||||
template<typename _Tp> template<typename _Tp2> inline
|
||||
Ptr<_Tp2> Ptr<_Tp>::ptr()
|
||||
{
|
||||
Ptr<_Tp2> p;
|
||||
if( !obj )
|
||||
return p;
|
||||
|
||||
_Tp2* obj_casted = dynamic_cast<_Tp2*>(obj);
|
||||
if (!obj_casted)
|
||||
return p;
|
||||
|
||||
if( refcount )
|
||||
CV_XADD(refcount, 1);
|
||||
|
||||
p.obj = obj_casted;
|
||||
p.refcount = refcount;
|
||||
return p;
|
||||
}
|
||||
|
||||
template<typename _Tp> template<typename _Tp2> inline
|
||||
const Ptr<_Tp2> Ptr<_Tp>::ptr() const
|
||||
{
|
||||
Ptr<_Tp2> p;
|
||||
if( !obj )
|
||||
return p;
|
||||
|
||||
_Tp2* obj_casted = dynamic_cast<_Tp2*>(obj);
|
||||
if (!obj_casted)
|
||||
return p;
|
||||
|
||||
if( refcount )
|
||||
CV_XADD(refcount, 1);
|
||||
|
||||
p.obj = obj_casted;
|
||||
p.refcount = refcount;
|
||||
return p;
|
||||
}
|
||||
|
||||
template<class _Tp, class _Tp2> static inline
|
||||
bool operator == (const Ptr<_Tp>& a, const Ptr<_Tp2>& b)
|
||||
{
|
||||
return a.refcount == b.refcount;
|
||||
}
|
||||
|
||||
template<class _Tp, class _Tp2> static inline
|
||||
bool operator != (const Ptr<_Tp>& a, const Ptr<_Tp2>& b)
|
||||
{
|
||||
return a.refcount != b.refcount;
|
||||
}
|
||||
|
||||
|
||||
|
||||
////////////////////////// cv::String implementation /////////////////////////
|
||||
|
||||
inline
|
||||
@ -940,4 +877,6 @@ namespace cv
|
||||
}
|
||||
}
|
||||
|
||||
#include "opencv2/core/ptr.inl.hpp"
|
||||
|
||||
#endif //__OPENCV_CORE_CVSTD_HPP__
|
||||
|
@ -283,12 +283,6 @@ CV_EXPORTS void setGlDevice(int device = 0);
|
||||
|
||||
}}
|
||||
|
||||
namespace cv {
|
||||
|
||||
template <> CV_EXPORTS void Ptr<cv::ogl::Buffer::Impl>::delete_obj();
|
||||
template <> CV_EXPORTS void Ptr<cv::ogl::Texture2D::Impl>::delete_obj();
|
||||
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
@ -445,14 +445,14 @@ int print(const Matx<_Tp, m, n>& matx, FILE* stream = stdout)
|
||||
template<typename _Tp> inline
|
||||
Ptr<_Tp> Algorithm::create(const String& name)
|
||||
{
|
||||
return _create(name).ptr<_Tp>();
|
||||
return _create(name).dynamicCast<_Tp>();
|
||||
}
|
||||
|
||||
template<typename _Tp> inline
|
||||
void Algorithm::set(const char* _name, const Ptr<_Tp>& value)
|
||||
{
|
||||
Ptr<Algorithm> algo_ptr = value. template ptr<cv::Algorithm>();
|
||||
if (algo_ptr.empty()) {
|
||||
Ptr<Algorithm> algo_ptr = value. template dynamicCast<cv::Algorithm>();
|
||||
if (!algo_ptr) {
|
||||
CV_Error( Error::StsUnsupportedFormat, "unknown/unsupported Ptr type of the second parameter of the method Algorithm::set");
|
||||
}
|
||||
info()->set(this, _name, ParamType<Algorithm>::type, &algo_ptr);
|
||||
@ -468,7 +468,7 @@ template<typename _Tp> inline
|
||||
void Algorithm::setAlgorithm(const char* _name, const Ptr<_Tp>& value)
|
||||
{
|
||||
Ptr<Algorithm> algo_ptr = value. template ptr<cv::Algorithm>();
|
||||
if (algo_ptr.empty()) {
|
||||
if (!algo_ptr) {
|
||||
CV_Error( Error::StsUnsupportedFormat, "unknown/unsupported Ptr type of the second parameter of the method Algorithm::set");
|
||||
}
|
||||
info()->set(this, _name, ParamType<Algorithm>::type, &algo_ptr);
|
||||
|
@ -186,7 +186,7 @@ public:
|
||||
//! the full constructor that opens file storage for reading or writing
|
||||
CV_WRAP FileStorage(const String& source, int flags, const String& encoding=String());
|
||||
//! the constructor that takes pointer to the C FileStorage structure
|
||||
FileStorage(CvFileStorage* fs);
|
||||
FileStorage(CvFileStorage* fs, bool owning=true);
|
||||
//! the destructor. calls release()
|
||||
virtual ~FileStorage();
|
||||
|
||||
@ -209,9 +209,9 @@ public:
|
||||
CV_WRAP FileNode operator[](const char* nodename) const;
|
||||
|
||||
//! returns pointer to the underlying C FileStorage structure
|
||||
CvFileStorage* operator *() { return fs; }
|
||||
CvFileStorage* operator *() { return fs.get(); }
|
||||
//! returns pointer to the underlying C FileStorage structure
|
||||
const CvFileStorage* operator *() const { return fs; }
|
||||
const CvFileStorage* operator *() const { return fs.get(); }
|
||||
//! writes one or more numbers of the specified format to the currently written structure
|
||||
void writeRaw( const String& fmt, const uchar* vec, size_t len );
|
||||
//! writes the registered C structure (CvMat, CvMatND, CvSeq). See cvWrite()
|
||||
@ -226,7 +226,7 @@ public:
|
||||
int state; //!< the writer state
|
||||
};
|
||||
|
||||
template<> CV_EXPORTS void Ptr<CvFileStorage>::delete_obj();
|
||||
template<> CV_EXPORTS void DefaultDeleter<CvFileStorage>::operator ()(CvFileStorage* obj) const;
|
||||
|
||||
/*!
|
||||
File Storage Node class
|
||||
|
@ -128,12 +128,17 @@ namespace cv
|
||||
} //namespace cv
|
||||
|
||||
#define CV_INIT_ALGORITHM(classname, algname, memberinit) \
|
||||
static ::cv::Algorithm* create##classname##_hidden() \
|
||||
static inline ::cv::Algorithm* create##classname##_hidden() \
|
||||
{ \
|
||||
return new classname; \
|
||||
} \
|
||||
\
|
||||
static ::cv::AlgorithmInfo& classname##_info() \
|
||||
static inline ::cv::Ptr< ::cv::Algorithm> create##classname##_ptr_hidden() \
|
||||
{ \
|
||||
return ::cv::makePtr<classname>(); \
|
||||
} \
|
||||
\
|
||||
static inline ::cv::AlgorithmInfo& classname##_info() \
|
||||
{ \
|
||||
static ::cv::AlgorithmInfo classname##_info_var(algname, create##classname##_hidden); \
|
||||
return classname##_info_var; \
|
||||
|
338
modules/core/include/opencv2/core/ptr.inl.hpp
Normal file
338
modules/core/include/opencv2/core/ptr.inl.hpp
Normal file
@ -0,0 +1,338 @@
|
||||
/*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) 2013, NVIDIA 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 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 copyright holders 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*/
|
||||
|
||||
#ifndef __OPENCV_CORE_PTR_INL_HPP__
|
||||
#define __OPENCV_CORE_PTR_INL_HPP__
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace cv {
|
||||
|
||||
template<typename Y>
|
||||
void DefaultDeleter<Y>::operator () (Y* p) const
|
||||
{
|
||||
delete p;
|
||||
}
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
struct PtrOwner
|
||||
{
|
||||
PtrOwner() : refCount(1)
|
||||
{}
|
||||
|
||||
void incRef()
|
||||
{
|
||||
CV_XADD(&refCount, 1);
|
||||
}
|
||||
|
||||
void decRef()
|
||||
{
|
||||
if (CV_XADD(&refCount, -1) == 1) deleteSelf();
|
||||
}
|
||||
|
||||
protected:
|
||||
/* This doesn't really need to be virtual, since PtrOwner is never deleted
|
||||
directly, but it doesn't hurt and it helps avoid warnings. */
|
||||
virtual ~PtrOwner()
|
||||
{}
|
||||
|
||||
virtual void deleteSelf() = 0;
|
||||
|
||||
private:
|
||||
unsigned int refCount;
|
||||
|
||||
// noncopyable
|
||||
PtrOwner(const PtrOwner&);
|
||||
PtrOwner& operator = (const PtrOwner&);
|
||||
};
|
||||
|
||||
template<typename Y, typename D>
|
||||
struct PtrOwnerImpl : PtrOwner
|
||||
{
|
||||
PtrOwnerImpl(Y* p, D d) : owned(p), deleter(d)
|
||||
{}
|
||||
|
||||
void deleteSelf()
|
||||
{
|
||||
deleter(owned);
|
||||
delete this;
|
||||
}
|
||||
|
||||
private:
|
||||
Y* owned;
|
||||
D deleter;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
Ptr<T>::Ptr() : owner(NULL), stored(NULL)
|
||||
{}
|
||||
|
||||
template<typename T>
|
||||
template<typename Y>
|
||||
Ptr<T>::Ptr(Y* p)
|
||||
: owner(p
|
||||
? new detail::PtrOwnerImpl<Y, DefaultDeleter<Y> >(p, DefaultDeleter<Y>())
|
||||
: NULL),
|
||||
stored(p)
|
||||
{}
|
||||
|
||||
template<typename T>
|
||||
template<typename Y, typename D>
|
||||
Ptr<T>::Ptr(Y* p, D d)
|
||||
: owner(p
|
||||
? new detail::PtrOwnerImpl<Y, D>(p, d)
|
||||
: NULL),
|
||||
stored(p)
|
||||
{}
|
||||
|
||||
template<typename T>
|
||||
Ptr<T>::Ptr(const Ptr& o) : owner(o.owner), stored(o.stored)
|
||||
{
|
||||
if (owner) owner->incRef();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
template<typename Y>
|
||||
Ptr<T>::Ptr(const Ptr<Y>& o) : owner(o.owner), stored(o.stored)
|
||||
{
|
||||
if (owner) owner->incRef();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
template<typename Y>
|
||||
Ptr<T>::Ptr(const Ptr<Y>& o, T* p) : owner(o.owner), stored(p)
|
||||
{
|
||||
if (owner) owner->incRef();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
Ptr<T>::~Ptr()
|
||||
{
|
||||
release();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
Ptr<T>& Ptr<T>::operator = (const Ptr<T>& o)
|
||||
{
|
||||
Ptr(o).swap(*this);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
template<typename Y>
|
||||
Ptr<T>& Ptr<T>::operator = (const Ptr<Y>& o)
|
||||
{
|
||||
Ptr(o).swap(*this);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void Ptr<T>::release()
|
||||
{
|
||||
if (owner) owner->decRef();
|
||||
owner = NULL;
|
||||
stored = NULL;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
template<typename Y>
|
||||
void Ptr<T>::reset(Y* p)
|
||||
{
|
||||
Ptr(p).swap(*this);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
template<typename Y, typename D>
|
||||
void Ptr<T>::reset(Y* p, D d)
|
||||
{
|
||||
Ptr(p, d).swap(*this);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void Ptr<T>::swap(Ptr<T>& o)
|
||||
{
|
||||
std::swap(owner, o.owner);
|
||||
std::swap(stored, o.stored);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T* Ptr<T>::get() const
|
||||
{
|
||||
return stored;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
typename detail::RefOrVoid<T>::type Ptr<T>::operator * () const
|
||||
{
|
||||
return *stored;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T* Ptr<T>::operator -> () const
|
||||
{
|
||||
return stored;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
Ptr<T>::operator T* () const
|
||||
{
|
||||
return stored;
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
bool Ptr<T>::empty() const
|
||||
{
|
||||
return !stored;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
template<typename Y>
|
||||
Ptr<Y> Ptr<T>::staticCast() const
|
||||
{
|
||||
return Ptr<Y>(*this, static_cast<Y*>(stored));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
template<typename Y>
|
||||
Ptr<Y> Ptr<T>::constCast() const
|
||||
{
|
||||
return Ptr<Y>(*this, const_cast<Y*>(stored));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
template<typename Y>
|
||||
Ptr<Y> Ptr<T>::dynamicCast() const
|
||||
{
|
||||
return Ptr<Y>(*this, dynamic_cast<Y*>(stored));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void swap(Ptr<T>& ptr1, Ptr<T>& ptr2){
|
||||
ptr1.swap(ptr2);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool operator == (const Ptr<T>& ptr1, const Ptr<T>& ptr2)
|
||||
{
|
||||
return ptr1.get() == ptr2.get();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool operator != (const Ptr<T>& ptr1, const Ptr<T>& ptr2)
|
||||
{
|
||||
return ptr1.get() != ptr2.get();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
Ptr<T> makePtr()
|
||||
{
|
||||
return Ptr<T>(new T());
|
||||
}
|
||||
|
||||
template<typename T, typename A1>
|
||||
Ptr<T> makePtr(const A1& a1)
|
||||
{
|
||||
return Ptr<T>(new T(a1));
|
||||
}
|
||||
|
||||
template<typename T, typename A1, typename A2>
|
||||
Ptr<T> makePtr(const A1& a1, const A2& a2)
|
||||
{
|
||||
return Ptr<T>(new T(a1, a2));
|
||||
}
|
||||
|
||||
template<typename T, typename A1, typename A2, typename A3>
|
||||
Ptr<T> makePtr(const A1& a1, const A2& a2, const A3& a3)
|
||||
{
|
||||
return Ptr<T>(new T(a1, a2, a3));
|
||||
}
|
||||
|
||||
template<typename T, typename A1, typename A2, typename A3, typename A4>
|
||||
Ptr<T> makePtr(const A1& a1, const A2& a2, const A3& a3, const A4& a4)
|
||||
{
|
||||
return Ptr<T>(new T(a1, a2, a3, a4));
|
||||
}
|
||||
|
||||
template<typename T, typename A1, typename A2, typename A3, typename A4, typename A5>
|
||||
Ptr<T> makePtr(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5)
|
||||
{
|
||||
return Ptr<T>(new T(a1, a2, a3, a4, a5));
|
||||
}
|
||||
|
||||
template<typename T, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6>
|
||||
Ptr<T> makePtr(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6)
|
||||
{
|
||||
return Ptr<T>(new T(a1, a2, a3, a4, a5, a6));
|
||||
}
|
||||
|
||||
template<typename T, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7>
|
||||
Ptr<T> makePtr(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7)
|
||||
{
|
||||
return Ptr<T>(new T(a1, a2, a3, a4, a5, a6, a7));
|
||||
}
|
||||
|
||||
template<typename T, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8>
|
||||
Ptr<T> makePtr(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8)
|
||||
{
|
||||
return Ptr<T>(new T(a1, a2, a3, a4, a5, a6, a7, a8));
|
||||
}
|
||||
|
||||
template<typename T, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8, typename A9>
|
||||
Ptr<T> makePtr(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9)
|
||||
{
|
||||
return Ptr<T>(new T(a1, a2, a3, a4, a5, a6, a7, a8, a9));
|
||||
}
|
||||
|
||||
template<typename T, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8, typename A9, typename A10>
|
||||
Ptr<T> makePtr(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9, const A10& a10)
|
||||
{
|
||||
return Ptr<T>(new T(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10));
|
||||
}
|
||||
|
||||
} // namespace cv
|
||||
|
||||
#endif // __OPENCV_CORE_PTR_INL_HPP__
|
@ -551,18 +551,18 @@ public:
|
||||
size_t hash() const;
|
||||
|
||||
//! converts vector of keypoints to vector of points
|
||||
static void convert(const std::vector<KeyPoint>& keypoints,
|
||||
CV_WRAP static void convert(const std::vector<KeyPoint>& keypoints,
|
||||
CV_OUT std::vector<Point2f>& points2f,
|
||||
const std::vector<int>& keypointIndexes=std::vector<int>());
|
||||
//! converts vector of points to the vector of keypoints, where each keypoint is assigned the same size and the same orientation
|
||||
static void convert(const std::vector<Point2f>& points2f,
|
||||
CV_WRAP static void convert(const std::vector<Point2f>& points2f,
|
||||
CV_OUT std::vector<KeyPoint>& keypoints,
|
||||
float size=1, float response=1, int octave=0, int class_id=-1);
|
||||
|
||||
//! computes overlap for pair of keypoints;
|
||||
//! overlap is a ratio between area of keypoint regions intersection and
|
||||
//! area of keypoint regions union (now keypoint region is circle)
|
||||
static float overlap(const KeyPoint& kp1, const KeyPoint& kp2);
|
||||
CV_WRAP static float overlap(const KeyPoint& kp1, const KeyPoint& kp2);
|
||||
|
||||
CV_PROP_RW Point2f pt; //!< coordinates of the keypoints
|
||||
CV_PROP_RW float size; //!< diameter of the meaningful keypoint neighborhood
|
||||
|
@ -163,7 +163,7 @@ Ptr<Algorithm> Algorithm::_create(const String& name)
|
||||
Algorithm::Constructor c = 0;
|
||||
if( !alglist().find(name, c) )
|
||||
return Ptr<Algorithm>();
|
||||
return c();
|
||||
return Ptr<Algorithm>(c());
|
||||
}
|
||||
|
||||
Algorithm::Algorithm()
|
||||
@ -490,7 +490,7 @@ void AlgorithmInfo::read(Algorithm* algo, const FileNode& fn) const
|
||||
else if( p.type == Param::ALGORITHM )
|
||||
{
|
||||
Ptr<Algorithm> nestedAlgo = Algorithm::_create((String)n["name"]);
|
||||
CV_Assert( !nestedAlgo.empty() );
|
||||
CV_Assert( nestedAlgo );
|
||||
nestedAlgo->read(n);
|
||||
info->set(algo, pname.c_str(), p.type, &nestedAlgo, true);
|
||||
}
|
||||
|
@ -3190,22 +3190,22 @@ cvCheckTermCriteria( CvTermCriteria criteria, double default_eps,
|
||||
namespace cv
|
||||
{
|
||||
|
||||
template<> void Ptr<CvMat>::delete_obj()
|
||||
template<> void DefaultDeleter<CvMat>::operator ()(CvMat* obj) const
|
||||
{ cvReleaseMat(&obj); }
|
||||
|
||||
template<> void Ptr<IplImage>::delete_obj()
|
||||
template<> void DefaultDeleter<IplImage>::operator ()(IplImage* obj) const
|
||||
{ cvReleaseImage(&obj); }
|
||||
|
||||
template<> void Ptr<CvMatND>::delete_obj()
|
||||
template<> void DefaultDeleter<CvMatND>::operator ()(CvMatND* obj) const
|
||||
{ cvReleaseMatND(&obj); }
|
||||
|
||||
template<> void Ptr<CvSparseMat>::delete_obj()
|
||||
template<> void DefaultDeleter<CvSparseMat>::operator ()(CvSparseMat* obj) const
|
||||
{ cvReleaseSparseMat(&obj); }
|
||||
|
||||
template<> void Ptr<CvMemStorage>::delete_obj()
|
||||
template<> void DefaultDeleter<CvMemStorage>::operator ()(CvMemStorage* obj) const
|
||||
{ cvReleaseMemStorage(&obj); }
|
||||
|
||||
template<> void Ptr<CvFileStorage>::delete_obj()
|
||||
template<> void DefaultDeleter<CvFileStorage>::operator ()(CvFileStorage* obj) const
|
||||
{ cvReleaseFileStorage(&obj); }
|
||||
|
||||
}
|
||||
|
@ -100,7 +100,7 @@ cv::cuda::Stream::Stream()
|
||||
#ifndef HAVE_CUDA
|
||||
throw_no_cuda();
|
||||
#else
|
||||
impl_ = new Impl;
|
||||
impl_ = makePtr<Impl>();
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -182,7 +182,7 @@ void cv::cuda::Stream::enqueueHostCallback(StreamCallback callback, void* userDa
|
||||
|
||||
Stream& cv::cuda::Stream::Null()
|
||||
{
|
||||
static Stream s(new Impl(0));
|
||||
static Stream s(Ptr<Impl>(new Impl(0)));
|
||||
return s;
|
||||
}
|
||||
|
||||
@ -195,10 +195,6 @@ cv::cuda::Stream::operator bool_type() const
|
||||
#endif
|
||||
}
|
||||
|
||||
template <> void cv::Ptr<Stream::Impl>::delete_obj()
|
||||
{
|
||||
if (obj) delete obj;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
// Stream
|
||||
@ -249,7 +245,7 @@ cv::cuda::Event::Event(CreateFlags flags)
|
||||
(void) flags;
|
||||
throw_no_cuda();
|
||||
#else
|
||||
impl_ = new Impl(flags);
|
||||
impl_ = makePtr<Impl>(flags);
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -301,8 +297,3 @@ float cv::cuda::Event::elapsedTime(const Event& start, const Event& end)
|
||||
return ms;
|
||||
#endif
|
||||
}
|
||||
|
||||
template <> void cv::Ptr<Event::Impl>::delete_obj()
|
||||
{
|
||||
if (obj) delete obj;
|
||||
}
|
||||
|
@ -836,10 +836,6 @@ unsigned int cv::ogl::Buffer::bufId() const
|
||||
#endif
|
||||
}
|
||||
|
||||
template <> void cv::Ptr<cv::ogl::Buffer::Impl>::delete_obj()
|
||||
{
|
||||
if (obj) delete obj;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
// ogl::Texture
|
||||
@ -1243,10 +1239,6 @@ unsigned int cv::ogl::Texture2D::texId() const
|
||||
#endif
|
||||
}
|
||||
|
||||
template <> void cv::Ptr<cv::ogl::Texture2D::Impl>::delete_obj()
|
||||
{
|
||||
if (obj) delete obj;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// ogl::Arrays
|
||||
|
@ -256,7 +256,7 @@ namespace
|
||||
cv::Ptr<cv::Formatted> format(const cv::Mat& mtx) const
|
||||
{
|
||||
char braces[5] = {'\0', '\0', ';', '\0', '\0'};
|
||||
return new FormattedImpl("[", "]", mtx, braces,
|
||||
return cv::makePtr<FormattedImpl>("[", "]", mtx, &*braces,
|
||||
mtx.cols == 1 || !multiline, mtx.depth() == CV_64F ? prec64f : prec32f );
|
||||
}
|
||||
};
|
||||
@ -270,7 +270,7 @@ namespace
|
||||
char braces[5] = {'[', ']', '\0', '[', ']'};
|
||||
if (mtx.cols == 1)
|
||||
braces[0] = braces[1] = '\0';
|
||||
return new FormattedImpl("[", "]", mtx, braces,
|
||||
return cv::makePtr<FormattedImpl>("[", "]", mtx, &*braces,
|
||||
mtx.cols*mtx.channels() == 1 || !multiline, mtx.depth() == CV_64F ? prec64f : prec32f );
|
||||
}
|
||||
};
|
||||
@ -288,7 +288,8 @@ namespace
|
||||
char braces[5] = {'[', ']', '\0', '[', ']'};
|
||||
if (mtx.cols == 1)
|
||||
braces[0] = braces[1] = '\0';
|
||||
return new FormattedImpl("array([", cv::format("], type='%s')", numpyTypes[mtx.depth()]), mtx, braces,
|
||||
return cv::makePtr<FormattedImpl>("array([",
|
||||
cv::format("], type='%s')", numpyTypes[mtx.depth()]), mtx, &*braces,
|
||||
mtx.cols*mtx.channels() == 1 || !multiline, mtx.depth() == CV_64F ? prec64f : prec32f );
|
||||
}
|
||||
};
|
||||
@ -300,7 +301,8 @@ namespace
|
||||
cv::Ptr<cv::Formatted> format(const cv::Mat& mtx) const
|
||||
{
|
||||
char braces[5] = {'\0', '\0', '\0', '\0', '\0'};
|
||||
return new FormattedImpl(cv::String(), mtx.rows > 1 ? cv::String("\n") : cv::String(), mtx, braces,
|
||||
return cv::makePtr<FormattedImpl>(cv::String(),
|
||||
mtx.rows > 1 ? cv::String("\n") : cv::String(), mtx, &*braces,
|
||||
mtx.cols*mtx.channels() == 1 || !multiline, mtx.depth() == CV_64F ? prec64f : prec32f );
|
||||
}
|
||||
};
|
||||
@ -312,7 +314,7 @@ namespace
|
||||
cv::Ptr<cv::Formatted> format(const cv::Mat& mtx) const
|
||||
{
|
||||
char braces[5] = {'\0', '\0', ',', '\0', '\0'};
|
||||
return new FormattedImpl("{", "}", mtx, braces,
|
||||
return cv::makePtr<FormattedImpl>("{", "}", mtx, &*braces,
|
||||
mtx.cols == 1 || !multiline, mtx.depth() == CV_64F ? prec64f : prec32f );
|
||||
}
|
||||
};
|
||||
@ -330,16 +332,16 @@ namespace cv
|
||||
switch(fmt)
|
||||
{
|
||||
case FMT_MATLAB:
|
||||
return new MatlabFormatter();
|
||||
return makePtr<MatlabFormatter>();
|
||||
case FMT_CSV:
|
||||
return new CSVFormatter();
|
||||
return makePtr<CSVFormatter>();
|
||||
case FMT_PYTHON:
|
||||
return new PythonFormatter();
|
||||
return makePtr<PythonFormatter>();
|
||||
case FMT_NUMPY:
|
||||
return new NumpyFormatter();
|
||||
return makePtr<NumpyFormatter>();
|
||||
case FMT_C:
|
||||
return new CFormatter();
|
||||
return makePtr<CFormatter>();
|
||||
}
|
||||
return new MatlabFormatter();
|
||||
return makePtr<MatlabFormatter>();
|
||||
}
|
||||
} // cv
|
||||
|
@ -5129,9 +5129,11 @@ FileStorage::FileStorage(const String& filename, int flags, const String& encodi
|
||||
open( filename, flags, encoding );
|
||||
}
|
||||
|
||||
FileStorage::FileStorage(CvFileStorage* _fs)
|
||||
FileStorage::FileStorage(CvFileStorage* _fs, bool owning)
|
||||
{
|
||||
fs = Ptr<CvFileStorage>(_fs);
|
||||
if (owning) fs.reset(_fs);
|
||||
else fs = Ptr<CvFileStorage>(Ptr<CvFileStorage>(), _fs);
|
||||
|
||||
state = _fs ? NAME_EXPECTED + INSIDE_MAP : UNDEFINED;
|
||||
}
|
||||
|
||||
@ -5147,7 +5149,7 @@ FileStorage::~FileStorage()
|
||||
bool FileStorage::open(const String& filename, int flags, const String& encoding)
|
||||
{
|
||||
release();
|
||||
fs = Ptr<CvFileStorage>(cvOpenFileStorage( filename.c_str(), 0, flags,
|
||||
fs.reset(cvOpenFileStorage( filename.c_str(), 0, flags,
|
||||
!encoding.empty() ? encoding.c_str() : 0));
|
||||
bool ok = isOpened();
|
||||
state = ok ? NAME_EXPECTED + INSIDE_MAP : UNDEFINED;
|
||||
@ -5156,7 +5158,7 @@ bool FileStorage::open(const String& filename, int flags, const String& encoding
|
||||
|
||||
bool FileStorage::isOpened() const
|
||||
{
|
||||
return !fs.empty() && fs.obj->is_opened;
|
||||
return fs && fs->is_opened;
|
||||
}
|
||||
|
||||
void FileStorage::release()
|
||||
@ -5169,8 +5171,8 @@ void FileStorage::release()
|
||||
String FileStorage::releaseAndGetString()
|
||||
{
|
||||
String buf;
|
||||
if( fs.obj && fs.obj->outbuf )
|
||||
icvClose(fs.obj, &buf);
|
||||
if( fs && fs->outbuf )
|
||||
icvClose(fs, &buf);
|
||||
|
||||
release();
|
||||
return buf;
|
||||
@ -5479,7 +5481,7 @@ void write( FileStorage& fs, const String& name, const Mat& value )
|
||||
// TODO: the 4 functions below need to be implemented more efficiently
|
||||
void write( FileStorage& fs, const String& name, const SparseMat& value )
|
||||
{
|
||||
Ptr<CvSparseMat> mat = cvCreateSparseMat(value);
|
||||
Ptr<CvSparseMat> mat(cvCreateSparseMat(value));
|
||||
cvWrite( *fs, name.size() ? name.c_str() : 0, mat );
|
||||
}
|
||||
|
||||
@ -5529,8 +5531,8 @@ void read( const FileNode& node, SparseMat& mat, const SparseMat& default_mat )
|
||||
default_mat.copyTo(mat);
|
||||
return;
|
||||
}
|
||||
Ptr<CvSparseMat> m = (CvSparseMat*)cvRead((CvFileStorage*)node.fs, (CvFileNode*)*node);
|
||||
CV_Assert(CV_IS_SPARSE_MAT(m.obj));
|
||||
Ptr<CvSparseMat> m((CvSparseMat*)cvRead((CvFileStorage*)node.fs, (CvFileNode*)*node));
|
||||
CV_Assert(CV_IS_SPARSE_MAT(m));
|
||||
m->copyToSparseMat(mat);
|
||||
}
|
||||
|
||||
|
@ -358,8 +358,6 @@ Core_DynStructBaseTest::Core_DynStructBaseTest()
|
||||
iterations = max_struct_size*2;
|
||||
gen = struct_idx = iter = -1;
|
||||
test_progress = -1;
|
||||
|
||||
storage = 0;
|
||||
}
|
||||
|
||||
|
||||
@ -999,7 +997,7 @@ void Core_SeqBaseTest::run( int )
|
||||
{
|
||||
t = cvtest::randReal(rng)*(max_log_storage_block_size - min_log_storage_block_size)
|
||||
+ min_log_storage_block_size;
|
||||
storage = cvCreateMemStorage( cvRound( exp(t * CV_LOG2) ) );
|
||||
storage.reset(cvCreateMemStorage( cvRound( exp(t * CV_LOG2) ) ));
|
||||
}
|
||||
|
||||
iter = struct_idx = -1;
|
||||
@ -1083,11 +1081,11 @@ void Core_SeqSortInvTest::run( int )
|
||||
{
|
||||
struct_idx = iter = -1;
|
||||
|
||||
if( storage.empty() )
|
||||
if( !storage )
|
||||
{
|
||||
t = cvtest::randReal(rng)*(max_log_storage_block_size - min_log_storage_block_size)
|
||||
+ min_log_storage_block_size;
|
||||
storage = cvCreateMemStorage( cvRound( exp(t * CV_LOG2) ) );
|
||||
storage.reset(cvCreateMemStorage( cvRound( exp(t * CV_LOG2) ) ));
|
||||
}
|
||||
|
||||
for( iter = 0; iter < iterations/10; iter++ )
|
||||
@ -1384,7 +1382,7 @@ void Core_SetTest::run( int )
|
||||
{
|
||||
struct_idx = iter = -1;
|
||||
t = cvtest::randReal(rng)*(max_log_storage_block_size - min_log_storage_block_size) + min_log_storage_block_size;
|
||||
storage = cvCreateMemStorage( cvRound( exp(t * CV_LOG2) ) );
|
||||
storage.reset(cvCreateMemStorage( cvRound( exp(t * CV_LOG2) ) ));
|
||||
|
||||
for( int i = 0; i < struct_count; i++ )
|
||||
{
|
||||
@ -1811,7 +1809,7 @@ void Core_GraphTest::run( int )
|
||||
int block_size = cvRound( exp(t * CV_LOG2) );
|
||||
block_size = MAX(block_size, (int)(sizeof(CvGraph) + sizeof(CvMemBlock) + sizeof(CvSeqBlock)));
|
||||
|
||||
storage = cvCreateMemStorage(block_size);
|
||||
storage.reset(cvCreateMemStorage(block_size));
|
||||
|
||||
for( i = 0; i < struct_count; i++ )
|
||||
{
|
||||
@ -1929,7 +1927,7 @@ void Core_GraphScanTest::run( int )
|
||||
storage_blocksize = MAX(storage_blocksize, (int)(sizeof(CvGraph) + sizeof(CvMemBlock) + sizeof(CvSeqBlock)));
|
||||
storage_blocksize = MAX(storage_blocksize, (int)(sizeof(CvGraphEdge) + sizeof(CvMemBlock) + sizeof(CvSeqBlock)));
|
||||
storage_blocksize = MAX(storage_blocksize, (int)(sizeof(CvGraphVtx) + sizeof(CvMemBlock) + sizeof(CvSeqBlock)));
|
||||
storage = cvCreateMemStorage(storage_blocksize);
|
||||
storage.reset(cvCreateMemStorage(storage_blocksize));
|
||||
|
||||
if( gen == 0 )
|
||||
{
|
||||
|
@ -270,16 +270,16 @@ protected:
|
||||
|
||||
cvRelease((void**)&m_nd);
|
||||
|
||||
Ptr<CvSparseMat> m_s = (CvSparseMat*)fs["test_sparse_mat"].readObj();
|
||||
Ptr<CvSparseMat> _test_sparse_ = cvCreateSparseMat(test_sparse_mat);
|
||||
Ptr<CvSparseMat> _test_sparse = (CvSparseMat*)cvClone(_test_sparse_);
|
||||
Ptr<CvSparseMat> m_s((CvSparseMat*)fs["test_sparse_mat"].readObj());
|
||||
Ptr<CvSparseMat> _test_sparse_(cvCreateSparseMat(test_sparse_mat));
|
||||
Ptr<CvSparseMat> _test_sparse((CvSparseMat*)cvClone(_test_sparse_));
|
||||
SparseMat m_s2;
|
||||
fs["test_sparse_mat"] >> m_s2;
|
||||
Ptr<CvSparseMat> _m_s2 = cvCreateSparseMat(m_s2);
|
||||
Ptr<CvSparseMat> _m_s2(cvCreateSparseMat(m_s2));
|
||||
|
||||
if( !m_s || !CV_IS_SPARSE_MAT(m_s) ||
|
||||
!cvTsCheckSparse(m_s, _test_sparse,0) ||
|
||||
!cvTsCheckSparse(_m_s2, _test_sparse,0))
|
||||
!cvTsCheckSparse(m_s, _test_sparse, 0) ||
|
||||
!cvTsCheckSparse(_m_s2, _test_sparse, 0))
|
||||
{
|
||||
ts->printf( cvtest::TS::LOG, "the read sparse matrix is not correct\n" );
|
||||
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_OUTPUT );
|
||||
|
@ -669,7 +669,7 @@ void Core_ArrayOpTest::run( int /* start_from */)
|
||||
cvSetReal3D(&matA, idx1[0], idx1[1], idx1[2], -val0);
|
||||
cvSetND(&matB, idx0, val1);
|
||||
cvSet3D(&matB, idx1[0], idx1[1], idx1[2], -val1);
|
||||
Ptr<CvMatND> matC = cvCloneMatND(&matB);
|
||||
Ptr<CvMatND> matC(cvCloneMatND(&matB));
|
||||
|
||||
if( A.at<float>(idx0[0], idx0[1], idx0[2]) != val0 ||
|
||||
A.at<float>(idx1[0], idx1[1], idx1[2]) != -val0 ||
|
||||
@ -762,7 +762,7 @@ void Core_ArrayOpTest::run( int /* start_from */)
|
||||
}
|
||||
}
|
||||
|
||||
Ptr<CvSparseMat> M2 = cvCreateSparseMat(M);
|
||||
Ptr<CvSparseMat> M2(cvCreateSparseMat(M));
|
||||
MatND Md;
|
||||
M.copyTo(Md);
|
||||
SparseMat M3; SparseMat(Md).convertTo(M3, Md.type(), 2);
|
||||
|
389
modules/core/test/test_ptr.cpp
Normal file
389
modules/core/test/test_ptr.cpp
Normal file
@ -0,0 +1,389 @@
|
||||
/*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) 2013, NVIDIA 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 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 copyright holders 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"
|
||||
|
||||
using namespace cv;
|
||||
|
||||
namespace {
|
||||
|
||||
struct Reporter {
|
||||
Reporter(bool* deleted) : deleted_(deleted)
|
||||
{ *deleted_ = false; }
|
||||
|
||||
// the destructor is virtual, so that we can test dynamic_cast later
|
||||
virtual ~Reporter()
|
||||
{ *deleted_ = true; }
|
||||
|
||||
private:
|
||||
bool* deleted_;
|
||||
|
||||
Reporter(const Reporter&);
|
||||
Reporter& operator = (const Reporter&);
|
||||
};
|
||||
|
||||
struct ReportingDeleter {
|
||||
ReportingDeleter(bool* deleted) : deleted_(deleted)
|
||||
{ *deleted_ = false; }
|
||||
|
||||
void operator()(void*)
|
||||
{ *deleted_ = true; }
|
||||
|
||||
private:
|
||||
bool* deleted_;
|
||||
};
|
||||
|
||||
int dummyObject;
|
||||
|
||||
}
|
||||
|
||||
TEST(Core_Ptr, default_ctor)
|
||||
{
|
||||
Ptr<int> p;
|
||||
EXPECT_EQ(NULL, p.get());
|
||||
}
|
||||
|
||||
TEST(Core_Ptr, owning_ctor)
|
||||
{
|
||||
bool deleted = false;
|
||||
|
||||
{
|
||||
Reporter* r = new Reporter(&deleted);
|
||||
Ptr<void> p(r);
|
||||
EXPECT_EQ(r, p.get());
|
||||
}
|
||||
|
||||
EXPECT_TRUE(deleted);
|
||||
|
||||
{
|
||||
Ptr<int> p(&dummyObject, ReportingDeleter(&deleted));
|
||||
EXPECT_EQ(&dummyObject, p.get());
|
||||
}
|
||||
|
||||
EXPECT_TRUE(deleted);
|
||||
|
||||
{
|
||||
Ptr<void> p((void*)0, ReportingDeleter(&deleted));
|
||||
EXPECT_EQ(NULL, p.get());
|
||||
}
|
||||
|
||||
EXPECT_FALSE(deleted);
|
||||
}
|
||||
|
||||
TEST(Core_Ptr, sharing_ctor)
|
||||
{
|
||||
bool deleted = false;
|
||||
|
||||
{
|
||||
Ptr<Reporter> p1(new Reporter(&deleted));
|
||||
Ptr<Reporter> p2(p1);
|
||||
EXPECT_EQ(p1.get(), p2.get());
|
||||
p1.release();
|
||||
EXPECT_FALSE(deleted);
|
||||
}
|
||||
|
||||
EXPECT_TRUE(deleted);
|
||||
|
||||
{
|
||||
Ptr<Reporter> p1(new Reporter(&deleted));
|
||||
Ptr<void> p2(p1);
|
||||
EXPECT_EQ(p1.get(), p2.get());
|
||||
p1.release();
|
||||
EXPECT_FALSE(deleted);
|
||||
}
|
||||
|
||||
EXPECT_TRUE(deleted);
|
||||
|
||||
{
|
||||
Ptr<Reporter> p1(new Reporter(&deleted));
|
||||
Ptr<int> p2(p1, &dummyObject);
|
||||
EXPECT_EQ(&dummyObject, p2.get());
|
||||
p1.release();
|
||||
EXPECT_FALSE(deleted);
|
||||
}
|
||||
|
||||
EXPECT_TRUE(deleted);
|
||||
}
|
||||
|
||||
TEST(Core_Ptr, assignment)
|
||||
{
|
||||
bool deleted1 = false, deleted2 = false;
|
||||
|
||||
{
|
||||
Ptr<Reporter> p1(new Reporter(&deleted1));
|
||||
p1 = p1;
|
||||
EXPECT_FALSE(deleted1);
|
||||
}
|
||||
|
||||
EXPECT_TRUE(deleted1);
|
||||
|
||||
{
|
||||
Ptr<Reporter> p1(new Reporter(&deleted1));
|
||||
Ptr<Reporter> p2(new Reporter(&deleted2));
|
||||
p2 = p1;
|
||||
EXPECT_TRUE(deleted2);
|
||||
EXPECT_EQ(p1.get(), p2.get());
|
||||
p1.release();
|
||||
EXPECT_FALSE(deleted1);
|
||||
}
|
||||
|
||||
EXPECT_TRUE(deleted1);
|
||||
|
||||
{
|
||||
Ptr<Reporter> p1(new Reporter(&deleted1));
|
||||
Ptr<void> p2(new Reporter(&deleted2));
|
||||
p2 = p1;
|
||||
EXPECT_TRUE(deleted2);
|
||||
EXPECT_EQ(p1.get(), p2.get());
|
||||
p1.release();
|
||||
EXPECT_FALSE(deleted1);
|
||||
}
|
||||
|
||||
EXPECT_TRUE(deleted1);
|
||||
}
|
||||
|
||||
TEST(Core_Ptr, release)
|
||||
{
|
||||
bool deleted = false;
|
||||
|
||||
Ptr<Reporter> p1(new Reporter(&deleted));
|
||||
p1.release();
|
||||
EXPECT_TRUE(deleted);
|
||||
EXPECT_EQ(NULL, p1.get());
|
||||
}
|
||||
|
||||
TEST(Core_Ptr, reset)
|
||||
{
|
||||
bool deleted_old = false, deleted_new = false;
|
||||
|
||||
{
|
||||
Ptr<void> p(new Reporter(&deleted_old));
|
||||
Reporter* r = new Reporter(&deleted_new);
|
||||
p.reset(r);
|
||||
EXPECT_TRUE(deleted_old);
|
||||
EXPECT_EQ(r, p.get());
|
||||
}
|
||||
|
||||
EXPECT_TRUE(deleted_new);
|
||||
|
||||
{
|
||||
Ptr<void> p(new Reporter(&deleted_old));
|
||||
p.reset(&dummyObject, ReportingDeleter(&deleted_new));
|
||||
EXPECT_TRUE(deleted_old);
|
||||
EXPECT_EQ(&dummyObject, p.get());
|
||||
}
|
||||
|
||||
EXPECT_TRUE(deleted_new);
|
||||
}
|
||||
|
||||
TEST(Core_Ptr, swap)
|
||||
{
|
||||
bool deleted1 = false, deleted2 = false;
|
||||
|
||||
{
|
||||
Reporter* r1 = new Reporter(&deleted1);
|
||||
Reporter* r2 = new Reporter(&deleted2);
|
||||
Ptr<Reporter> p1(r1), p2(r2);
|
||||
p1.swap(p2);
|
||||
EXPECT_EQ(r1, p2.get());
|
||||
EXPECT_EQ(r2, p1.get());
|
||||
EXPECT_FALSE(deleted1);
|
||||
EXPECT_FALSE(deleted2);
|
||||
p1.release();
|
||||
EXPECT_TRUE(deleted2);
|
||||
}
|
||||
|
||||
EXPECT_TRUE(deleted1);
|
||||
|
||||
{
|
||||
Reporter* r1 = new Reporter(&deleted1);
|
||||
Reporter* r2 = new Reporter(&deleted2);
|
||||
Ptr<Reporter> p1(r1), p2(r2);
|
||||
swap(p1, p2);
|
||||
EXPECT_EQ(r1, p2.get());
|
||||
EXPECT_EQ(r2, p1.get());
|
||||
EXPECT_FALSE(deleted1);
|
||||
EXPECT_FALSE(deleted2);
|
||||
p1.release();
|
||||
EXPECT_TRUE(deleted2);
|
||||
}
|
||||
|
||||
EXPECT_TRUE(deleted1);
|
||||
}
|
||||
|
||||
TEST(Core_Ptr, accessors)
|
||||
{
|
||||
{
|
||||
Ptr<int> p;
|
||||
EXPECT_EQ(NULL, static_cast<int*>(p));
|
||||
EXPECT_TRUE(p.empty());
|
||||
}
|
||||
|
||||
{
|
||||
Size* s = new Size();
|
||||
Ptr<Size> p(s);
|
||||
EXPECT_EQ(s, static_cast<Size*>(p));
|
||||
EXPECT_EQ(s, &*p);
|
||||
EXPECT_EQ(&s->width, &p->width);
|
||||
EXPECT_FALSE(p.empty());
|
||||
}
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
struct SubReporterBase {
|
||||
virtual ~SubReporterBase() {}
|
||||
int padding;
|
||||
};
|
||||
|
||||
/* multiple inheritance, so that casts do something interesting */
|
||||
struct SubReporter : SubReporterBase, Reporter
|
||||
{
|
||||
SubReporter(bool* deleted) : Reporter(deleted)
|
||||
{}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
TEST(Core_Ptr, casts)
|
||||
{
|
||||
bool deleted = false;
|
||||
|
||||
{
|
||||
Ptr<const Reporter> p1(new Reporter(&deleted));
|
||||
Ptr<Reporter> p2 = p1.constCast<Reporter>();
|
||||
EXPECT_EQ(p1.get(), p2.get());
|
||||
p1.release();
|
||||
EXPECT_FALSE(deleted);
|
||||
}
|
||||
|
||||
EXPECT_TRUE(deleted);
|
||||
|
||||
{
|
||||
SubReporter* sr = new SubReporter(&deleted);
|
||||
Ptr<Reporter> p1(sr);
|
||||
// This next check isn't really for Ptr itself; it checks that Reporter
|
||||
// is at a non-zero offset within SubReporter, so that the next
|
||||
// check will give us more confidence that the cast actually did something.
|
||||
EXPECT_NE(static_cast<void*>(sr), static_cast<void*>(p1.get()));
|
||||
Ptr<SubReporter> p2 = p1.staticCast<SubReporter>();
|
||||
EXPECT_EQ(sr, p2.get());
|
||||
p1.release();
|
||||
EXPECT_FALSE(deleted);
|
||||
}
|
||||
|
||||
EXPECT_TRUE(deleted);
|
||||
|
||||
{
|
||||
SubReporter* sr = new SubReporter(&deleted);
|
||||
Ptr<Reporter> p1(sr);
|
||||
EXPECT_NE(static_cast<void*>(sr), static_cast<void*>(p1.get()));
|
||||
Ptr<void> p2 = p1.dynamicCast<void>();
|
||||
EXPECT_EQ(sr, p2.get());
|
||||
p1.release();
|
||||
EXPECT_FALSE(deleted);
|
||||
}
|
||||
|
||||
EXPECT_TRUE(deleted);
|
||||
|
||||
{
|
||||
Ptr<Reporter> p1(new Reporter(&deleted));
|
||||
Ptr<SubReporter> p2 = p1.dynamicCast<SubReporter>();
|
||||
EXPECT_EQ(NULL, p2.get());
|
||||
p1.release();
|
||||
EXPECT_FALSE(deleted);
|
||||
}
|
||||
|
||||
EXPECT_TRUE(deleted);
|
||||
}
|
||||
|
||||
TEST(Core_Ptr, comparisons)
|
||||
{
|
||||
Ptr<int> p1, p2(new int), p3(new int);
|
||||
Ptr<int> p4(p2, p3.get());
|
||||
|
||||
// Not using EXPECT_EQ here, since none of them are really "expected" or "actual".
|
||||
EXPECT_TRUE(p1 == p1);
|
||||
EXPECT_TRUE(p2 == p2);
|
||||
EXPECT_TRUE(p2 != p3);
|
||||
EXPECT_TRUE(p2 != p4);
|
||||
EXPECT_TRUE(p3 == p4);
|
||||
}
|
||||
|
||||
TEST(Core_Ptr, make)
|
||||
{
|
||||
bool deleted = true;
|
||||
|
||||
{
|
||||
Ptr<void> p = makePtr<Reporter>(&deleted);
|
||||
EXPECT_FALSE(deleted);
|
||||
}
|
||||
|
||||
EXPECT_TRUE(deleted);
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
struct SpeciallyDeletable
|
||||
{
|
||||
SpeciallyDeletable() : deleted(false)
|
||||
{}
|
||||
bool deleted;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
namespace cv {
|
||||
|
||||
template<>
|
||||
void DefaultDeleter<SpeciallyDeletable>::operator()(SpeciallyDeletable * obj) const
|
||||
{ obj->deleted = true; }
|
||||
|
||||
}
|
||||
|
||||
TEST(Core_Ptr, specialized_deleter)
|
||||
{
|
||||
SpeciallyDeletable sd;
|
||||
|
||||
{ Ptr<void> p(&sd); }
|
||||
|
||||
ASSERT_TRUE(sd.deleted);
|
||||
}
|
@ -207,8 +207,8 @@ private:
|
||||
ncvAssertCUDAReturn(cudaGetDeviceProperties(&devProp, devId), NCV_CUDA_ERROR);
|
||||
|
||||
// Load the classifier from file (assuming its size is about 1 mb) using a simple allocator
|
||||
gpuCascadeAllocator = new NCVMemNativeAllocator(NCVMemoryTypeDevice, static_cast<int>(devProp.textureAlignment));
|
||||
cpuCascadeAllocator = new NCVMemNativeAllocator(NCVMemoryTypeHostPinned, static_cast<int>(devProp.textureAlignment));
|
||||
gpuCascadeAllocator = makePtr<NCVMemNativeAllocator>(NCVMemoryTypeDevice, static_cast<int>(devProp.textureAlignment));
|
||||
cpuCascadeAllocator = makePtr<NCVMemNativeAllocator>(NCVMemoryTypeHostPinned, static_cast<int>(devProp.textureAlignment));
|
||||
|
||||
ncvAssertPrintReturn(gpuCascadeAllocator->isInitialized(), "Error creating cascade GPU allocator", NCV_CUDA_ERROR);
|
||||
ncvAssertPrintReturn(cpuCascadeAllocator->isInitialized(), "Error creating cascade CPU allocator", NCV_CUDA_ERROR);
|
||||
@ -217,9 +217,9 @@ private:
|
||||
ncvStat = ncvHaarGetClassifierSize(classifierFile, haarNumStages, haarNumNodes, haarNumFeatures);
|
||||
ncvAssertPrintReturn(ncvStat == NCV_SUCCESS, "Error reading classifier size (check the file)", NCV_FILE_ERROR);
|
||||
|
||||
h_haarStages = new NCVVectorAlloc<HaarStage64>(*cpuCascadeAllocator, haarNumStages);
|
||||
h_haarNodes = new NCVVectorAlloc<HaarClassifierNode128>(*cpuCascadeAllocator, haarNumNodes);
|
||||
h_haarFeatures = new NCVVectorAlloc<HaarFeature64>(*cpuCascadeAllocator, haarNumFeatures);
|
||||
h_haarStages.reset (new NCVVectorAlloc<HaarStage64>(*cpuCascadeAllocator, haarNumStages));
|
||||
h_haarNodes.reset (new NCVVectorAlloc<HaarClassifierNode128>(*cpuCascadeAllocator, haarNumNodes));
|
||||
h_haarFeatures.reset(new NCVVectorAlloc<HaarFeature64>(*cpuCascadeAllocator, haarNumFeatures));
|
||||
|
||||
ncvAssertPrintReturn(h_haarStages->isMemAllocated(), "Error in cascade CPU allocator", NCV_CUDA_ERROR);
|
||||
ncvAssertPrintReturn(h_haarNodes->isMemAllocated(), "Error in cascade CPU allocator", NCV_CUDA_ERROR);
|
||||
@ -228,9 +228,9 @@ private:
|
||||
ncvStat = ncvHaarLoadFromFile_host(classifierFile, haar, *h_haarStages, *h_haarNodes, *h_haarFeatures);
|
||||
ncvAssertPrintReturn(ncvStat == NCV_SUCCESS, "Error loading classifier", NCV_FILE_ERROR);
|
||||
|
||||
d_haarStages = new NCVVectorAlloc<HaarStage64>(*gpuCascadeAllocator, haarNumStages);
|
||||
d_haarNodes = new NCVVectorAlloc<HaarClassifierNode128>(*gpuCascadeAllocator, haarNumNodes);
|
||||
d_haarFeatures = new NCVVectorAlloc<HaarFeature64>(*gpuCascadeAllocator, haarNumFeatures);
|
||||
d_haarStages.reset (new NCVVectorAlloc<HaarStage64>(*gpuCascadeAllocator, haarNumStages));
|
||||
d_haarNodes.reset (new NCVVectorAlloc<HaarClassifierNode128>(*gpuCascadeAllocator, haarNumNodes));
|
||||
d_haarFeatures.reset(new NCVVectorAlloc<HaarFeature64>(*gpuCascadeAllocator, haarNumFeatures));
|
||||
|
||||
ncvAssertPrintReturn(d_haarStages->isMemAllocated(), "Error in cascade GPU allocator", NCV_CUDA_ERROR);
|
||||
ncvAssertPrintReturn(d_haarNodes->isMemAllocated(), "Error in cascade GPU allocator", NCV_CUDA_ERROR);
|
||||
@ -279,8 +279,8 @@ private:
|
||||
ncvAssertReturnNcvStat(ncvStat);
|
||||
ncvAssertCUDAReturn(cudaStreamSynchronize(0), NCV_CUDA_ERROR);
|
||||
|
||||
gpuAllocator = new NCVMemStackAllocator(NCVMemoryTypeDevice, gpuCounter.maxSize(), static_cast<int>(devProp.textureAlignment));
|
||||
cpuAllocator = new NCVMemStackAllocator(NCVMemoryTypeHostPinned, cpuCounter.maxSize(), static_cast<int>(devProp.textureAlignment));
|
||||
gpuAllocator = makePtr<NCVMemStackAllocator>(NCVMemoryTypeDevice, gpuCounter.maxSize(), static_cast<int>(devProp.textureAlignment));
|
||||
cpuAllocator = makePtr<NCVMemStackAllocator>(NCVMemoryTypeHostPinned, cpuCounter.maxSize(), static_cast<int>(devProp.textureAlignment));
|
||||
|
||||
ncvAssertPrintReturn(gpuAllocator->isInitialized(), "Error creating GPU memory allocator", NCV_CUDA_ERROR);
|
||||
ncvAssertPrintReturn(cpuAllocator->isInitialized(), "Error creating CPU memory allocator", NCV_CUDA_ERROR);
|
||||
|
@ -629,7 +629,7 @@ Ptr<Convolution> cv::cuda::createConvolution(Size user_block_size)
|
||||
CV_Error(Error::StsNotImplemented, "The library was build without CUFFT");
|
||||
return Ptr<Convolution>();
|
||||
#else
|
||||
return new ConvolutionImpl(user_block_size);
|
||||
return makePtr<ConvolutionImpl>(user_block_size);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -497,7 +497,7 @@ namespace
|
||||
|
||||
Ptr<LookUpTable> cv::cuda::createLookUpTable(InputArray lut)
|
||||
{
|
||||
return new LookUpTableImpl(lut);
|
||||
return makePtr<LookUpTableImpl>(lut);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
@ -76,7 +76,7 @@ using namespace perf;
|
||||
|
||||
namespace cv
|
||||
{
|
||||
template<> void Ptr<CvBGStatModel>::delete_obj()
|
||||
template<> void DefaultDeleter<CvBGStatModel>::operator ()(CvBGStatModel* obj) const
|
||||
{
|
||||
cvReleaseBGStatModel(&obj);
|
||||
}
|
||||
|
@ -725,7 +725,7 @@ namespace
|
||||
|
||||
Ptr<cuda::BackgroundSubtractorFGD> cv::cuda::createBackgroundSubtractorFGD(const FGDParams& params)
|
||||
{
|
||||
return new FGDImpl(params);
|
||||
return makePtr<FGDImpl>(params);
|
||||
}
|
||||
|
||||
#endif // HAVE_CUDA
|
||||
|
@ -271,7 +271,7 @@ namespace
|
||||
|
||||
Ptr<cuda::BackgroundSubtractorGMG> cv::cuda::createBackgroundSubtractorGMG(int initializationFrames, double decisionThreshold)
|
||||
{
|
||||
return new GMGImpl(initializationFrames, decisionThreshold);
|
||||
return makePtr<GMGImpl>(initializationFrames, decisionThreshold);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -203,7 +203,7 @@ namespace
|
||||
|
||||
Ptr<cuda::BackgroundSubtractorMOG> cv::cuda::createBackgroundSubtractorMOG(int history, int nmixtures, double backgroundRatio, double noiseSigma)
|
||||
{
|
||||
return new MOGImpl(history, nmixtures, backgroundRatio, noiseSigma);
|
||||
return makePtr<MOGImpl>(history, nmixtures, backgroundRatio, noiseSigma);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -247,7 +247,7 @@ namespace
|
||||
|
||||
Ptr<cuda::BackgroundSubtractorMOG2> cv::cuda::createBackgroundSubtractorMOG2(int history, double varThreshold, bool detectShadows)
|
||||
{
|
||||
return new MOG2Impl(history, varThreshold, detectShadows);
|
||||
return makePtr<MOG2Impl>(history, varThreshold, detectShadows);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -70,7 +70,7 @@ using namespace cvtest;
|
||||
|
||||
namespace cv
|
||||
{
|
||||
template<> void Ptr<CvBGStatModel>::delete_obj()
|
||||
template<> void DefaultDeleter<CvBGStatModel>::operator ()(CvBGStatModel* obj) const
|
||||
{
|
||||
cvReleaseBGStatModel(&obj);
|
||||
}
|
||||
|
@ -167,9 +167,4 @@ void cv::cudacodec::detail::Thread::sleep(int ms)
|
||||
#endif
|
||||
}
|
||||
|
||||
template <> void cv::Ptr<cv::cudacodec::detail::Thread::Impl>::delete_obj()
|
||||
{
|
||||
if (obj) delete obj;
|
||||
}
|
||||
|
||||
#endif // HAVE_NVCUVID
|
||||
|
@ -67,8 +67,4 @@ private:
|
||||
|
||||
}}}
|
||||
|
||||
namespace cv {
|
||||
template <> void Ptr<cv::cudacodec::detail::Thread::Impl>::delete_obj();
|
||||
}
|
||||
|
||||
#endif // __THREAD_WRAPPERS_HPP__
|
||||
|
@ -169,7 +169,7 @@ Ptr<Filter> cv::cuda::createBoxFilter(int srcType, int dstType, Size ksize, Poin
|
||||
|
||||
dstType = CV_MAKE_TYPE(CV_MAT_DEPTH(dstType), CV_MAT_CN(srcType));
|
||||
|
||||
return new NPPBoxFilter(srcType, dstType, ksize, anchor, borderMode, borderVal);
|
||||
return makePtr<NPPBoxFilter>(srcType, dstType, ksize, anchor, borderMode, borderVal);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -277,7 +277,7 @@ Ptr<Filter> cv::cuda::createLinearFilter(int srcType, int dstType, InputArray ke
|
||||
|
||||
dstType = CV_MAKE_TYPE(CV_MAT_DEPTH(dstType), CV_MAT_CN(srcType));
|
||||
|
||||
return new LinearFilter(srcType, dstType, kernel, anchor, borderMode, borderVal);
|
||||
return makePtr<LinearFilter>(srcType, dstType, kernel, anchor, borderMode, borderVal);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -428,7 +428,7 @@ Ptr<Filter> cv::cuda::createSeparableLinearFilter(int srcType, int dstType, Inpu
|
||||
if (columnBorderMode < 0)
|
||||
columnBorderMode = rowBorderMode;
|
||||
|
||||
return new SeparableLinearFilter(srcType, dstType, rowKernel, columnKernel, anchor, rowBorderMode, columnBorderMode);
|
||||
return makePtr<SeparableLinearFilter>(srcType, dstType, rowKernel, columnKernel, anchor, rowBorderMode, columnBorderMode);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -748,27 +748,27 @@ Ptr<Filter> cv::cuda::createMorphologyFilter(int op, int srcType, InputArray ker
|
||||
{
|
||||
case MORPH_ERODE:
|
||||
case MORPH_DILATE:
|
||||
return new MorphologyFilter(op, srcType, kernel, anchor, iterations);
|
||||
return makePtr<MorphologyFilter>(op, srcType, kernel, anchor, iterations);
|
||||
break;
|
||||
|
||||
case MORPH_OPEN:
|
||||
return new MorphologyOpenFilter(srcType, kernel, anchor, iterations);
|
||||
return makePtr<MorphologyOpenFilter>(srcType, kernel, anchor, iterations);
|
||||
break;
|
||||
|
||||
case MORPH_CLOSE:
|
||||
return new MorphologyCloseFilter(srcType, kernel, anchor, iterations);
|
||||
return makePtr<MorphologyCloseFilter>(srcType, kernel, anchor, iterations);
|
||||
break;
|
||||
|
||||
case MORPH_GRADIENT:
|
||||
return new MorphologyGradientFilter(srcType, kernel, anchor, iterations);
|
||||
return makePtr<MorphologyGradientFilter>(srcType, kernel, anchor, iterations);
|
||||
break;
|
||||
|
||||
case MORPH_TOPHAT:
|
||||
return new MorphologyTophatFilter(srcType, kernel, anchor, iterations);
|
||||
return makePtr<MorphologyTophatFilter>(srcType, kernel, anchor, iterations);
|
||||
break;
|
||||
|
||||
case MORPH_BLACKHAT:
|
||||
return new MorphologyBlackhatFilter(srcType, kernel, anchor, iterations);
|
||||
return makePtr<MorphologyBlackhatFilter>(srcType, kernel, anchor, iterations);
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -782,7 +782,7 @@ Ptr<Filter> cv::cuda::createMorphologyFilter(int op, int srcType, InputArray ker
|
||||
|
||||
namespace
|
||||
{
|
||||
enum
|
||||
enum RankType
|
||||
{
|
||||
RANK_MAX,
|
||||
RANK_MIN
|
||||
@ -862,12 +862,12 @@ namespace
|
||||
|
||||
Ptr<Filter> cv::cuda::createBoxMaxFilter(int srcType, Size ksize, Point anchor, int borderMode, Scalar borderVal)
|
||||
{
|
||||
return new NPPRankFilter(RANK_MAX, srcType, ksize, anchor, borderMode, borderVal);
|
||||
return makePtr<NPPRankFilter>(RANK_MAX, srcType, ksize, anchor, borderMode, borderVal);
|
||||
}
|
||||
|
||||
Ptr<Filter> cv::cuda::createBoxMinFilter(int srcType, Size ksize, Point anchor, int borderMode, Scalar borderVal)
|
||||
{
|
||||
return new NPPRankFilter(RANK_MIN, srcType, ksize, anchor, borderMode, borderVal);
|
||||
return makePtr<NPPRankFilter>(RANK_MIN, srcType, ksize, anchor, borderMode, borderVal);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -931,7 +931,7 @@ namespace
|
||||
|
||||
Ptr<Filter> cv::cuda::createRowSumFilter(int srcType, int dstType, int ksize, int anchor, int borderMode, Scalar borderVal)
|
||||
{
|
||||
return new NppRowSumFilter(srcType, dstType, ksize, anchor, borderMode, borderVal);
|
||||
return makePtr<NppRowSumFilter>(srcType, dstType, ksize, anchor, borderMode, borderVal);
|
||||
}
|
||||
|
||||
namespace
|
||||
@ -992,7 +992,7 @@ namespace
|
||||
|
||||
Ptr<Filter> cv::cuda::createColumnSumFilter(int srcType, int dstType, int ksize, int anchor, int borderMode, Scalar borderVal)
|
||||
{
|
||||
return new NppColumnSumFilter(srcType, dstType, ksize, anchor, borderMode, borderVal);
|
||||
return makePtr<NppColumnSumFilter>(srcType, dstType, ksize, anchor, borderMode, borderVal);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -228,7 +228,7 @@ namespace
|
||||
|
||||
Ptr<CannyEdgeDetector> cv::cuda::createCannyEdgeDetector(double low_thresh, double high_thresh, int apperture_size, bool L2gradient)
|
||||
{
|
||||
return new CannyImpl(low_thresh, high_thresh, apperture_size, L2gradient);
|
||||
return makePtr<CannyImpl>(low_thresh, high_thresh, apperture_size, L2gradient);
|
||||
}
|
||||
|
||||
#endif /* !defined (HAVE_CUDA) */
|
||||
|
@ -178,12 +178,12 @@ namespace
|
||||
|
||||
Ptr<cuda::CornernessCriteria> cv::cuda::createHarrisCorner(int srcType, int blockSize, int ksize, double k, int borderType)
|
||||
{
|
||||
return new Harris(srcType, blockSize, ksize, k, borderType);
|
||||
return makePtr<Harris>(srcType, blockSize, ksize, k, borderType);
|
||||
}
|
||||
|
||||
Ptr<cuda::CornernessCriteria> cv::cuda::createMinEigenValCorner(int srcType, int blockSize, int ksize, int borderType)
|
||||
{
|
||||
return new MinEigenVal(srcType, blockSize, ksize, borderType);
|
||||
return makePtr<MinEigenVal>(srcType, blockSize, ksize, borderType);
|
||||
}
|
||||
|
||||
#endif /* !defined (HAVE_CUDA) */
|
||||
|
@ -554,7 +554,7 @@ namespace
|
||||
|
||||
Ptr<GeneralizedHoughBallard> cv::cuda::createGeneralizedHoughBallard()
|
||||
{
|
||||
return new GeneralizedHoughBallardImpl;
|
||||
return makePtr<GeneralizedHoughBallardImpl>();
|
||||
}
|
||||
|
||||
// GeneralizedHoughGuil
|
||||
@ -900,7 +900,7 @@ namespace
|
||||
|
||||
Ptr<GeneralizedHoughGuil> cv::cuda::createGeneralizedHoughGuil()
|
||||
{
|
||||
return new GeneralizedHoughGuilImpl;
|
||||
return makePtr<GeneralizedHoughGuilImpl>();
|
||||
}
|
||||
|
||||
#endif /* !defined (HAVE_CUDA) */
|
||||
|
@ -209,7 +209,8 @@ namespace
|
||||
Ptr<cuda::CornersDetector> cv::cuda::createGoodFeaturesToTrackDetector(int srcType, int maxCorners, double qualityLevel, double minDistance,
|
||||
int blockSize, bool useHarrisDetector, double harrisK)
|
||||
{
|
||||
return new GoodFeaturesToTrackDetector(srcType, maxCorners, qualityLevel, minDistance, blockSize, useHarrisDetector, harrisK);
|
||||
return Ptr<cuda::CornersDetector>(
|
||||
new GoodFeaturesToTrackDetector(srcType, maxCorners, qualityLevel, minDistance, blockSize, useHarrisDetector, harrisK));
|
||||
}
|
||||
|
||||
#endif /* !defined (HAVE_CUDA) */
|
||||
|
@ -257,7 +257,7 @@ namespace
|
||||
|
||||
cv::Ptr<cv::cuda::CLAHE> cv::cuda::createCLAHE(double clipLimit, cv::Size tileGridSize)
|
||||
{
|
||||
return new CLAHE_Impl(clipLimit, tileGridSize.width, tileGridSize.height);
|
||||
return makePtr<CLAHE_Impl>(clipLimit, tileGridSize.width, tileGridSize.height);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
@ -291,7 +291,7 @@ namespace
|
||||
|
||||
Ptr<HoughCirclesDetector> cv::cuda::createHoughCirclesDetector(float dp, float minDist, int cannyThreshold, int votesThreshold, int minRadius, int maxRadius, int maxCircles)
|
||||
{
|
||||
return new HoughCirclesDetectorImpl(dp, minDist, cannyThreshold, votesThreshold, minRadius, maxRadius, maxCircles);
|
||||
return makePtr<HoughCirclesDetectorImpl>(dp, minDist, cannyThreshold, votesThreshold, minRadius, maxRadius, maxCircles);
|
||||
}
|
||||
|
||||
#endif /* !defined (HAVE_CUDA) */
|
||||
|
@ -196,7 +196,7 @@ namespace
|
||||
|
||||
Ptr<HoughLinesDetector> cv::cuda::createHoughLinesDetector(float rho, float theta, int threshold, bool doSort, int maxLines)
|
||||
{
|
||||
return new HoughLinesDetectorImpl(rho, theta, threshold, doSort, maxLines);
|
||||
return makePtr<HoughLinesDetectorImpl>(rho, theta, threshold, doSort, maxLines);
|
||||
}
|
||||
|
||||
#endif /* !defined (HAVE_CUDA) */
|
||||
|
@ -177,7 +177,7 @@ namespace
|
||||
|
||||
Ptr<HoughSegmentDetector> cv::cuda::createHoughSegmentDetector(float rho, float theta, int minLineLength, int maxLineGap, int maxLines)
|
||||
{
|
||||
return new HoughSegmentDetectorImpl(rho, theta, minLineLength, maxLineGap, maxLines);
|
||||
return makePtr<HoughSegmentDetectorImpl>(rho, theta, minLineLength, maxLineGap, maxLines);
|
||||
}
|
||||
|
||||
#endif /* !defined (HAVE_CUDA) */
|
||||
|
@ -607,10 +607,10 @@ Ptr<cuda::TemplateMatching> cv::cuda::createTemplateMatching(int srcType, int me
|
||||
switch (method)
|
||||
{
|
||||
case TM_SQDIFF:
|
||||
return new Match_SQDIFF_32F;
|
||||
return makePtr<Match_SQDIFF_32F>();
|
||||
|
||||
case TM_CCORR:
|
||||
return new Match_CCORR_32F(user_block_size);
|
||||
return makePtr<Match_CCORR_32F>(user_block_size);
|
||||
|
||||
default:
|
||||
CV_Error( Error::StsBadFlag, "Unsopported method" );
|
||||
@ -622,22 +622,22 @@ Ptr<cuda::TemplateMatching> cv::cuda::createTemplateMatching(int srcType, int me
|
||||
switch (method)
|
||||
{
|
||||
case TM_SQDIFF:
|
||||
return new Match_SQDIFF_8U(user_block_size);
|
||||
return makePtr<Match_SQDIFF_8U>(user_block_size);
|
||||
|
||||
case TM_SQDIFF_NORMED:
|
||||
return new Match_SQDIFF_NORMED_8U(user_block_size);
|
||||
return makePtr<Match_SQDIFF_NORMED_8U>(user_block_size);
|
||||
|
||||
case TM_CCORR:
|
||||
return new Match_CCORR_8U(user_block_size);
|
||||
return makePtr<Match_CCORR_8U>(user_block_size);
|
||||
|
||||
case TM_CCORR_NORMED:
|
||||
return new Match_CCORR_NORMED_8U(user_block_size);
|
||||
return makePtr<Match_CCORR_NORMED_8U>(user_block_size);
|
||||
|
||||
case TM_CCOEFF:
|
||||
return new Match_CCOEFF_8U(user_block_size);
|
||||
return makePtr<Match_CCOEFF_8U>(user_block_size);
|
||||
|
||||
case TM_CCOEFF_NORMED:
|
||||
return new Match_CCOEFF_NORMED_8U(user_block_size);
|
||||
return makePtr<Match_CCOEFF_NORMED_8U>(user_block_size);
|
||||
|
||||
default:
|
||||
CV_Error( Error::StsBadFlag, "Unsopported method" );
|
||||
|
@ -2138,8 +2138,8 @@ static NCVStatus loadFromXML(const cv::String &filename,
|
||||
haarClassifierNodes.resize(0);
|
||||
haarFeatures.resize(0);
|
||||
|
||||
cv::Ptr<CvHaarClassifierCascade> oldCascade = (CvHaarClassifierCascade*)cvLoad(filename.c_str(), 0, 0, 0);
|
||||
if (oldCascade.empty())
|
||||
cv::Ptr<CvHaarClassifierCascade> oldCascade((CvHaarClassifierCascade*)cvLoad(filename.c_str(), 0, 0, 0));
|
||||
if (!oldCascade)
|
||||
{
|
||||
return NCV_HAAR_XML_LOADING_EXCEPTION;
|
||||
}
|
||||
|
@ -200,7 +200,7 @@ namespace
|
||||
|
||||
Ptr<cuda::DisparityBilateralFilter> cv::cuda::createDisparityBilateralFilter(int ndisp, int radius, int iters)
|
||||
{
|
||||
return new DispBilateralFilterImpl(ndisp, radius, iters);
|
||||
return makePtr<DispBilateralFilterImpl>(ndisp, radius, iters);
|
||||
}
|
||||
|
||||
#endif /* !defined (HAVE_CUDA) */
|
||||
|
@ -179,7 +179,7 @@ namespace
|
||||
|
||||
Ptr<cuda::StereoBM> cv::cuda::createStereoBM(int numDisparities, int blockSize)
|
||||
{
|
||||
return new StereoBMImpl(numDisparities, blockSize);
|
||||
return makePtr<StereoBMImpl>(numDisparities, blockSize);
|
||||
}
|
||||
|
||||
#endif /* !defined (HAVE_CUDA) */
|
||||
|
@ -361,7 +361,7 @@ namespace
|
||||
|
||||
Ptr<cuda::StereoBeliefPropagation> cv::cuda::createStereoBeliefPropagation(int ndisp, int iters, int levels, int msg_type)
|
||||
{
|
||||
return new StereoBPImpl(ndisp, iters, levels, msg_type);
|
||||
return makePtr<StereoBPImpl>(ndisp, iters, levels, msg_type);
|
||||
}
|
||||
|
||||
void cv::cuda::StereoBeliefPropagation::estimateRecommendedParams(int width, int height, int& ndisp, int& iters, int& levels)
|
||||
|
@ -366,7 +366,7 @@ namespace
|
||||
|
||||
Ptr<cuda::StereoConstantSpaceBP> cv::cuda::createStereoConstantSpaceBP(int ndisp, int iters, int levels, int nr_plane, int msg_type)
|
||||
{
|
||||
return new StereoCSBPImpl(ndisp, iters, levels, nr_plane, msg_type);
|
||||
return makePtr<StereoCSBPImpl>(ndisp, iters, levels, nr_plane, msg_type);
|
||||
}
|
||||
|
||||
void cv::cuda::StereoConstantSpaceBP::estimateRecommendedParams(int width, int height, int& ndisp, int& iters, int& levels, int& nr_plane)
|
||||
|
@ -237,7 +237,7 @@ Ptr<ImagePyramid> cv::cuda::createImagePyramid(InputArray img, int nLayers, Stre
|
||||
throw_no_cuda();
|
||||
return Ptr<ImagePyramid>();
|
||||
#else
|
||||
return new ImagePyramidImpl(img, nLayers, stream);
|
||||
return Ptr<ImagePyramid>(new ImagePyramidImpl(img, nLayers, stream));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -646,7 +646,7 @@ public:
|
||||
* gridRows Grid rows count.
|
||||
* gridCols Grid column count.
|
||||
*/
|
||||
CV_WRAP GridAdaptedFeatureDetector( const Ptr<FeatureDetector>& detector=0,
|
||||
CV_WRAP GridAdaptedFeatureDetector( const Ptr<FeatureDetector>& detector=Ptr<FeatureDetector>(),
|
||||
int maxTotalKeypoints=1000,
|
||||
int gridRows=4, int gridCols=4 );
|
||||
|
||||
@ -1143,8 +1143,8 @@ protected:
|
||||
class CV_EXPORTS_W FlannBasedMatcher : public DescriptorMatcher
|
||||
{
|
||||
public:
|
||||
CV_WRAP FlannBasedMatcher( const Ptr<flann::IndexParams>& indexParams=new flann::KDTreeIndexParams(),
|
||||
const Ptr<flann::SearchParams>& searchParams=new flann::SearchParams() );
|
||||
CV_WRAP FlannBasedMatcher( const Ptr<flann::IndexParams>& indexParams=makePtr<flann::KDTreeIndexParams>(),
|
||||
const Ptr<flann::SearchParams>& searchParams=makePtr<flann::SearchParams>() );
|
||||
|
||||
virtual void add( const std::vector<Mat>& descriptors );
|
||||
virtual void clear();
|
||||
|
@ -2003,7 +2003,7 @@ BriskLayer::BriskLayer(const cv::Mat& img_in, float scale_in, float offset_in)
|
||||
scale_ = scale_in;
|
||||
offset_ = offset_in;
|
||||
// create an agast detector
|
||||
fast_9_16_ = new FastFeatureDetector(1, true, FastFeatureDetector::TYPE_9_16);
|
||||
fast_9_16_ = makePtr<FastFeatureDetector>(1, true, FastFeatureDetector::TYPE_9_16);
|
||||
makeOffsets(pixel_5_8_, (int)img_.step, 8);
|
||||
makeOffsets(pixel_9_16_, (int)img_.step, 16);
|
||||
}
|
||||
@ -2025,7 +2025,7 @@ BriskLayer::BriskLayer(const BriskLayer& layer, int mode)
|
||||
offset_ = 0.5f * scale_ - 0.5f;
|
||||
}
|
||||
scores_ = cv::Mat::zeros(img_.rows, img_.cols, CV_8U);
|
||||
fast_9_16_ = new FastFeatureDetector(1, false, FastFeatureDetector::TYPE_9_16);
|
||||
fast_9_16_ = makePtr<FastFeatureDetector>(1, false, FastFeatureDetector::TYPE_9_16);
|
||||
makeOffsets(pixel_5_8_, (int)img_.step, 8);
|
||||
makeOffsets(pixel_9_16_, (int)img_.step, 16);
|
||||
}
|
||||
|
@ -99,7 +99,7 @@ Ptr<DescriptorExtractor> DescriptorExtractor::create(const String& descriptorExt
|
||||
{
|
||||
size_t pos = String("Opponent").size();
|
||||
String type = descriptorExtractorType.substr(pos);
|
||||
return new OpponentColorDescriptorExtractor(DescriptorExtractor::create(type));
|
||||
return makePtr<OpponentColorDescriptorExtractor>(DescriptorExtractor::create(type));
|
||||
}
|
||||
|
||||
return Algorithm::create<DescriptorExtractor>("Feature2D." + descriptorExtractorType);
|
||||
@ -119,7 +119,7 @@ CV_WRAP void Feature2D::compute( const Mat& image, CV_OUT CV_IN_OUT std::vector<
|
||||
OpponentColorDescriptorExtractor::OpponentColorDescriptorExtractor( const Ptr<DescriptorExtractor>& _descriptorExtractor ) :
|
||||
descriptorExtractor(_descriptorExtractor)
|
||||
{
|
||||
CV_Assert( !descriptorExtractor.empty() );
|
||||
CV_Assert( descriptorExtractor );
|
||||
}
|
||||
|
||||
static void convertBGRImageToOpponentColorSpace( const Mat& bgrImage, std::vector<Mat>& opponentChannels )
|
||||
@ -249,7 +249,7 @@ int OpponentColorDescriptorExtractor::descriptorType() const
|
||||
|
||||
bool OpponentColorDescriptorExtractor::empty() const
|
||||
{
|
||||
return descriptorExtractor.empty() || (DescriptorExtractor*)(descriptorExtractor)->empty();
|
||||
return !descriptorExtractor || descriptorExtractor->empty();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -90,19 +90,19 @@ Ptr<FeatureDetector> FeatureDetector::create( const String& detectorType )
|
||||
{
|
||||
if( detectorType.find("Grid") == 0 )
|
||||
{
|
||||
return new GridAdaptedFeatureDetector(FeatureDetector::create(
|
||||
return makePtr<GridAdaptedFeatureDetector>(FeatureDetector::create(
|
||||
detectorType.substr(strlen("Grid"))));
|
||||
}
|
||||
|
||||
if( detectorType.find("Pyramid") == 0 )
|
||||
{
|
||||
return new PyramidAdaptedFeatureDetector(FeatureDetector::create(
|
||||
return makePtr<PyramidAdaptedFeatureDetector>(FeatureDetector::create(
|
||||
detectorType.substr(strlen("Pyramid"))));
|
||||
}
|
||||
|
||||
if( detectorType.find("Dynamic") == 0 )
|
||||
{
|
||||
return new DynamicAdaptedFeatureDetector(AdjusterAdapter::create(
|
||||
return makePtr<DynamicAdaptedFeatureDetector>(AdjusterAdapter::create(
|
||||
detectorType.substr(strlen("Dynamic"))));
|
||||
}
|
||||
|
||||
@ -190,7 +190,7 @@ GridAdaptedFeatureDetector::GridAdaptedFeatureDetector( const Ptr<FeatureDetecto
|
||||
|
||||
bool GridAdaptedFeatureDetector::empty() const
|
||||
{
|
||||
return detector.empty() || (FeatureDetector*)detector->empty();
|
||||
return !detector || detector->empty();
|
||||
}
|
||||
|
||||
struct ResponseComparator
|
||||
@ -295,7 +295,7 @@ PyramidAdaptedFeatureDetector::PyramidAdaptedFeatureDetector( const Ptr<FeatureD
|
||||
|
||||
bool PyramidAdaptedFeatureDetector::empty() const
|
||||
{
|
||||
return detector.empty() || (FeatureDetector*)detector->empty();
|
||||
return !detector || detector->empty();
|
||||
}
|
||||
|
||||
void PyramidAdaptedFeatureDetector::detectImpl( const Mat& image, std::vector<KeyPoint>& keypoints, const Mat& mask ) const
|
||||
|
@ -51,7 +51,7 @@ DynamicAdaptedFeatureDetector::DynamicAdaptedFeatureDetector(const Ptr<AdjusterA
|
||||
|
||||
bool DynamicAdaptedFeatureDetector::empty() const
|
||||
{
|
||||
return adjuster_.empty() || adjuster_->empty();
|
||||
return !adjuster_ || adjuster_->empty();
|
||||
}
|
||||
|
||||
void DynamicAdaptedFeatureDetector::detectImpl(const Mat& image, std::vector<KeyPoint>& keypoints, const Mat& mask) const
|
||||
@ -124,7 +124,7 @@ bool FastAdjuster::good() const
|
||||
|
||||
Ptr<AdjusterAdapter> FastAdjuster::clone() const
|
||||
{
|
||||
Ptr<AdjusterAdapter> cloned_obj = new FastAdjuster( init_thresh_, nonmax_, min_thresh_, max_thresh_ );
|
||||
Ptr<AdjusterAdapter> cloned_obj(new FastAdjuster( init_thresh_, nonmax_, min_thresh_, max_thresh_ ));
|
||||
return cloned_obj;
|
||||
}
|
||||
|
||||
@ -158,7 +158,7 @@ bool StarAdjuster::good() const
|
||||
|
||||
Ptr<AdjusterAdapter> StarAdjuster::clone() const
|
||||
{
|
||||
Ptr<AdjusterAdapter> cloned_obj = new StarAdjuster( init_thresh_, min_thresh_, max_thresh_ );
|
||||
Ptr<AdjusterAdapter> cloned_obj(new StarAdjuster( init_thresh_, min_thresh_, max_thresh_ ));
|
||||
return cloned_obj;
|
||||
}
|
||||
|
||||
@ -195,7 +195,7 @@ bool SurfAdjuster::good() const
|
||||
|
||||
Ptr<AdjusterAdapter> SurfAdjuster::clone() const
|
||||
{
|
||||
Ptr<AdjusterAdapter> cloned_obj = new SurfAdjuster( init_thresh_, min_thresh_, max_thresh_ );
|
||||
Ptr<AdjusterAdapter> cloned_obj(new SurfAdjuster( init_thresh_, min_thresh_, max_thresh_ ));
|
||||
return cloned_obj;
|
||||
}
|
||||
|
||||
@ -205,15 +205,15 @@ Ptr<AdjusterAdapter> AdjusterAdapter::create( const String& detectorType )
|
||||
|
||||
if( !detectorType.compare( "FAST" ) )
|
||||
{
|
||||
adapter = new FastAdjuster();
|
||||
adapter = makePtr<FastAdjuster>();
|
||||
}
|
||||
else if( !detectorType.compare( "STAR" ) )
|
||||
{
|
||||
adapter = new StarAdjuster();
|
||||
adapter = makePtr<StarAdjuster>();
|
||||
}
|
||||
else if( !detectorType.compare( "SURF" ) )
|
||||
{
|
||||
adapter = new SurfAdjuster();
|
||||
adapter = makePtr<SurfAdjuster>();
|
||||
}
|
||||
|
||||
return adapter;
|
||||
|
@ -461,7 +461,7 @@ void cv::evaluateFeatureDetector( const Mat& img1, const Mat& img2, const Mat& H
|
||||
keypoints1 = _keypoints1 != 0 ? _keypoints1 : &buf1;
|
||||
keypoints2 = _keypoints2 != 0 ? _keypoints2 : &buf2;
|
||||
|
||||
if( (keypoints1->empty() || keypoints2->empty()) && fdetector.empty() )
|
||||
if( (keypoints1->empty() || keypoints2->empty()) && !fdetector )
|
||||
CV_Error( Error::StsBadArg, "fdetector must not be empty when keypoints1 or keypoints2 is empty" );
|
||||
|
||||
if( keypoints1->empty() )
|
||||
@ -575,7 +575,7 @@ void cv::evaluateGenericDescriptorMatcher( const Mat& img1, const Mat& img2, con
|
||||
if( keypoints1.empty() )
|
||||
CV_Error( Error::StsBadArg, "keypoints1 must not be empty" );
|
||||
|
||||
if( matches1to2->empty() && dmatcher.empty() )
|
||||
if( matches1to2->empty() && !dmatcher )
|
||||
CV_Error( Error::StsBadArg, "dmatch must not be empty when matches1to2 is empty" );
|
||||
|
||||
bool computeKeypoints2ByPrj = keypoints2.empty();
|
||||
|
@ -326,7 +326,7 @@ BFMatcher::BFMatcher( int _normType, bool _crossCheck )
|
||||
|
||||
Ptr<DescriptorMatcher> BFMatcher::clone( bool emptyTrainData ) const
|
||||
{
|
||||
BFMatcher* matcher = new BFMatcher(normType, crossCheck);
|
||||
Ptr<BFMatcher> matcher = makePtr<BFMatcher>(normType, crossCheck);
|
||||
if( !emptyTrainData )
|
||||
{
|
||||
matcher->trainDescCollection.resize(trainDescCollection.size());
|
||||
@ -458,31 +458,31 @@ void BFMatcher::radiusMatchImpl( const Mat& queryDescriptors, std::vector<std::v
|
||||
*/
|
||||
Ptr<DescriptorMatcher> DescriptorMatcher::create( const String& descriptorMatcherType )
|
||||
{
|
||||
DescriptorMatcher* dm = 0;
|
||||
Ptr<DescriptorMatcher> dm;
|
||||
if( !descriptorMatcherType.compare( "FlannBased" ) )
|
||||
{
|
||||
dm = new FlannBasedMatcher();
|
||||
dm = makePtr<FlannBasedMatcher>();
|
||||
}
|
||||
else if( !descriptorMatcherType.compare( "BruteForce" ) ) // L2
|
||||
{
|
||||
dm = new BFMatcher(NORM_L2);
|
||||
dm = makePtr<BFMatcher>(int(NORM_L2)); // anonymous enums can't be template parameters
|
||||
}
|
||||
else if( !descriptorMatcherType.compare( "BruteForce-SL2" ) ) // Squared L2
|
||||
{
|
||||
dm = new BFMatcher(NORM_L2SQR);
|
||||
dm = makePtr<BFMatcher>(int(NORM_L2SQR));
|
||||
}
|
||||
else if( !descriptorMatcherType.compare( "BruteForce-L1" ) )
|
||||
{
|
||||
dm = new BFMatcher(NORM_L1);
|
||||
dm = makePtr<BFMatcher>(int(NORM_L1));
|
||||
}
|
||||
else if( !descriptorMatcherType.compare("BruteForce-Hamming") ||
|
||||
!descriptorMatcherType.compare("BruteForce-HammingLUT") )
|
||||
{
|
||||
dm = new BFMatcher(NORM_HAMMING);
|
||||
dm = makePtr<BFMatcher>(int(NORM_HAMMING));
|
||||
}
|
||||
else if( !descriptorMatcherType.compare("BruteForce-Hamming(2)") )
|
||||
{
|
||||
dm = new BFMatcher(NORM_HAMMING2);
|
||||
dm = makePtr<BFMatcher>(int(NORM_HAMMING2));
|
||||
}
|
||||
else
|
||||
CV_Error( Error::StsBadArg, "Unknown matcher name" );
|
||||
@ -497,8 +497,8 @@ Ptr<DescriptorMatcher> DescriptorMatcher::create( const String& descriptorMatche
|
||||
FlannBasedMatcher::FlannBasedMatcher( const Ptr<flann::IndexParams>& _indexParams, const Ptr<flann::SearchParams>& _searchParams )
|
||||
: indexParams(_indexParams), searchParams(_searchParams), addedDescCount(0)
|
||||
{
|
||||
CV_Assert( !_indexParams.empty() );
|
||||
CV_Assert( !_searchParams.empty() );
|
||||
CV_Assert( _indexParams );
|
||||
CV_Assert( _searchParams );
|
||||
}
|
||||
|
||||
void FlannBasedMatcher::add( const std::vector<Mat>& descriptors )
|
||||
@ -522,17 +522,17 @@ void FlannBasedMatcher::clear()
|
||||
|
||||
void FlannBasedMatcher::train()
|
||||
{
|
||||
if( flannIndex.empty() || mergedDescriptors.size() < addedDescCount )
|
||||
if( !flannIndex || mergedDescriptors.size() < addedDescCount )
|
||||
{
|
||||
mergedDescriptors.set( trainDescCollection );
|
||||
flannIndex = new flann::Index( mergedDescriptors.getDescriptors(), *indexParams );
|
||||
flannIndex = makePtr<flann::Index>( mergedDescriptors.getDescriptors(), *indexParams );
|
||||
}
|
||||
}
|
||||
|
||||
void FlannBasedMatcher::read( const FileNode& fn)
|
||||
{
|
||||
if (indexParams.empty())
|
||||
indexParams = new flann::IndexParams();
|
||||
if (!indexParams)
|
||||
indexParams = makePtr<flann::IndexParams>();
|
||||
|
||||
FileNode ip = fn["indexParams"];
|
||||
CV_Assert(ip.type() == FileNode::SEQ);
|
||||
@ -570,8 +570,8 @@ void FlannBasedMatcher::read( const FileNode& fn)
|
||||
};
|
||||
}
|
||||
|
||||
if (searchParams.empty())
|
||||
searchParams = new flann::SearchParams();
|
||||
if (!searchParams)
|
||||
searchParams = makePtr<flann::SearchParams>();
|
||||
|
||||
FileNode sp = fn["searchParams"];
|
||||
CV_Assert(sp.type() == FileNode::SEQ);
|
||||
@ -725,7 +725,7 @@ bool FlannBasedMatcher::isMaskSupported() const
|
||||
|
||||
Ptr<DescriptorMatcher> FlannBasedMatcher::clone( bool emptyTrainData ) const
|
||||
{
|
||||
FlannBasedMatcher* matcher = new FlannBasedMatcher(indexParams, searchParams);
|
||||
Ptr<FlannBasedMatcher> matcher = makePtr<FlannBasedMatcher>(indexParams, searchParams);
|
||||
if( !emptyTrainData )
|
||||
{
|
||||
CV_Error( Error::StsNotImplemented, "deep clone functionality is not implemented, because "
|
||||
@ -1066,7 +1066,7 @@ Ptr<GenericDescriptorMatcher> GenericDescriptorMatcher::create( const String& ge
|
||||
Ptr<GenericDescriptorMatcher> descriptorMatcher =
|
||||
Algorithm::create<GenericDescriptorMatcher>("DescriptorMatcher." + genericDescritptorMatcherType);
|
||||
|
||||
if( !paramsFilename.empty() && !descriptorMatcher.empty() )
|
||||
if( !paramsFilename.empty() && descriptorMatcher )
|
||||
{
|
||||
FileStorage fs = FileStorage( paramsFilename, FileStorage::READ );
|
||||
if( fs.isOpened() )
|
||||
@ -1086,7 +1086,7 @@ VectorDescriptorMatcher::VectorDescriptorMatcher( const Ptr<DescriptorExtractor>
|
||||
const Ptr<DescriptorMatcher>& _matcher )
|
||||
: extractor( _extractor ), matcher( _matcher )
|
||||
{
|
||||
CV_Assert( !extractor.empty() && !matcher.empty() );
|
||||
CV_Assert( extractor && matcher );
|
||||
}
|
||||
|
||||
VectorDescriptorMatcher::~VectorDescriptorMatcher()
|
||||
@ -1152,14 +1152,14 @@ void VectorDescriptorMatcher::write (FileStorage& fs) const
|
||||
|
||||
bool VectorDescriptorMatcher::empty() const
|
||||
{
|
||||
return extractor.empty() || extractor->empty() ||
|
||||
matcher.empty() || matcher->empty();
|
||||
return !extractor || extractor->empty() ||
|
||||
!matcher || matcher->empty();
|
||||
}
|
||||
|
||||
Ptr<GenericDescriptorMatcher> VectorDescriptorMatcher::clone( bool emptyTrainData ) const
|
||||
{
|
||||
// TODO clone extractor
|
||||
return new VectorDescriptorMatcher( extractor, matcher->clone(emptyTrainData) );
|
||||
return makePtr<VectorDescriptorMatcher>( extractor, matcher->clone(emptyTrainData) );
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -141,7 +141,7 @@ protected:
|
||||
|
||||
void emptyDataTest()
|
||||
{
|
||||
assert( !dextractor.empty() );
|
||||
assert( dextractor );
|
||||
|
||||
// One image.
|
||||
Mat image;
|
||||
@ -186,7 +186,7 @@ protected:
|
||||
|
||||
void regressionTest()
|
||||
{
|
||||
assert( !dextractor.empty() );
|
||||
assert( dextractor );
|
||||
|
||||
// Read the test image.
|
||||
string imgFilename = string(ts->get_data_path()) + FEATURES2D_DIR + "/" + IMAGE_FILENAME;
|
||||
@ -267,7 +267,7 @@ protected:
|
||||
void run(int)
|
||||
{
|
||||
createDescriptorExtractor();
|
||||
if( dextractor.empty() )
|
||||
if( !dextractor )
|
||||
{
|
||||
ts->printf(cvtest::TS::LOG, "Descriptor extractor is empty.\n");
|
||||
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_TEST_DATA );
|
||||
|
@ -230,7 +230,7 @@ void CV_FeatureDetectorTest::regressionTest()
|
||||
|
||||
void CV_FeatureDetectorTest::run( int /*start_from*/ )
|
||||
{
|
||||
if( fdetector.empty() )
|
||||
if( !fdetector )
|
||||
{
|
||||
ts->printf( cvtest::TS::LOG, "Feature detector is empty.\n" );
|
||||
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_TEST_DATA );
|
||||
|
@ -62,7 +62,7 @@ protected:
|
||||
virtual void run(int)
|
||||
{
|
||||
cv::initModule_features2d();
|
||||
CV_Assert(!detector.empty());
|
||||
CV_Assert(detector);
|
||||
string imgFilename = string(ts->get_data_path()) + FEATURES2D_DIR + "/" + IMAGE_FILENAME;
|
||||
|
||||
// Read the test image.
|
||||
|
@ -196,7 +196,7 @@ public:
|
||||
minKeyPointMatchesRatio(_minKeyPointMatchesRatio),
|
||||
minAngleInliersRatio(_minAngleInliersRatio)
|
||||
{
|
||||
CV_Assert(!featureDetector.empty());
|
||||
CV_Assert(featureDetector);
|
||||
}
|
||||
|
||||
protected:
|
||||
@ -307,8 +307,8 @@ public:
|
||||
normType(_normType),
|
||||
minDescInliersRatio(_minDescInliersRatio)
|
||||
{
|
||||
CV_Assert(!featureDetector.empty());
|
||||
CV_Assert(!descriptorExtractor.empty());
|
||||
CV_Assert(featureDetector);
|
||||
CV_Assert(descriptorExtractor);
|
||||
}
|
||||
|
||||
protected:
|
||||
@ -392,7 +392,7 @@ public:
|
||||
minKeyPointMatchesRatio(_minKeyPointMatchesRatio),
|
||||
minScaleInliersRatio(_minScaleInliersRatio)
|
||||
{
|
||||
CV_Assert(!featureDetector.empty());
|
||||
CV_Assert(featureDetector);
|
||||
}
|
||||
|
||||
protected:
|
||||
@ -510,8 +510,8 @@ public:
|
||||
normType(_normType),
|
||||
minDescInliersRatio(_minDescInliersRatio)
|
||||
{
|
||||
CV_Assert(!featureDetector.empty());
|
||||
CV_Assert(!descriptorExtractor.empty());
|
||||
CV_Assert(featureDetector);
|
||||
CV_Assert(descriptorExtractor);
|
||||
}
|
||||
|
||||
protected:
|
||||
|
@ -81,7 +81,7 @@ The function ``imshow`` displays an image in the specified window. If the window
|
||||
|
||||
If window was created with OpenGL support, ``imshow`` also support :ocv:class:`ogl::Buffer` , :ocv:class:`ogl::Texture2D` and :ocv:class:`cuda::GpuMat` as input.
|
||||
|
||||
.. note:: This function should be followed by ``waitKey`` function which displays the image for specified milliseconds. Otherwise, it won't display the image.
|
||||
.. note:: This function should be followed by ``waitKey`` function which displays the image for specified milliseconds. Otherwise, it won't display the image. For example, ``waitKey(0)`` will display the window infinitely until any keypress (it is suitable for image display). ``waitKey(25)`` will display a frame for 25 ms, after which display will be automatically closed. (If you put it in a loop to read videos, it will display the video frame-by-frame)
|
||||
|
||||
|
||||
namedWindow
|
||||
|
@ -544,8 +544,8 @@ protected:
|
||||
Ptr<CvVideoWriter> writer;
|
||||
};
|
||||
|
||||
template<> CV_EXPORTS void Ptr<CvCapture>::delete_obj();
|
||||
template<> CV_EXPORTS void Ptr<CvVideoWriter>::delete_obj();
|
||||
template<> CV_EXPORTS void DefaultDeleter<CvCapture>::operator ()(CvCapture* obj) const;
|
||||
template<> CV_EXPORTS void DefaultDeleter<CvVideoWriter>::operator ()(CvVideoWriter* obj) const;
|
||||
|
||||
} // cv
|
||||
|
||||
|
@ -49,10 +49,10 @@
|
||||
namespace cv
|
||||
{
|
||||
|
||||
template<> void Ptr<CvCapture>::delete_obj()
|
||||
template<> void DefaultDeleter<CvCapture>::operator ()(CvCapture* obj) const
|
||||
{ cvReleaseCapture(&obj); }
|
||||
|
||||
template<> void Ptr<CvVideoWriter>::delete_obj()
|
||||
template<> void DefaultDeleter<CvVideoWriter>::operator ()(CvVideoWriter* obj) const
|
||||
{ cvReleaseVideoWriter(&obj); }
|
||||
|
||||
}
|
||||
@ -492,14 +492,14 @@ VideoCapture::~VideoCapture()
|
||||
bool VideoCapture::open(const String& filename)
|
||||
{
|
||||
if (isOpened()) release();
|
||||
cap = cvCreateFileCapture(filename.c_str());
|
||||
cap.reset(cvCreateFileCapture(filename.c_str()));
|
||||
return isOpened();
|
||||
}
|
||||
|
||||
bool VideoCapture::open(int device)
|
||||
{
|
||||
if (isOpened()) release();
|
||||
cap = cvCreateCameraCapture(device);
|
||||
cap.reset(cvCreateCameraCapture(device));
|
||||
return isOpened();
|
||||
}
|
||||
|
||||
@ -578,7 +578,7 @@ VideoWriter::~VideoWriter()
|
||||
|
||||
bool VideoWriter::open(const String& filename, int _fourcc, double fps, Size frameSize, bool isColor)
|
||||
{
|
||||
writer = cvCreateVideoWriter(filename.c_str(), _fourcc, fps, frameSize, isColor);
|
||||
writer.reset(cvCreateVideoWriter(filename.c_str(), _fourcc, fps, frameSize, isColor));
|
||||
return isOpened();
|
||||
}
|
||||
|
||||
|
@ -70,7 +70,7 @@ void BmpDecoder::close()
|
||||
|
||||
ImageDecoder BmpDecoder::newDecoder() const
|
||||
{
|
||||
return new BmpDecoder;
|
||||
return makePtr<BmpDecoder>();
|
||||
}
|
||||
|
||||
bool BmpDecoder::readHeader()
|
||||
@ -496,7 +496,7 @@ BmpEncoder::~BmpEncoder()
|
||||
|
||||
ImageEncoder BmpEncoder::newEncoder() const
|
||||
{
|
||||
return new BmpEncoder;
|
||||
return makePtr<BmpEncoder>();
|
||||
}
|
||||
|
||||
bool BmpEncoder::write( const Mat& img, const std::vector<int>& )
|
||||
|
@ -551,7 +551,7 @@ void ExrDecoder::RGBToGray( float *in, float *out )
|
||||
|
||||
ImageDecoder ExrDecoder::newDecoder() const
|
||||
{
|
||||
return new ExrDecoder;
|
||||
return makePtr<ExrDecoder>();
|
||||
}
|
||||
|
||||
/////////////////////// ExrEncoder ///////////////////
|
||||
@ -726,7 +726,7 @@ bool ExrEncoder::write( const Mat& img, const std::vector<int>& )
|
||||
|
||||
ImageEncoder ExrEncoder::newEncoder() const
|
||||
{
|
||||
return new ExrEncoder;
|
||||
return makePtr<ExrEncoder>();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -208,7 +208,7 @@ void JpegDecoder::close()
|
||||
|
||||
ImageDecoder JpegDecoder::newDecoder() const
|
||||
{
|
||||
return new JpegDecoder;
|
||||
return makePtr<JpegDecoder>();
|
||||
}
|
||||
|
||||
bool JpegDecoder::readHeader()
|
||||
@ -539,7 +539,7 @@ JpegEncoder::~JpegEncoder()
|
||||
|
||||
ImageEncoder JpegEncoder::newEncoder() const
|
||||
{
|
||||
return new JpegEncoder;
|
||||
return makePtr<JpegEncoder>();
|
||||
}
|
||||
|
||||
bool JpegEncoder::write( const Mat& img, const std::vector<int>& params )
|
||||
|
@ -88,7 +88,7 @@ Jpeg2KDecoder::~Jpeg2KDecoder()
|
||||
|
||||
ImageDecoder Jpeg2KDecoder::newDecoder() const
|
||||
{
|
||||
return new Jpeg2KDecoder;
|
||||
return makePtr<Jpeg2KDecoder>();
|
||||
}
|
||||
|
||||
void Jpeg2KDecoder::close()
|
||||
@ -403,7 +403,7 @@ Jpeg2KEncoder::~Jpeg2KEncoder()
|
||||
|
||||
ImageEncoder Jpeg2KEncoder::newEncoder() const
|
||||
{
|
||||
return new Jpeg2KEncoder;
|
||||
return makePtr<Jpeg2KEncoder>();
|
||||
}
|
||||
|
||||
bool Jpeg2KEncoder::isFormatSupported( int depth ) const
|
||||
|
@ -101,7 +101,7 @@ PngDecoder::~PngDecoder()
|
||||
|
||||
ImageDecoder PngDecoder::newDecoder() const
|
||||
{
|
||||
return new PngDecoder;
|
||||
return makePtr<PngDecoder>();
|
||||
}
|
||||
|
||||
void PngDecoder::close()
|
||||
@ -317,7 +317,7 @@ bool PngEncoder::isFormatSupported( int depth ) const
|
||||
|
||||
ImageEncoder PngEncoder::newEncoder() const
|
||||
{
|
||||
return new PngEncoder;
|
||||
return makePtr<PngEncoder>();
|
||||
}
|
||||
|
||||
|
||||
|
@ -116,7 +116,7 @@ bool PxMDecoder::checkSignature( const String& signature ) const
|
||||
|
||||
ImageDecoder PxMDecoder::newDecoder() const
|
||||
{
|
||||
return new PxMDecoder;
|
||||
return makePtr<PxMDecoder>();
|
||||
}
|
||||
|
||||
void PxMDecoder::close()
|
||||
@ -357,7 +357,7 @@ PxMEncoder::~PxMEncoder()
|
||||
|
||||
ImageEncoder PxMEncoder::newEncoder() const
|
||||
{
|
||||
return new PxMEncoder;
|
||||
return makePtr<PxMEncoder>();
|
||||
}
|
||||
|
||||
|
||||
|
@ -63,7 +63,7 @@ SunRasterDecoder::~SunRasterDecoder()
|
||||
|
||||
ImageDecoder SunRasterDecoder::newDecoder() const
|
||||
{
|
||||
return new SunRasterDecoder;
|
||||
return makePtr<SunRasterDecoder>();
|
||||
}
|
||||
|
||||
void SunRasterDecoder::close()
|
||||
@ -388,7 +388,7 @@ SunRasterEncoder::SunRasterEncoder()
|
||||
|
||||
ImageEncoder SunRasterEncoder::newEncoder() const
|
||||
{
|
||||
return new SunRasterEncoder;
|
||||
return makePtr<SunRasterEncoder>();
|
||||
}
|
||||
|
||||
SunRasterEncoder::~SunRasterEncoder()
|
||||
|
@ -108,7 +108,7 @@ int TiffDecoder::normalizeChannelsNumber(int channels) const
|
||||
|
||||
ImageDecoder TiffDecoder::newDecoder() const
|
||||
{
|
||||
return new TiffDecoder;
|
||||
return makePtr<TiffDecoder>();
|
||||
}
|
||||
|
||||
bool TiffDecoder::readHeader()
|
||||
@ -400,7 +400,7 @@ TiffEncoder::~TiffEncoder()
|
||||
|
||||
ImageEncoder TiffEncoder::newEncoder() const
|
||||
{
|
||||
return new TiffEncoder;
|
||||
return makePtr<TiffEncoder>();
|
||||
}
|
||||
|
||||
bool TiffEncoder::isFormatSupported( int depth ) const
|
||||
|
@ -90,7 +90,7 @@ bool WebPDecoder::checkSignature(const String & signature) const
|
||||
|
||||
ImageDecoder WebPDecoder::newDecoder() const
|
||||
{
|
||||
return new WebPDecoder;
|
||||
return makePtr<WebPDecoder>();
|
||||
}
|
||||
|
||||
bool WebPDecoder::readHeader()
|
||||
@ -201,7 +201,7 @@ WebPEncoder::~WebPEncoder() { }
|
||||
|
||||
ImageEncoder WebPEncoder::newEncoder() const
|
||||
{
|
||||
return new WebPEncoder();
|
||||
return makePtr<WebPEncoder>();
|
||||
}
|
||||
|
||||
bool WebPEncoder::write(const Mat& img, const std::vector<int>& params)
|
||||
|
@ -58,35 +58,35 @@ struct ImageCodecInitializer
|
||||
{
|
||||
ImageCodecInitializer()
|
||||
{
|
||||
decoders.push_back( new BmpDecoder );
|
||||
encoders.push_back( new BmpEncoder );
|
||||
decoders.push_back( makePtr<BmpDecoder>() );
|
||||
encoders.push_back( makePtr<BmpEncoder>() );
|
||||
#ifdef HAVE_JPEG
|
||||
decoders.push_back( new JpegDecoder );
|
||||
encoders.push_back( new JpegEncoder );
|
||||
decoders.push_back( makePtr<JpegDecoder>() );
|
||||
encoders.push_back( makePtr<JpegEncoder>() );
|
||||
#endif
|
||||
#ifdef HAVE_WEBP
|
||||
decoders.push_back( new WebPDecoder );
|
||||
encoders.push_back( new WebPEncoder );
|
||||
decoders.push_back( makePtr<WebPDecoder>() );
|
||||
encoders.push_back( makePtr<WebPEncoder>() );
|
||||
#endif
|
||||
decoders.push_back( new SunRasterDecoder );
|
||||
encoders.push_back( new SunRasterEncoder );
|
||||
decoders.push_back( new PxMDecoder );
|
||||
encoders.push_back( new PxMEncoder );
|
||||
decoders.push_back( makePtr<SunRasterDecoder>() );
|
||||
encoders.push_back( makePtr<SunRasterEncoder>() );
|
||||
decoders.push_back( makePtr<PxMDecoder>() );
|
||||
encoders.push_back( makePtr<PxMEncoder>() );
|
||||
#ifdef HAVE_TIFF
|
||||
decoders.push_back( new TiffDecoder );
|
||||
decoders.push_back( makePtr<TiffDecoder>() );
|
||||
#endif
|
||||
encoders.push_back( new TiffEncoder );
|
||||
encoders.push_back( makePtr<TiffEncoder>() );
|
||||
#ifdef HAVE_PNG
|
||||
decoders.push_back( new PngDecoder );
|
||||
encoders.push_back( new PngEncoder );
|
||||
decoders.push_back( makePtr<PngDecoder>() );
|
||||
encoders.push_back( makePtr<PngEncoder>() );
|
||||
#endif
|
||||
#ifdef HAVE_JASPER
|
||||
decoders.push_back( new Jpeg2KDecoder );
|
||||
encoders.push_back( new Jpeg2KEncoder );
|
||||
decoders.push_back( makePtr<Jpeg2KDecoder>() );
|
||||
encoders.push_back( makePtr<Jpeg2KEncoder>() );
|
||||
#endif
|
||||
#ifdef HAVE_OPENEXR
|
||||
decoders.push_back( new ExrDecoder );
|
||||
encoders.push_back( new ExrEncoder );
|
||||
decoders.push_back( makePtr<ExrDecoder>() );
|
||||
encoders.push_back( makePtr<ExrEncoder>() );
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -198,7 +198,7 @@ imread_( const String& filename, int flags, int hdrtype, Mat* mat=0 )
|
||||
Mat temp, *data = &temp;
|
||||
|
||||
ImageDecoder decoder = findDecoder(filename);
|
||||
if( decoder.empty() )
|
||||
if( !decoder )
|
||||
return 0;
|
||||
decoder->setSource(filename);
|
||||
if( !decoder->readHeader() )
|
||||
@ -269,7 +269,7 @@ static bool imwrite_( const String& filename, const Mat& image,
|
||||
CV_Assert( image.channels() == 1 || image.channels() == 3 || image.channels() == 4 );
|
||||
|
||||
ImageEncoder encoder = findEncoder( filename );
|
||||
if( encoder.empty() )
|
||||
if( !encoder )
|
||||
CV_Error( CV_StsError, "could not find a writer for the specified extension" );
|
||||
|
||||
if( !encoder->isFormatSupported(image.depth()) )
|
||||
@ -309,7 +309,7 @@ imdecode_( const Mat& buf, int flags, int hdrtype, Mat* mat=0 )
|
||||
String filename;
|
||||
|
||||
ImageDecoder decoder = findDecoder(buf);
|
||||
if( decoder.empty() )
|
||||
if( !decoder )
|
||||
return 0;
|
||||
|
||||
if( !decoder->setSource(buf) )
|
||||
@ -409,7 +409,7 @@ bool imencode( const String& ext, InputArray _image,
|
||||
CV_Assert( channels == 1 || channels == 3 || channels == 4 );
|
||||
|
||||
ImageEncoder encoder = findEncoder( ext );
|
||||
if( encoder.empty() )
|
||||
if( !encoder )
|
||||
CV_Error( CV_StsError, "could not find encoder for the specified extension" );
|
||||
|
||||
if( !encoder->isFormatSupported(image.depth()) )
|
||||
|
@ -71,8 +71,8 @@ void CV_FramecountTest::run(int)
|
||||
{
|
||||
string file_path = src_dir+"video/big_buck_bunny."+ext[i];
|
||||
|
||||
cap = cvCreateFileCapture(file_path.c_str());
|
||||
if (cap.empty())
|
||||
cap.reset(cvCreateFileCapture(file_path.c_str()));
|
||||
if (!cap)
|
||||
{
|
||||
ts->printf(cvtest::TS::LOG, "\nFile information (video %d): \n\nName: big_buck_bunny.%s\nFAILED\n\n", i+1, ext[i].c_str());
|
||||
ts->printf(cvtest::TS::LOG, "Error: cannot read source video file.\n");
|
||||
|
@ -656,7 +656,7 @@ public:
|
||||
Point dstOfs = Point(0,0),
|
||||
bool isolated = false);
|
||||
//! returns true if the filter is separable
|
||||
bool isSeparable() const { return (const BaseFilter*)filter2D == 0; }
|
||||
bool isSeparable() const { return !filter2D; }
|
||||
//! returns the number
|
||||
int remainingInputRows() const;
|
||||
int remainingOutputRows() const;
|
||||
|
@ -330,5 +330,5 @@ namespace
|
||||
|
||||
cv::Ptr<cv::CLAHE> cv::createCLAHE(double clipLimit, cv::Size tileGridSize)
|
||||
{
|
||||
return new CLAHE_Impl(clipLimit, tileGridSize.width, tileGridSize.height);
|
||||
return makePtr<CLAHE_Impl>(clipLimit, tileGridSize.width, tileGridSize.height);
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user