added function cv::findNonZero (patch #2205)
This commit is contained in:
parent
d72cc06b96
commit
8441cf700d
@ -2102,6 +2102,9 @@ CV_EXPORTS_W void LUT(InputArray src, InputArray lut, OutputArray dst,
|
||||
CV_EXPORTS_AS(sumElems) Scalar sum(InputArray src);
|
||||
//! computes the number of nonzero array elements
|
||||
CV_EXPORTS_W int countNonZero( InputArray src );
|
||||
//! returns the list of locations of non-zero pixels
|
||||
CV_EXPORTS_W void findNonZero( InputArray src, OutputArray idx );
|
||||
|
||||
//! computes mean value of selected array elements
|
||||
CV_EXPORTS_W Scalar mean(InputArray src, InputArray mask=noArray());
|
||||
//! computes mean value and standard deviation of all or selected array elements
|
||||
|
@ -1904,6 +1904,28 @@ void cv::batchDistance( InputArray _src1, InputArray _src2,
|
||||
}
|
||||
|
||||
|
||||
void cv::findNonZero( InputArray _src, OutputArray _idx )
|
||||
{
|
||||
Mat src = _src.getMat();
|
||||
CV_Assert( src.type() == CV_8UC1 );
|
||||
int n = countNonZero(src);
|
||||
if( _idx.kind() == _InputArray::MAT && !_idx.getMatRef().isContinuous() )
|
||||
_idx.release();
|
||||
_idx.create(n, 1, CV_32SC2);
|
||||
Mat idx = _idx.getMat();
|
||||
CV_Assert(idx.isContinuous());
|
||||
Point* idx_ptr = (Point*)idx.data;
|
||||
|
||||
for( int i = 0; i < src.rows; i++ )
|
||||
{
|
||||
const uchar* bin_ptr = src.ptr(i);
|
||||
for( int j = 0; j < src.cols; j++ )
|
||||
if( bin_ptr[j] )
|
||||
*idx_ptr++ = Point(j, i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
CV_IMPL CvScalar cvSum( const CvArr* srcarr )
|
||||
{
|
||||
cv::Scalar sum = cv::sum(cv::cvarrToMat(srcarr, false, true, 1));
|
||||
|
Loading…
x
Reference in New Issue
Block a user