Merge pull request #5335 from Dikay900:ports_to_master

This commit is contained in:
Alexander Alekhin 2015-09-18 11:06:07 +00:00
commit af0942c78f
14 changed files with 100 additions and 52 deletions

View File

@ -56,6 +56,8 @@ foreach(mod ${OPENCV_MODULES_BUILD} ${OPENCV_MODULES_DISABLED_USER} ${OPENCV_MOD
if(HAVE_${mod})
unset(HAVE_${mod} CACHE)
endif()
unset(OPENCV_MODULE_${mod}_DEPS CACHE)
unset(OPENCV_MODULE_${mod}_DEPS_EXT CACHE)
unset(OPENCV_MODULE_${mod}_REQ_DEPS CACHE)
unset(OPENCV_MODULE_${mod}_OPT_DEPS CACHE)
unset(OPENCV_MODULE_${mod}_PRIVATE_REQ_DEPS CACHE)

View File

@ -352,6 +352,7 @@ CV_IMPL CvString
cvMemStorageAllocString( CvMemStorage* storage, const char* ptr, int len )
{
CvString str;
memset(&str, 0, sizeof(CvString));
str.len = len >= 0 ? len : (int)strlen(ptr);
str.ptr = (char*)cvMemStorageAlloc( storage, str.len + 1 );

View File

@ -491,6 +491,7 @@ class Core_SeqBaseTest : public Core_DynStructBaseTest
{
public:
Core_SeqBaseTest();
virtual ~Core_SeqBaseTest();
void clear();
void run( int );
@ -501,11 +502,14 @@ protected:
int test_seq_ops( int iters );
};
Core_SeqBaseTest::Core_SeqBaseTest()
{
}
Core_SeqBaseTest::~Core_SeqBaseTest()
{
clear();
}
void Core_SeqBaseTest::clear()
{
@ -1206,6 +1210,7 @@ class Core_SetTest : public Core_DynStructBaseTest
{
public:
Core_SetTest();
virtual ~Core_SetTest();
void clear();
void run( int );
@ -1219,6 +1224,10 @@ Core_SetTest::Core_SetTest()
{
}
Core_SetTest::~Core_SetTest()
{
clear();
}
void Core_SetTest::clear()
{
@ -1417,6 +1426,7 @@ class Core_GraphTest : public Core_DynStructBaseTest
{
public:
Core_GraphTest();
virtual ~Core_GraphTest();
void clear();
void run( int );
@ -1430,6 +1440,10 @@ Core_GraphTest::Core_GraphTest()
{
}
Core_GraphTest::~Core_GraphTest()
{
clear();
}
void Core_GraphTest::clear()
{
@ -2042,6 +2056,8 @@ void Core_GraphScanTest::run( int )
CV_TS_SEQ_CHECK_CONDITION( vtx_count == 0 && edge_count == 0,
"Not every vertex/edge has been visited" );
update_progressbar();
cvReleaseGraphScanner( &scanner );
}
// for a random graph the test just checks that every graph vertex and
@ -2106,8 +2122,6 @@ void Core_GraphScanTest::run( int )
catch(int)
{
}
cvReleaseGraphScanner( &scanner );
}

View File

@ -60,7 +60,7 @@ static void writeMatInBin( const Mat& mat, const string& filename )
fwrite( (void*)&mat.rows, sizeof(int), 1, f );
fwrite( (void*)&mat.cols, sizeof(int), 1, f );
fwrite( (void*)&type, sizeof(int), 1, f );
int dataSize = (int)(mat.step * mat.rows * mat.channels());
int dataSize = (int)(mat.step * mat.rows);
fwrite( (void*)&dataSize, sizeof(int), 1, f );
fwrite( (void*)mat.ptr(), 1, dataSize, f );
fclose(f);
@ -82,13 +82,14 @@ static Mat readMatFromBin( const string& filename )
int step = dataSize / rows / CV_ELEM_SIZE(type);
CV_Assert(step >= cols);
Mat m = Mat(rows, step, type).colRange(0, cols);
Mat returnMat = Mat(rows, step, type).colRange(0, cols);
size_t elements_read = fread( m.ptr(), 1, dataSize, f );
size_t elements_read = fread( returnMat.ptr(), 1, dataSize, f );
CV_Assert(elements_read == (size_t)(dataSize));
fclose(f);
return m;
return returnMat;
}
return Mat();
}

View File

@ -67,13 +67,13 @@ protected:
virtual void run( int start_from );
virtual void createModel( const Mat& data ) = 0;
virtual int findNeighbors( Mat& points, Mat& neighbors ) = 0;
virtual int checkGetPoins( const Mat& data );
virtual int checkGetPoints( const Mat& data );
virtual int checkFindBoxed();
virtual int checkFind( const Mat& data );
virtual void releaseModel() = 0;
};
int NearestNeighborTest::checkGetPoins( const Mat& )
int NearestNeighborTest::checkGetPoints( const Mat& )
{
return cvtest::TS::OK;
}
@ -127,11 +127,11 @@ int NearestNeighborTest::checkFind( const Mat& data )
void NearestNeighborTest::run( int /*start_from*/ ) {
int code = cvtest::TS::OK, tempCode;
Mat desc( featuresCount, dims, CV_32FC1 );
randu( desc, Scalar(minValue), Scalar(maxValue) );
ts->get_rng().fill( desc, RNG::UNIFORM, minValue, maxValue );
createModel( desc );
tempCode = checkGetPoins( desc );
tempCode = checkGetPoints( desc );
if( tempCode != cvtest::TS::OK )
{
ts->printf( cvtest::TS::LOG, "bad accuracy of GetPoints \n" );
@ -161,7 +161,7 @@ void NearestNeighborTest::run( int /*start_from*/ ) {
class CV_FlannTest : public NearestNeighborTest
{
public:
CV_FlannTest() {}
CV_FlannTest() : NearestNeighborTest(), index(NULL) { }
protected:
void createIndex( const Mat& data, const IndexParams& params );
int knnSearch( Mat& points, Mat& neighbors );
@ -172,6 +172,9 @@ protected:
void CV_FlannTest::createIndex( const Mat& data, const IndexParams& params )
{
// release previously allocated index
releaseModel();
index = new Index( data, params );
}
@ -238,7 +241,11 @@ int CV_FlannTest::radiusSearch( Mat& points, Mat& neighbors )
void CV_FlannTest::releaseModel()
{
delete index;
if (index)
{
delete index;
index = NULL;
}
}
//---------------------------------------

View File

@ -377,6 +377,7 @@ private:
// evaluate kdtree for all parameter combinations
for (size_t i = 0; i < FLANN_ARRAY_LEN(testTrees); ++i) {
CostData cost;
cost.params["algorithm"] = FLANN_INDEX_KDTREE;
cost.params["trees"] = testTrees[i];
evaluate_kdtree(cost);

View File

@ -441,6 +441,8 @@ public:
}
root_ = pool_.allocate<KMeansNode>();
std::memset(root_, 0, sizeof(KMeansNode));
computeNodeStatistics(root_, indices_, (int)size_);
computeClustering(root_, indices_, (int)size_, branching_,0);
}
@ -864,11 +866,11 @@ private:
variance -= distance_(centers[c], ZeroIterator<ElementType>(), veclen_);
node->childs[c] = pool_.allocate<KMeansNode>();
std::memset(node->childs[c], 0, sizeof(KMeansNode));
node->childs[c]->radius = radiuses[c];
node->childs[c]->pivot = centers[c];
node->childs[c]->variance = variance;
node->childs[c]->mean_radius = mean_radius;
node->childs[c]->indices = NULL;
computeClustering(node->childs[c],indices+start, end-start, branching, level+1);
start=end;
}

View File

@ -2232,6 +2232,7 @@ void cv::polylines(InputOutputArray _img, InputArrayOfArrays pts,
Mat p = pts.getMat(manyContours ? i : -1);
if( p.total() == 0 )
{
ptsptr[i] = NULL;
npts[i] = 0;
continue;
}

View File

@ -184,24 +184,28 @@ static void rotatingCalipers( const Point2f* points, int n, int mode, float* out
/* compute cosine of angle between calipers side and polygon edge */
/* dp - dot product */
float dp0 = base_a * vect[seq[0]].x + base_b * vect[seq[0]].y;
float dp1 = -base_b * vect[seq[1]].x + base_a * vect[seq[1]].y;
float dp2 = -base_a * vect[seq[2]].x - base_b * vect[seq[2]].y;
float dp3 = base_b * vect[seq[3]].x - base_a * vect[seq[3]].y;
float dp[4] = {
+base_a * vect[seq[0]].x + base_b * vect[seq[0]].y,
-base_b * vect[seq[1]].x + base_a * vect[seq[1]].y,
-base_a * vect[seq[2]].x - base_b * vect[seq[2]].y,
+base_b * vect[seq[3]].x - base_a * vect[seq[3]].y,
};
float cosalpha = dp0 * inv_vect_length[seq[0]];
float maxcos = cosalpha;
float maxcos = dp[0] * inv_vect_length[seq[0]];
/* number of calipers edges, that has minimal angle with edge */
int main_element = 0;
/* choose minimal angle */
cosalpha = dp1 * inv_vect_length[seq[1]];
maxcos = (cosalpha > maxcos) ? (main_element = 1, cosalpha) : maxcos;
cosalpha = dp2 * inv_vect_length[seq[2]];
maxcos = (cosalpha > maxcos) ? (main_element = 2, cosalpha) : maxcos;
cosalpha = dp3 * inv_vect_length[seq[3]];
maxcos = (cosalpha > maxcos) ? (main_element = 3, cosalpha) : maxcos;
for ( i = 1; i < 4; ++i )
{
float cosalpha = dp[i] * inv_vect_length[seq[i]];
if (cosalpha > maxcos)
{
main_element = i;
maxcos = cosalpha;
}
}
/*rotate calipers*/
{

View File

@ -548,7 +548,7 @@ void referenceRGB2YUV(const Mat& rgb, Mat& yuv, RGBreader* rgbReader, YUVwriter*
struct ConversionYUV
{
ConversionYUV( const int code )
explicit ConversionYUV( const int code )
{
yuvReader_ = YUVreader :: getReader(code);
yuvWriter_ = YUVwriter :: getWriter(code);
@ -557,6 +557,24 @@ struct ConversionYUV
grayWriter_ = GRAYwriter:: getWriter(code);
}
~ConversionYUV()
{
if (yuvReader_)
delete yuvReader_;
if (yuvWriter_)
delete yuvWriter_;
if (rgbReader_)
delete rgbReader_;
if (rgbWriter_)
delete rgbWriter_;
if (grayWriter_)
delete grayWriter_;
}
int getDcn()
{
return (rgbWriter_ != 0) ? rgbWriter_->channels() : ((grayWriter_ != 0) ? grayWriter_->channels() : yuvWriter_->channels());

View File

@ -508,6 +508,8 @@ _exit_:
comp[7] = new_val.val[2];
#endif
comp[8] = 0;
cvReleaseMemStorage(&st);
}

View File

@ -1377,12 +1377,17 @@ TEST(Imgproc_cvWarpAffine, regression)
IplImage* src = cvCreateImage(cvSize(100, 100), IPL_DEPTH_8U, 1);
IplImage* dst = cvCreateImage(cvSize(100, 100), IPL_DEPTH_8U, 1);
cvZero(src);
float m[6];
CvMat M = cvMat( 2, 3, CV_32F, m );
int w = src->width;
int h = src->height;
cv2DRotationMatrix(cvPoint2D32f(w*0.5f, h*0.5f), 45.0, 1.0, &M);
cvWarpAffine(src, dst, &M);
cvReleaseImage(&src);
cvReleaseImage(&dst);
}
TEST(Imgproc_fitLine_vector_3d, regression)

View File

@ -651,8 +651,7 @@ private:
};
CV_Remap_Test::CV_Remap_Test() :
CV_ImageWarpBaseTest(), mapx(), mapy(),
borderType(-1), borderValue()
CV_ImageWarpBaseTest(), borderType(-1)
{
funcs[0] = &CV_Remap_Test::remap_nearest;
funcs[1] = &CV_Remap_Test::remap_generic;
@ -673,7 +672,7 @@ void CV_Remap_Test::generate_test_data()
// generating the mapx, mapy matrices
static const int mapx_types[] = { CV_16SC2, CV_32FC1, CV_32FC2 };
mapx.create(dst.size(), mapx_types[rng.uniform(0, sizeof(mapx_types) / sizeof(int))]);
mapy = Mat();
mapy.release();
const int n = std::min(std::min(src.cols, src.rows) / 10 + 1, 2);
float _n = 0; //static_cast<float>(-n);
@ -700,7 +699,7 @@ void CV_Remap_Test::generate_test_data()
{
MatIterator_<ushort> begin_y = mapy.begin<ushort>(), end_y = mapy.end<ushort>();
for ( ; begin_y != end_y; ++begin_y)
begin_y[0] = static_cast<short>(rng.uniform(0, 1024));
*begin_y = static_cast<ushort>(rng.uniform(0, 1024));
}
break;
@ -708,7 +707,7 @@ void CV_Remap_Test::generate_test_data()
{
MatIterator_<short> begin_y = mapy.begin<short>(), end_y = mapy.end<short>();
for ( ; begin_y != end_y; ++begin_y)
begin_y[0] = static_cast<short>(rng.uniform(0, 1024));
*begin_y = static_cast<short>(rng.uniform(0, 1024));
}
break;
}
@ -725,8 +724,8 @@ void CV_Remap_Test::generate_test_data()
MatIterator_<float> begin_y = mapy.begin<float>();
for ( ; begin_x != end_x; ++begin_x, ++begin_y)
{
begin_x[0] = rng.uniform(_n, fscols);
begin_y[0] = rng.uniform(_n, fsrows);
*begin_x = rng.uniform(_n, fscols);
*begin_y = rng.uniform(_n, fsrows);
}
}
break;
@ -794,23 +793,6 @@ void CV_Remap_Test::prepare_test_data_for_reference_func()
{
CV_ImageWarpBaseTest::prepare_test_data_for_reference_func();
convert_maps();
/*
const int ksize = 3;
Mat kernel = getStructuringElement(CV_MOP_ERODE, Size(ksize, ksize));
Mat mask(src.size(), CV_8UC1, Scalar::all(255)), dst_mask;
cv::erode(src, erode_src, kernel);
cv::erode(mask, dst_mask, kernel, Point(-1, -1), 1, BORDER_CONSTANT, Scalar::all(0));
bitwise_not(dst_mask, mask);
src.copyTo(erode_src, mask);
dst_mask.release();
mask = Scalar::all(0);
kernel = getStructuringElement(CV_MOP_DILATE, kernel.size());
cv::dilate(src, dilate_src, kernel);
cv::dilate(mask, dst_mask, kernel, Point(-1, -1), 1, BORDER_CONSTANT, Scalar::all(255));
src.copyTo(dilate_src, dst_mask);
dst_mask.release();
*/
}
void CV_Remap_Test::run_reference_func()

View File

@ -243,7 +243,7 @@ CvGBTrees::train( const CvMat* _train_data, int _tflag,
for (int i=1; i<n; ++i)
{
int k = 0;
while ((int(orig_response->data.fl[i]) - class_labels->data.i[k]) && (k<j))
while ((k<j) && (int(orig_response->data.fl[i]) - class_labels->data.i[k]))
k++;
if (k == j)
{
@ -1274,13 +1274,18 @@ CvGBTrees::calc_error( CvMLData* _data, int type, std::vector<float> *resp )
return -FLT_MAX;
float* pred_resp = 0;
bool needsFreeing = false;
if (resp)
{
resp->resize(n);
pred_resp = &((*resp)[0]);
}
else
{
pred_resp = new float[n];
needsFreeing = true;
}
Sample_predictor predictor = Sample_predictor(this, pred_resp, _data->get_values(),
_data->get_missing(), _sample_idx);
@ -1313,6 +1318,9 @@ CvGBTrees::calc_error( CvMLData* _data, int type, std::vector<float> *resp )
err = err / (float)n;
}
if (needsFreeing)
delete[]pred_resp;
return err;
}