made several minor fixes as pointed out by Andrey

pull/482/head
Vadim Pisarevsky 12 years ago
parent 77d647b675
commit 78402bf596
  1. 5
      modules/core/src/matrix.cpp
  2. 7
      modules/imgproc/perf/perf_houghLines.cpp
  3. 2
      modules/imgproc/src/cornersubpix.cpp
  4. 185
      modules/imgproc/src/distransform.cpp
  5. 9
      modules/imgproc/src/hough.cpp
  6. 8
      modules/imgproc/src/samplers.cpp
  7. 7
      modules/imgproc/src/segmentation.cpp

@ -1969,6 +1969,11 @@ static TransposeInplaceFunc transposeInplaceTab[] =
void cv::transpose( InputArray _src, OutputArray _dst )
{
Mat src = _src.getMat();
if( src.empty() )
{
_dst.release();
return;
}
size_t esz = src.elemSize();
CV_Assert( src.dims <= 2 && esz <= (size_t)32 );

@ -31,12 +31,11 @@ PERF_TEST_P(Image_RhoStep_ThetaStep_Threshold, HoughLines,
Canny(image, image, 0, 0);
Mat lines_t, lines;
Mat lines;
declare.time(60);
TEST_CYCLE() HoughLines(image, lines_t, rhoStep, thetaStep, threshold);
TEST_CYCLE() HoughLines(image, lines, rhoStep, thetaStep, threshold);
if( !lines_t.empty() )
transpose(lines_t, lines);
transpose(lines, lines);
SANITY_CHECK(lines);
}

@ -60,7 +60,7 @@ void cv::cornerSubPix( InputArray _image, InputOutputArray _corners,
return;
CV_Assert( win.width > 0 && win.height > 0 );
CV_Assert( src.cols >= win_w + 4 && src.rows >= win_h + 4 );
CV_Assert( src.cols >= win.width*2 + 5 && src.rows >= win.height*2 + 5 );
CV_Assert( src.channels() == 1 );
Mat maskm(win_h, win_w, CV_32F), subpix_buf(win_h+2, win_w+2, CV_32F);

@ -592,6 +592,88 @@ trueDistTrans( const Mat& src, Mat& dst )
cv::parallel_for(cv::BlockedRange(0, m), cv::DTRowInvoker(&dst, sqr_tab, inv_tab));
}
/****************************************************************************************\
Non-inplace and Inplace 8u->8u Distance Transform for CityBlock (a.k.a. L1) metric
(C) 2006 by Jay Stavinzky.
\****************************************************************************************/
//BEGIN ATS ADDITION
// 8-bit grayscale distance transform function
static void
distanceATS_L1_8u( const Mat& src, Mat& dst )
{
int width = src.cols, height = src.rows;
int a;
uchar lut[256];
int x, y;
const uchar *sbase = src.data;
uchar *dbase = dst.data;
int srcstep = (int)src.step;
int dststep = (int)dst.step;
CV_Assert( src.type() == CV_8UC1 && dst.type() == CV_8UC1 );
CV_Assert( src.size() == dst.size() );
////////////////////// forward scan ////////////////////////
for( x = 0; x < 256; x++ )
lut[x] = CV_CAST_8U(x+1);
//init first pixel to max (we're going to be skipping it)
dbase[0] = (uchar)(sbase[0] == 0 ? 0 : 255);
//first row (scan west only, skip first pixel)
for( x = 1; x < width; x++ )
dbase[x] = (uchar)(sbase[x] == 0 ? 0 : lut[dbase[x-1]]);
for( y = 1; y < height; y++ )
{
sbase += srcstep;
dbase += dststep;
//for left edge, scan north only
a = sbase[0] == 0 ? 0 : lut[dbase[-dststep]];
dbase[0] = (uchar)a;
for( x = 1; x < width; x++ )
{
a = sbase[x] == 0 ? 0 : lut[MIN(a, dbase[x - dststep])];
dbase[x] = (uchar)a;
}
}
////////////////////// backward scan ///////////////////////
a = dbase[width-1];
// do last row east pixel scan here (skip bottom right pixel)
for( x = width - 2; x >= 0; x-- )
{
a = lut[a];
dbase[x] = (uchar)(CV_CALC_MIN_8U(a, dbase[x]));
}
// right edge is the only error case
for( y = height - 2; y >= 0; y-- )
{
dbase -= dststep;
// do right edge
a = lut[dbase[width-1+dststep]];
dbase[width-1] = (uchar)(MIN(a, dbase[width-1]));
for( x = width - 2; x >= 0; x-- )
{
int b = dbase[x+dststep];
a = lut[MIN(a, b)];
dbase[x] = (uchar)(MIN(a, dbase[x]));
}
}
}
//END ATS ADDITION
}
@ -599,11 +681,19 @@ trueDistTrans( const Mat& src, Mat& dst )
void cv::distanceTransform( InputArray _src, OutputArray _dst, OutputArray _labels,
int distType, int maskSize, int labelType )
{
Mat src = _src.getMat();
_dst.create( src.size(), CV_32F );
Mat dst = _dst.getMat(), labels;
Mat src = _src.getMat(), dst = _dst.getMat(), labels;
bool need_labels = _labels.needed();
CV_Assert( src.type() == CV_8U );
if( dst.size == src.size && dst.type() == CV_8U && !need_labels && distType == CV_DIST_L1 )
{
distanceATS_L1_8u(src, dst);
return;
}
_dst.create( src.size(), CV_32F );
dst = _dst.getMat();
if( need_labels )
{
CV_Assert( labelType == DIST_LABEL_PIXEL || labelType == DIST_LABEL_CCOMP );
@ -682,98 +772,15 @@ void cv::distanceTransform( InputArray _src, OutputArray _dst,
}
/****************************************************************************************\
Non-inplace and Inplace 8u->8u Distance Transform for CityBlock (a.k.a. L1) metric
(C) 2006 by Jay Stavinzky.
\****************************************************************************************/
//BEGIN ATS ADDITION
/* 8-bit grayscale distance transform function */
static void
icvDistanceATS_L1_8u( const cv::Mat& src, cv::Mat& dst )
{
int width = src.cols, height = src.rows;
int a;
uchar lut[256];
int x, y;
const uchar *sbase = src.data;
uchar *dbase = dst.data;
int srcstep = (int)src.step;
int dststep = (int)dst.step;
CV_Assert( src.type() == CV_8UC1 && dst.type() == CV_8UC1 );
CV_Assert( src.size() == dst.size() );
////////////////////// forward scan ////////////////////////
for( x = 0; x < 256; x++ )
lut[x] = CV_CAST_8U(x+1);
//init first pixel to max (we're going to be skipping it)
dbase[0] = (uchar)(sbase[0] == 0 ? 0 : 255);
//first row (scan west only, skip first pixel)
for( x = 1; x < width; x++ )
dbase[x] = (uchar)(sbase[x] == 0 ? 0 : lut[dbase[x-1]]);
for( y = 1; y < height; y++ )
{
sbase += srcstep;
dbase += dststep;
//for left edge, scan north only
a = sbase[0] == 0 ? 0 : lut[dbase[-dststep]];
dbase[0] = (uchar)a;
for( x = 1; x < width; x++ )
{
a = sbase[x] == 0 ? 0 : lut[MIN(a, dbase[x - dststep])];
dbase[x] = (uchar)a;
}
}
////////////////////// backward scan ///////////////////////
a = dbase[width-1];
// do last row east pixel scan here (skip bottom right pixel)
for( x = width - 2; x >= 0; x-- )
{
a = lut[a];
dbase[x] = (uchar)(CV_CALC_MIN_8U(a, dbase[x]));
}
// right edge is the only error case
for( y = height - 2; y >= 0; y-- )
{
dbase -= dststep;
// do right edge
a = lut[dbase[width-1+dststep]];
dbase[width-1] = (uchar)(MIN(a, dbase[width-1]));
for( x = width - 2; x >= 0; x-- )
{
int b = dbase[x+dststep];
a = lut[MIN(a, b)];
dbase[x] = (uchar)(MIN(a, dbase[x]));
}
}
}
//END ATS ADDITION
CV_IMPL void
cvDistTransform( const void* srcarr, void* dstarr,
int distType, int maskSize,
const float * /*mask*/,
void* labelsarr, int labelType )
{
cv::Mat src = cv::cvarrToMat(srcarr), dst = cv::cvarrToMat(dstarr);
cv::Mat labels = cv::cvarrToMat(labelsarr);
if( !labelsarr && distType == CV_DIST_L1 && dst.type() == CV_8U )
icvDistanceATS_L1_8u( src, dst );
cv::Mat src = cv::cvarrToMat(srcarr);
const cv::Mat dst = cv::cvarrToMat(dstarr);
const cv::Mat labels = cv::cvarrToMat(labelsarr);
cv::distanceTransform(src, dst, labelsarr ? cv::_OutputArray(labels) : cv::_OutputArray(),
distType, maskSize, labelType);

@ -7,10 +7,11 @@
// copy or use the software.
//
//
// Intel License Agreement
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000, Intel Corporation, all rights reserved.
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
@ -23,7 +24,7 @@
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of Intel Corporation may not be used to endorse or promote products
// * 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
@ -398,8 +399,8 @@ HoughLinesProbabilistic( Mat& image,
for( int n = 0; n < numangle; n++ )
{
trigtab[n*2] = (float)(cos(n*theta) * irho);
trigtab[n*2+1] = (float)(sin(n*theta) * irho);
trigtab[n*2] = (float)(cos((double)n*theta) * irho);
trigtab[n*2+1] = (float)(sin((double)n*theta) * irho);
}
const float* ttab = &trigtab[0];
uchar* mdata0 = mask.data;

@ -7,7 +7,7 @@
// copy or use the software.
//
//
// License Agreement
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000, Intel Corporation, all rights reserved.
@ -298,7 +298,8 @@ void cv::getRectSubPix( InputArray _image, Size patchSize, Point2f center,
CV_IMPL void
cvGetRectSubPix( const void* srcarr, void* dstarr, CvPoint2D32f center )
{
cv::Mat src = cv::cvarrToMat(srcarr), dst = cv::cvarrToMat(dstarr);
cv::Mat src = cv::cvarrToMat(srcarr);
const cv::Mat dst = cv::cvarrToMat(dstarr);
CV_Assert( src.channels() == dst.channels() );
cv::getRectSubPix(src, dst.size(), center, dst, dst.type());
@ -308,7 +309,8 @@ cvGetRectSubPix( const void* srcarr, void* dstarr, CvPoint2D32f center )
CV_IMPL void
cvGetQuadrangleSubPix( const void* srcarr, void* dstarr, const CvMat* mat )
{
cv::Mat src = cv::cvarrToMat(srcarr), dst = cv::cvarrToMat(dstarr), m = cv::cvarrToMat(mat);
cv::Mat src = cv::cvarrToMat(srcarr), m = cv::cvarrToMat(mat);
const cv::Mat dst = cv::cvarrToMat(dstarr);
cv::Size win_size = dst.size();
double matrix[6];
cv::Mat M(2, 3, CV_64F, matrix);

@ -7,10 +7,11 @@
// copy or use the software.
//
//
// Intel License Agreement
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000, Intel Corporation, all rights reserved.
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
@ -23,7 +24,7 @@
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of Intel Corporation may not be used to endorse or promote products
// * 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
@ -529,7 +530,7 @@ cvPyrMeanShiftFiltering( const CvArr* srcarr, CvArr* dstarr,
CvTermCriteria termcrit )
{
cv::Mat src = cv::cvarrToMat(srcarr);
cv::Mat dst = cv::cvarrToMat(dstarr);
const cv::Mat dst = cv::cvarrToMat(dstarr);
cv::pyrMeanShiftFiltering(src, dst, sp0, sr, max_level, termcrit);
}

Loading…
Cancel
Save