本文整理汇总了C++中CV_MAT_CN函数的典型用法代码示例。如果您正苦于以下问题:C++ CV_MAT_CN函数的具体用法?C++ CV_MAT_CN怎么用?C++ CV_MAT_CN使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了CV_MAT_CN函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: cvInitUndistortMap
CV_IMPL void
cvInitUndistortMap( const CvMat* A, const CvMat* dist_coeffs,
CvArr* mapxarr, CvArr* mapyarr )
{
uchar* buffer = 0;
CV_FUNCNAME( "cvInitUndistortMap" );
__BEGIN__;
float a[9], k[4];
int coi1 = 0, coi2 = 0;
CvMat mapxstub, *_mapx = (CvMat*)mapxarr;
CvMat mapystub, *_mapy = (CvMat*)mapyarr;
float *mapx, *mapy;
CvMat _a = cvMat( 3, 3, CV_32F, a ), _k;
int mapxstep, mapystep;
int u, v;
float u0, v0, fx, fy, _fx, _fy, k1, k2, p1, p2;
CvSize size;
CV_CALL( _mapx = cvGetMat( _mapx, &mapxstub, &coi1 ));
CV_CALL( _mapy = cvGetMat( _mapy, &mapystub, &coi2 ));
if( coi1 != 0 || coi2 != 0 )
CV_ERROR( CV_BadCOI, "The function does not support COI" );
if( CV_MAT_TYPE(_mapx->type) != CV_32FC1 )
CV_ERROR( CV_StsUnsupportedFormat, "Both maps must have 32fC1 type" );
if( !CV_ARE_TYPES_EQ( _mapx, _mapy ))
CV_ERROR( CV_StsUnmatchedFormats, "" );
if( !CV_ARE_SIZES_EQ( _mapx, _mapy ))
CV_ERROR( CV_StsUnmatchedSizes, "" );
if( !CV_IS_MAT(A) || A->rows != 3 || A->cols != 3 ||
CV_MAT_TYPE(A->type) != CV_32FC1 && CV_MAT_TYPE(A->type) != CV_64FC1 )
CV_ERROR( CV_StsBadArg, "Intrinsic matrix must be a valid 3x3 floating-point matrix" );
if( !CV_IS_MAT(dist_coeffs) || dist_coeffs->rows != 1 && dist_coeffs->cols != 1 ||
dist_coeffs->rows*dist_coeffs->cols*CV_MAT_CN(dist_coeffs->type) != 4 ||
CV_MAT_DEPTH(dist_coeffs->type) != CV_64F &&
CV_MAT_DEPTH(dist_coeffs->type) != CV_32F )
CV_ERROR( CV_StsBadArg,
"Distortion coefficients must be 1x4 or 4x1 floating-point vector" );
cvConvert( A, &_a );
_k = cvMat( dist_coeffs->rows, dist_coeffs->cols,
CV_MAKETYPE(CV_32F, CV_MAT_CN(dist_coeffs->type)), k );
cvConvert( dist_coeffs, &_k );
u0 = a[2]; v0 = a[5];
fx = a[0]; fy = a[4];
_fx = 1.f/fx; _fy = 1.f/fy;
k1 = k[0]; k2 = k[1];
p1 = k[2]; p2 = k[3];
mapxstep = _mapx->step ? _mapx->step : CV_STUB_STEP;
mapystep = _mapy->step ? _mapy->step : CV_STUB_STEP;
mapx = _mapx->data.fl;
mapy = _mapy->data.fl;
size = cvGetMatSize(_mapx);
/*if( icvUndistortGetSize_p && icvCreateMapCameraUndistort_32f_C1R_p )
{
int buf_size = 0;
if( icvUndistortGetSize_p( size, &buf_size ) && buf_size > 0 )
{
CV_CALL( buffer = (uchar*)cvAlloc( buf_size ));
if( icvCreateMapCameraUndistort_32f_C1R_p(
mapx, mapxstep, mapy, mapystep, size,
a[0], a[4], a[2], a[5], k[0], k[1], k[2], k[3], buffer ) >= 0 )
EXIT;
}
}*/
mapxstep /= sizeof(mapx[0]);
mapystep /= sizeof(mapy[0]);
for( v = 0; v < size.height; v++, mapx += mapxstep, mapy += mapystep )
{
float y = (v - v0)*_fy;
float y2 = y*y;
float _2p1y = 2*p1*y;
float _3p1y2 = 3*p1*y2;
float p2y2 = p2*y2;
for( u = 0; u < size.width; u++ )
{
float x = (u - u0)*_fx;
float x2 = x*x;
float r2 = x2 + y2;
float d = 1 + (k1 + k2*r2)*r2;
float _u = fx*(x*(d + _2p1y) + p2y2 + (3*p2)*x2) + u0;
float _v = fy*(y*(d + (2*p2)*x) + _3p1y2 + p1*x2) + v0;
mapx[u] = _u;
mapy[u] = _v;
}
//.........这里部分代码省略.........
示例2: _buffer
bool PngDecoder::readData( Mat& img )
{
bool result = false;
AutoBuffer<uchar*> _buffer(m_height);
uchar** buffer = _buffer;
int color = img.channels() > 1;
uchar* data = img.data;
int step = (int)img.step;
if( m_png_ptr && m_info_ptr && m_end_info && m_width && m_height )
{
png_structp png_ptr = (png_structp)m_png_ptr;
png_infop info_ptr = (png_infop)m_info_ptr;
png_infop end_info = (png_infop)m_end_info;
if( setjmp( png_jmpbuf ( png_ptr ) ) == 0 )
{
int y;
if( img.depth() == CV_8U && m_bit_depth == 16 )
png_set_strip_16( png_ptr );
else if( !isBigEndian() )
png_set_swap( png_ptr );
if(img.channels() < 4)
{
/* observation: png_read_image() writes 400 bytes beyond
* end of data when reading a 400x118 color png
* "mpplus_sand.png". OpenCV crashes even with demo
* programs. Looking at the loaded image I'd say we get 4
* bytes per pixel instead of 3 bytes per pixel. Test
* indicate that it is a good idea to always ask for
* stripping alpha.. 18.11.2004 Axel Walthelm
*/
png_set_strip_alpha( png_ptr );
}
if( m_color_type == PNG_COLOR_TYPE_PALETTE )
png_set_palette_to_rgb( png_ptr );
if( m_color_type == PNG_COLOR_TYPE_GRAY && m_bit_depth < 8 )
#if PNG_LIBPNG_VER_MAJOR*100 + PNG_LIBPNG_VER_MINOR >= 104
png_set_expand_gray_1_2_4_to_8( png_ptr );
#else
png_set_gray_1_2_4_to_8( png_ptr );
#endif
if( CV_MAT_CN(m_type) > 1 && color )
png_set_bgr( png_ptr ); // convert RGB to BGR
else if( color )
png_set_gray_to_rgb( png_ptr ); // Gray->RGB
else
png_set_rgb_to_gray( png_ptr, 1, 0.299, 0.587 ); // RGB->Gray
png_read_update_info( png_ptr, info_ptr );
for( y = 0; y < m_height; y++ )
buffer[y] = data + y*step;
png_read_image( png_ptr, buffer );
png_read_end( png_ptr, end_info );
result = true;
}
}
close();
return result;
}
示例3: CV_MAT_DEPTH
void cv::Laplacian( InputArray _src, OutputArray _dst, int ddepth, int ksize,
double scale, double delta, int borderType )
{
int stype = _src.type(), sdepth = CV_MAT_DEPTH(stype), cn = CV_MAT_CN(stype);
if (ddepth < 0)
ddepth = sdepth;
_dst.create( _src.size(), CV_MAKETYPE(ddepth, cn) );
#ifdef HAVE_TEGRA_OPTIMIZATION
if (scale == 1.0 && delta == 0)
{
Mat src = _src.getMat(), dst = _dst.getMat();
if (ksize == 1 && tegra::laplace1(src, dst, borderType))
return;
if (ksize == 3 && tegra::laplace3(src, dst, borderType))
return;
if (ksize == 5 && tegra::laplace5(src, dst, borderType))
return;
}
#endif
if( ksize == 1 || ksize == 3 )
{
float K[2][9] =
{
{ 0, 1, 0, 1, -4, 1, 0, 1, 0 },
{ 2, 0, 2, 0, -8, 0, 2, 0, 2 }
};
Mat kernel(3, 3, CV_32F, K[ksize == 3]);
if( scale != 1 )
kernel *= scale;
filter2D( _src, _dst, ddepth, kernel, Point(-1, -1), delta, borderType );
}
else
{
int ktype = std::max(CV_32F, std::max(ddepth, sdepth));
int wdepth = sdepth == CV_8U && ksize <= 5 ? CV_16S : sdepth <= CV_32F ? CV_32F : CV_64F;
int wtype = CV_MAKETYPE(wdepth, cn);
Mat kd, ks;
getSobelKernels( kd, ks, 2, 0, ksize, false, ktype );
CV_OCL_RUN(_dst.isUMat(),
ocl_Laplacian5(_src, _dst, kd, ks, scale,
delta, borderType, wdepth, ddepth))
const size_t STRIPE_SIZE = 1 << 14;
Ptr<FilterEngine> fx = createSeparableLinearFilter(stype,
wtype, kd, ks, Point(-1,-1), 0, borderType, borderType, Scalar() );
Ptr<FilterEngine> fy = createSeparableLinearFilter(stype,
wtype, ks, kd, Point(-1,-1), 0, borderType, borderType, Scalar() );
Mat src = _src.getMat(), dst = _dst.getMat();
int y = fx->start(src), dsty = 0, dy = 0;
fy->start(src);
const uchar* sptr = src.data + y*src.step;
int dy0 = std::min(std::max((int)(STRIPE_SIZE/(CV_ELEM_SIZE(stype)*src.cols)), 1), src.rows);
Mat d2x( dy0 + kd.rows - 1, src.cols, wtype );
Mat d2y( dy0 + kd.rows - 1, src.cols, wtype );
for( ; dsty < src.rows; sptr += dy0*src.step, dsty += dy )
{
fx->proceed( sptr, (int)src.step, dy0, d2x.data, (int)d2x.step );
dy = fy->proceed( sptr, (int)src.step, dy0, d2y.data, (int)d2y.step );
if( dy > 0 )
{
Mat dstripe = dst.rowRange(dsty, dsty + dy);
d2x.rows = d2y.rows = dy; // modify the headers, which should work
d2x += d2y;
d2x.convertTo( dstripe, ddepth, scale, delta );
}
}
}
}
示例4: CV_MAT_CN
inline
int CudaMem::channels() const
{
return CV_MAT_CN(flags);
}
示例5: imread_
static void*
imread_( const string& filename, int flags, int hdrtype, Mat* mat=0 )
{
IplImage* image = 0;
CvMat *matrix = 0;
Mat temp, *data = &temp;
ImageDecoder decoder = findDecoder(filename);
if( decoder.empty() )
return 0;
decoder->setSource(filename);
if( !decoder->readHeader() )
return 0;
CvSize size;
size.width = decoder->width();
size.height = decoder->height();
int type = decoder->type();
if( flags != -1 )
{
if( (flags & CV_LOAD_IMAGE_ANYDEPTH) == 0 )
type = CV_MAKETYPE(CV_8U, CV_MAT_CN(type));
if( (flags & CV_LOAD_IMAGE_COLOR) != 0 ||
((flags & CV_LOAD_IMAGE_ANYCOLOR) != 0 && CV_MAT_CN(type) > 1) )
type = CV_MAKETYPE(CV_MAT_DEPTH(type), 3);
else
type = CV_MAKETYPE(CV_MAT_DEPTH(type), 1);
}
if( hdrtype == LOAD_CVMAT || hdrtype == LOAD_MAT )
{
if( hdrtype == LOAD_CVMAT )
{
matrix = cvCreateMat( size.height, size.width, type );
temp = cvarrToMat(matrix);
}
else
{
mat->create( size.height, size.width, type );
data = mat;
}
}
else
{
image = cvCreateImage( size, cvIplDepth(type), CV_MAT_CN(type) );
temp = cvarrToMat(image);
}
if( !decoder->readData( *data ))
{
cvReleaseImage( &image );
cvReleaseMat( &matrix );
if( mat )
mat->release();
return 0;
}
return hdrtype == LOAD_CVMAT ? (void*)matrix :
hdrtype == LOAD_IMAGE ? (void*)image : (void*)mat;
}
示例6: cvGetRectSubPix
CV_IMPL void
cvGetRectSubPix( const void* srcarr, void* dstarr, CvPoint2D32f center )
{
static CvFuncTable gr_tab[2];
static int inittab = 0;
CV_FUNCNAME( "cvGetRectSubPix" );
__BEGIN__;
CvMat srcstub, *src = (CvMat*)srcarr;
CvMat dststub, *dst = (CvMat*)dstarr;
CvSize src_size, dst_size;
CvGetRectSubPixFunc func;
int cn, src_step, dst_step;
if( !inittab )
{
icvInitGetRectSubPixC1RTable( gr_tab + 0 );
icvInitGetRectSubPixC3RTable( gr_tab + 1 );
inittab = 1;
}
if( !CV_IS_MAT(src))
CV_CALL( src = cvGetMat( src, &srcstub ));
if( !CV_IS_MAT(dst))
CV_CALL( dst = cvGetMat( dst, &dststub ));
cn = CV_MAT_CN( src->type );
if( (cn != 1 && cn != 3) || !CV_ARE_CNS_EQ( src, dst ))
CV_ERROR( CV_StsUnsupportedFormat, "" );
src_size = cvGetMatSize( src );
dst_size = cvGetMatSize( dst );
src_step = src->step ? src->step : CV_STUB_STEP;
dst_step = dst->step ? dst->step : CV_STUB_STEP;
//if( dst_size.width > src_size.width || dst_size.height > src_size.height )
// CV_ERROR( CV_StsBadSize, "destination ROI must be smaller than source ROI" );
if( CV_ARE_DEPTHS_EQ( src, dst ))
{
func = (CvGetRectSubPixFunc)(gr_tab[cn != 1].fn_2d[CV_MAT_DEPTH(src->type)]);
}
else
{
if( CV_MAT_DEPTH( src->type ) != CV_8U || CV_MAT_DEPTH( dst->type ) != CV_32F )
CV_ERROR( CV_StsUnsupportedFormat, "" );
func = (CvGetRectSubPixFunc)(gr_tab[cn != 1].fn_2d[1]);
}
if( !func )
CV_ERROR( CV_StsUnsupportedFormat, "" );
IPPI_CALL( func( src->data.ptr, src_step, src_size,
dst->data.ptr, dst_step, dst_size, center ));
__END__;
}
示例7: cvIntegral
CV_IMPL void
cvIntegral( const CvArr* image, CvArr* sumImage,
CvArr* sumSqImage, CvArr* tiltedSumImage )
{
CV_FUNCNAME( "cvIntegralImage" );
__BEGIN__;
CvMat src_stub, *src = (CvMat*)image;
CvMat sum_stub, *sum = (CvMat*)sumImage;
CvMat sqsum_stub, *sqsum = (CvMat*)sumSqImage;
CvMat tilted_stub, *tilted = (CvMat*)tiltedSumImage;
int coi0 = 0, coi1 = 0, coi2 = 0, coi3 = 0;
//int depth;
int cn;
int src_step, sum_step, sqsum_step, tilted_step;
CvSize size;
CV_CALL( src = cvGetMat( src, &src_stub, &coi0 ));
CV_CALL( sum = cvGetMat( sum, &sum_stub, &coi1 ));
if( sum->width != src->width + 1 ||
sum->height != src->height + 1 )
CV_ERROR( CV_StsUnmatchedSizes, "" );
if(CV_MAT_DEPTH(src->type)!=CV_8U || CV_MAT_CN(src->type)!=1)
CV_ERROR( CV_StsUnsupportedFormat, "the source array must be 8UC1");
if( CV_MAT_DEPTH( sum->type ) != CV_32S ||
!CV_ARE_CNS_EQ( src, sum ))
CV_ERROR( CV_StsUnsupportedFormat,
"Sum array must have 32s type in case of 8u source array"
"and the same number of channels as the source array" );
if( sqsum )
{
CV_CALL( sqsum = cvGetMat( sqsum, &sqsum_stub, &coi2 ));
if( !CV_ARE_SIZES_EQ( sum, sqsum ) )
CV_ERROR( CV_StsUnmatchedSizes, "" );
if( CV_MAT_DEPTH( sqsum->type ) != CV_64S || !CV_ARE_CNS_EQ( src, sqsum ))
CV_ERROR( CV_StsUnsupportedFormat,
"Squares sum array must be 64s "
"and the same number of channels as the source array" );
}
if( tilted )
{
if( !sqsum )
CV_ERROR( CV_StsNullPtr,
"Squared sum array must be passed if tilted sum array is passed" );
CV_CALL( tilted = cvGetMat( tilted, &tilted_stub, &coi3 ));
if( !CV_ARE_SIZES_EQ( sum, tilted ) )
CV_ERROR( CV_StsUnmatchedSizes, "" );
if( !CV_ARE_TYPES_EQ( sum, tilted ) )
CV_ERROR( CV_StsUnmatchedFormats,
"Sum and tilted sum must have the same types" );
if( CV_MAT_CN(tilted->type) != 1 )
CV_ERROR( CV_StsNotImplemented,
"Tilted sum can not be computed for multi-channel arrays" );
}
if( coi0 || coi1 || coi2 || coi3 )
CV_ERROR( CV_BadCOI, "COI is not supported by the function" );
//depth = CV_MAT_DEPTH(src->type);
cn = CV_MAT_CN(src->type);
size = cvGetMatSize(src);
src_step = src->step ? src->step : CV_STUB_STEP;
sum_step = sum->step ? sum->step : CV_STUB_STEP;
sqsum_step = !sqsum ? 0 : sqsum->step ? sqsum->step : CV_STUB_STEP;
tilted_step = !tilted ? 0 : tilted->step ? tilted->step : CV_STUB_STEP;
if( cn == 1 )
{
cvIntegralImage_8u32s64s_C1R( src->data.ptr, src_step, (int*)(sum->data.ptr), sum_step,
sqsum ? (int64*)(sqsum->data.ptr) : 0, sqsum_step,
tilted ? (int*)(tilted->data.ptr) : 0, tilted_step, size );
}
__END__;
}
示例8: CV_FUNCNAME
void CvBoxFilter::init( int _max_width, int _src_type, int _dst_type,
bool _normalized, CvSize _ksize,
CvPoint _anchor, int _border_mode,
CvScalar _border_value )
{
CV_FUNCNAME( "CvBoxFilter::init" );
__BEGIN__;
sum = 0;
normalized = _normalized;
if( normalized && CV_MAT_TYPE(_src_type) != CV_MAT_TYPE(_dst_type) ||
!normalized && CV_MAT_CN(_src_type) != CV_MAT_CN(_dst_type))
CV_ERROR( CV_StsUnmatchedFormats,
"In case of normalized box filter input and output must have the same type.\n"
"In case of unnormalized box filter the number of input and output channels must be the same" );
min_depth = CV_MAT_DEPTH(_src_type) == CV_8U ? CV_32S : CV_64F;
CvBaseImageFilter::init( _max_width, _src_type, _dst_type, 1, _ksize,
_anchor, _border_mode, _border_value );
scale = normalized ? 1./(ksize.width*ksize.height) : 1;
if( CV_MAT_DEPTH(src_type) == CV_8U )
x_func = (CvRowFilterFunc)icvSumRow_8u32s;
else if( CV_MAT_DEPTH(src_type) == CV_32F )
x_func = (CvRowFilterFunc)icvSumRow_32f64f;
else
CV_ERROR( CV_StsUnsupportedFormat, "Unknown/unsupported input image format" );
if( CV_MAT_DEPTH(dst_type) == CV_8U )
{
if( !normalized )
CV_ERROR( CV_StsBadArg, "Only normalized box filter can be used for 8u->8u transformation" );
y_func = (CvColumnFilterFunc)icvSumCol_32s8u;
}
else if( CV_MAT_DEPTH(dst_type) == CV_16S )
{
if( normalized || CV_MAT_DEPTH(src_type) != CV_8U )
CV_ERROR( CV_StsBadArg, "Only 8u->16s unnormalized box filter is supported in case of 16s output" );
y_func = (CvColumnFilterFunc)icvSumCol_32s16s;
}
else if( CV_MAT_DEPTH(dst_type) == CV_32S )
{
if( normalized || CV_MAT_DEPTH(src_type) != CV_8U )
CV_ERROR( CV_StsBadArg, "Only 8u->32s unnormalized box filter is supported in case of 32s output");
y_func = (CvColumnFilterFunc)icvSumCol_32s32s;
}
else if( CV_MAT_DEPTH(dst_type) == CV_32F )
{
if( CV_MAT_DEPTH(src_type) != CV_32F )
CV_ERROR( CV_StsBadArg, "Only 32f->32f box filter (normalized or not) is supported in case of 32f output" );
y_func = (CvColumnFilterFunc)icvSumCol_64f32f;
}
else{
CV_ERROR( CV_StsBadArg, "Unknown/unsupported destination image format" );
}
__END__;
}
示例9: cvConvexHull2
CV_IMPL CvSeq*
cvConvexHull2( const CvArr* array, void* hull_storage,
int orientation, int return_points )
{
CvMat* mat = 0;
CvContour contour_header;
CvSeq hull_header;
CvSeqBlock block, hullblock;
CvSeq* ptseq = 0;
CvSeq* hullseq = 0;
if( CV_IS_SEQ( array ))
{
ptseq = (CvSeq*)array;
if( !CV_IS_SEQ_POINT_SET( ptseq ))
CV_Error( CV_StsBadArg, "Unsupported sequence type" );
if( hull_storage == 0 )
hull_storage = ptseq->storage;
}
else
{
ptseq = cvPointSeqFromMat( CV_SEQ_KIND_GENERIC, array, &contour_header, &block );
}
bool isStorage = isStorageOrMat(hull_storage);
if(isStorage)
{
if( return_points )
{
hullseq = cvCreateSeq(CV_SEQ_KIND_CURVE|CV_SEQ_ELTYPE(ptseq)|
CV_SEQ_FLAG_CLOSED|CV_SEQ_FLAG_CONVEX,
sizeof(CvContour), sizeof(CvPoint),(CvMemStorage*)hull_storage );
}
else
{
hullseq = cvCreateSeq(
CV_SEQ_KIND_CURVE|CV_SEQ_ELTYPE_PPOINT|
CV_SEQ_FLAG_CLOSED|CV_SEQ_FLAG_CONVEX,
sizeof(CvContour), sizeof(CvPoint*), (CvMemStorage*)hull_storage );
}
}
else
{
mat = (CvMat*)hull_storage;
if( (mat->cols != 1 && mat->rows != 1) || !CV_IS_MAT_CONT(mat->type))
CV_Error( CV_StsBadArg,
"The hull matrix should be continuous and have a single row or a single column" );
if( mat->cols + mat->rows - 1 < ptseq->total )
CV_Error( CV_StsBadSize, "The hull matrix size might be not enough to fit the hull" );
if( CV_MAT_TYPE(mat->type) != CV_SEQ_ELTYPE(ptseq) &&
CV_MAT_TYPE(mat->type) != CV_32SC1 )
CV_Error( CV_StsUnsupportedFormat,
"The hull matrix must have the same type as input or 32sC1 (integers)" );
hullseq = cvMakeSeqHeaderForArray(
CV_SEQ_KIND_CURVE|CV_MAT_TYPE(mat->type)|CV_SEQ_FLAG_CLOSED,
sizeof(hull_header), CV_ELEM_SIZE(mat->type), mat->data.ptr,
mat->cols + mat->rows - 1, &hull_header, &hullblock );
cvClearSeq( hullseq );
}
int hulltype = CV_SEQ_ELTYPE(hullseq);
int total = ptseq->total;
if( total == 0 )
{
if( !isStorage )
CV_Error( CV_StsBadSize,
"Point sequence can not be empty if the output is matrix" );
return 0;
}
cv::AutoBuffer<double> _ptbuf;
cv::Mat h0;
cv::convexHull(cv::cvarrToMat(ptseq, false, false, 0, &_ptbuf), h0,
orientation == CV_CLOCKWISE, CV_MAT_CN(hulltype) == 2);
if( hulltype == CV_SEQ_ELTYPE_PPOINT )
{
const int* idx = h0.ptr<int>();
int ctotal = (int)h0.total();
for( int i = 0; i < ctotal; i++ )
{
void* ptr = cvGetSeqElem(ptseq, idx[i]);
cvSeqPush( hullseq, &ptr );
}
}
else
cvSeqPushMulti(hullseq, h0.ptr(), (int)h0.total());
if (isStorage)
{
return hullseq;
}
else
{
//.........这里部分代码省略.........
示例10: icvSumCol_32s16s
static void
icvSumCol_32s16s( const int** src, short* dst,
int dst_step, int count, void* params )
{
CvBoxFilter* state = (CvBoxFilter*)params;
int ksize = state->get_kernel_size().height;
int ktotal = ksize*state->get_kernel_size().width;
int i, width = state->get_width();
int cn = CV_MAT_CN(state->get_src_type());
int* sum = (int*)state->get_sum_buf();
int* _sum_count = state->get_sum_count_ptr();
int sum_count = *_sum_count;
dst_step /= sizeof(dst[0]);
width *= cn;
src += sum_count;
count += ksize - 1 - sum_count;
for( ; count--; src++ )
{
const int* sp = src[0];
if( sum_count+1 < ksize )
{
for( i = 0; i <= width - 2; i += 2 )
{
int s0 = sum[i] + sp[i], s1 = sum[i+1] + sp[i+1];
sum[i] = s0; sum[i+1] = s1;
}
for( ; i < width; i++ )
sum[i] += sp[i];
sum_count++;
}
else if( ktotal < 128 )
{
const int* sm = src[-ksize+1];
for( i = 0; i <= width - 2; i += 2 )
{
int s0 = sum[i] + sp[i], s1 = sum[i+1] + sp[i+1];
dst[i] = (short)s0; dst[i+1] = (short)s1;
s0 -= sm[i]; s1 -= sm[i+1];
sum[i] = s0; sum[i+1] = s1;
}
for( ; i < width; i++ )
{
int s0 = sum[i] + sp[i];
dst[i] = (short)s0;
sum[i] = s0 - sm[i];
}
dst += dst_step;
}
else
{
const int* sm = src[-ksize+1];
for( i = 0; i <= width - 2; i += 2 )
{
int s0 = sum[i] + sp[i], s1 = sum[i+1] + sp[i+1];
dst[i] = CV_CAST_16S(s0); dst[i+1] = CV_CAST_16S(s1);
s0 -= sm[i]; s1 -= sm[i+1];
sum[i] = s0; sum[i+1] = s1;
}
for( ; i < width; i++ )
{
int s0 = sum[i] + sp[i];
dst[i] = CV_CAST_16S(s0);
sum[i] = s0 - sm[i];
}
dst += dst_step;
}
}
*_sum_count = sum_count;
}
示例11: icvSumCol_64f32f
static void
icvSumCol_64f32f( const double** src, float* dst,
int dst_step, int count, void* params )
{
CvBoxFilter* state = (CvBoxFilter*)params;
int ksize = state->get_kernel_size().height;
int i, width = state->get_width();
int cn = CV_MAT_CN(state->get_src_type());
double scale = state->get_scale();
bool normalized = state->is_normalized();
double* sum = (double*)state->get_sum_buf();
int* _sum_count = state->get_sum_count_ptr();
int sum_count = *_sum_count;
dst_step /= sizeof(dst[0]);
width *= cn;
src += sum_count;
count += ksize - 1 - sum_count;
for( ; count--; src++ )
{
const double* sp = src[0];
if( sum_count+1 < ksize )
{
for( i = 0; i <= width - 2; i += 2 )
{
double s0 = sum[i] + sp[i], s1 = sum[i+1] + sp[i+1];
sum[i] = s0; sum[i+1] = s1;
}
for( ; i < width; i++ )
sum[i] += sp[i];
sum_count++;
}
else
{
const double* sm = src[-ksize+1];
if( normalized )
for( i = 0; i <= width - 2; i += 2 )
{
double s0 = sum[i] + sp[i], s1 = sum[i+1] + sp[i+1];
double t0 = s0*scale, t1 = s1*scale;
s0 -= sm[i]; s1 -= sm[i+1];
dst[i] = (float)t0; dst[i+1] = (float)t1;
sum[i] = s0; sum[i+1] = s1;
}
else
for( i = 0; i <= width - 2; i += 2 )
{
double s0 = sum[i] + sp[i], s1 = sum[i+1] + sp[i+1];
dst[i] = (float)s0; dst[i+1] = (float)s1;
s0 -= sm[i]; s1 -= sm[i+1];
sum[i] = s0; sum[i+1] = s1;
}
for( ; i < width; i++ )
{
double s0 = sum[i] + sp[i], t0 = s0*scale;
sum[i] = s0 - sm[i]; dst[i] = (float)t0;
}
dst += dst_step;
}
}
*_sum_count = sum_count;
}
示例12: return
inline int oclMat::oclchannels() const
{
return (CV_MAT_CN(flags)) == 3 ? 4 : (CV_MAT_CN(flags));
}
示例13: cvKMeans2
CV_IMPL void
cvKMeans2( const CvArr* samples_arr, int cluster_count,
CvArr* labels_arr, CvTermCriteria termcrit )
{
CvMat* centers = 0;
CvMat* old_centers = 0;
CvMat* counters = 0;
CV_FUNCNAME( "cvKMeans2" );
__BEGIN__;
CvMat samples_stub, labels_stub;
CvMat* samples = (CvMat*)samples_arr;
CvMat* labels = (CvMat*)labels_arr;
CvMat* temp = 0;
CvRNG rng = CvRNG(-1);
int i, j, k, sample_count, dims;
int ids_delta, iter;
double max_dist;
if( !CV_IS_MAT( samples ))
CV_CALL( samples = cvGetMat( samples, &samples_stub ));
if( !CV_IS_MAT( labels ))
CV_CALL( labels = cvGetMat( labels, &labels_stub ));
if( cluster_count < 1 )
CV_ERROR( CV_StsOutOfRange, "Number of clusters should be positive" );
if( CV_MAT_DEPTH(samples->type) != CV_32F || CV_MAT_TYPE(labels->type) != CV_32SC1 )
CV_ERROR( CV_StsUnsupportedFormat,
"samples should be floating-point matrix, cluster_idx - integer vector" );
if( labels->rows != 1 && (labels->cols != 1 || !CV_IS_MAT_CONT(labels->type)) ||
labels->rows + labels->cols - 1 != samples->rows )
CV_ERROR( CV_StsUnmatchedSizes,
"cluster_idx should be 1D vector of the same number of elements as samples' number of rows" );
CV_CALL( termcrit = cvCheckTermCriteria( termcrit, 1e-6, 100 ));
termcrit.epsilon *= termcrit.epsilon;
sample_count = samples->rows;
if( cluster_count > sample_count )
cluster_count = sample_count;
dims = samples->cols*CV_MAT_CN(samples->type);
ids_delta = labels->step ? labels->step/(int)sizeof(int) : 1;
CV_CALL( centers = cvCreateMat( cluster_count, dims, CV_64FC1 ));
CV_CALL( old_centers = cvCreateMat( cluster_count, dims, CV_64FC1 ));
CV_CALL( counters = cvCreateMat( 1, cluster_count, CV_32SC1 ));
// init centers
for( i = 0; i < sample_count; i++ )
labels->data.i[i] = cvRandInt(&rng) % cluster_count;
counters->cols = cluster_count; // cut down counters
max_dist = termcrit.epsilon*2;
for( iter = 0; iter < termcrit.max_iter; iter++ )
{
// computer centers
cvZero( centers );
cvZero( counters );
for( i = 0; i < sample_count; i++ )
{
float* s = (float*)(samples->data.ptr + i*samples->step);
k = labels->data.i[i*ids_delta];
double* c = (double*)(centers->data.ptr + k*centers->step);
for( j = 0; j <= dims - 4; j += 4 )
{
double t0 = c[j] + s[j];
double t1 = c[j+1] + s[j+1];
c[j] = t0;
c[j+1] = t1;
t0 = c[j+2] + s[j+2];
t1 = c[j+3] + s[j+3];
c[j+2] = t0;
c[j+3] = t1;
}
for( ; j < dims; j++ )
c[j] += s[j];
counters->data.i[k]++;
}
if( iter > 0 )
max_dist = 0;
for( k = 0; k < cluster_count; k++ )
{
double* c = (double*)(centers->data.ptr + k*centers->step);
if( counters->data.i[k] != 0 )
{
double scale = 1./counters->data.i[k];
//.........这里部分代码省略.........
示例14: cvFindStereoCorrespondenceGC
CV_IMPL void cvFindStereoCorrespondenceGC( const CvArr* _left, const CvArr* _right,
CvArr* _dispLeft, CvArr* _dispRight, CvStereoGCState* state, int useDisparityGuess )
{
CvStereoGCState2 state2;
state2.orphans = 0;
state2.maxOrphans = 0;
CV_FUNCNAME( "cvFindStereoCorrespondenceGC" );
__BEGIN__;
CvMat lstub, *left = cvGetMat( _left, &lstub );
CvMat rstub, *right = cvGetMat( _right, &rstub );
CvMat dlstub, *dispLeft = cvGetMat( _dispLeft, &dlstub );
CvMat drstub, *dispRight = cvGetMat( _dispRight, &drstub );
CvSize size;
int iter, i, nZeroExpansions = 0;
CvRNG rng = cvRNG(-1);
int* disp;
CvMat _disp;
int64 E;
CV_ASSERT( state != 0 );
CV_ASSERT( CV_ARE_SIZES_EQ(left, right) && CV_ARE_TYPES_EQ(left, right) &&
CV_MAT_TYPE(left->type) == CV_8UC1 );
CV_ASSERT( !dispLeft ||
(CV_ARE_SIZES_EQ(dispLeft, left) && CV_MAT_CN(dispLeft->type) == 1) );
CV_ASSERT( !dispRight ||
(CV_ARE_SIZES_EQ(dispRight, left) && CV_MAT_CN(dispRight->type) == 1) );
size = cvGetSize(left);
if( !state->left || state->left->width != size.width || state->left->height != size.height )
{
int pcn = (int)(sizeof(GCVtx*)/sizeof(int));
int vcn = (int)(sizeof(GCVtx)/sizeof(int));
int ecn = (int)(sizeof(GCEdge)/sizeof(int));
cvReleaseMat( &state->left );
cvReleaseMat( &state->right );
cvReleaseMat( &state->ptrLeft );
cvReleaseMat( &state->ptrRight );
cvReleaseMat( &state->dispLeft );
cvReleaseMat( &state->dispRight );
state->left = cvCreateMat( size.height, size.width, CV_8UC3 );
state->right = cvCreateMat( size.height, size.width, CV_8UC3 );
state->dispLeft = cvCreateMat( size.height, size.width, CV_16SC1 );
state->dispRight = cvCreateMat( size.height, size.width, CV_16SC1 );
state->ptrLeft = cvCreateMat( size.height, size.width, CV_32SC(pcn) );
state->ptrRight = cvCreateMat( size.height, size.width, CV_32SC(pcn) );
state->vtxBuf = cvCreateMat( 1, size.height*size.width*2, CV_32SC(vcn) );
state->edgeBuf = cvCreateMat( 1, size.height*size.width*12 + 16, CV_32SC(ecn) );
}
if( !useDisparityGuess )
{
cvSet( state->dispLeft, cvScalarAll(OCCLUDED));
cvSet( state->dispRight, cvScalarAll(OCCLUDED));
}
else
{
CV_ASSERT( dispLeft && dispRight );
cvConvert( dispLeft, state->dispLeft );
cvConvert( dispRight, state->dispRight );
}
state2.Ithreshold = state->Ithreshold;
state2.interactionRadius = state->interactionRadius;
state2.lambda = cvRound(state->lambda*DENOMINATOR);
state2.lambda1 = cvRound(state->lambda1*DENOMINATOR);
state2.lambda2 = cvRound(state->lambda2*DENOMINATOR);
state2.K = cvRound(state->K*DENOMINATOR);
icvInitStereoConstTabs();
icvInitGraySubpix( left, right, state->left, state->right );
disp = (int*)cvStackAlloc( state->numberOfDisparities*sizeof(disp[0]) );
_disp = cvMat( 1, state->numberOfDisparities, CV_32S, disp );
cvRange( &_disp, state->minDisparity, state->minDisparity + state->numberOfDisparities );
cvRandShuffle( &_disp, &rng );
if( state2.lambda < 0 && (state2.K < 0 || state2.lambda1 < 0 || state2.lambda2 < 0) )
{
float L = icvComputeK(state)*0.2f;
state2.lambda = cvRound(L*DENOMINATOR);
}
if( state2.K < 0 )
state2.K = state2.lambda*5;
if( state2.lambda1 < 0 )
state2.lambda1 = state2.lambda*3;
if( state2.lambda2 < 0 )
state2.lambda2 = state2.lambda;
icvInitStereoTabs( &state2 );
E = icvComputeEnergy( state, &state2, !useDisparityGuess );
for( iter = 0; iter < state->maxIters; iter++ )
{
for( i = 0; i < state->numberOfDisparities; i++ )
{
int alpha = disp[i];
//.........这里部分代码省略.........
示例15: imreadmulti_
/**
* Read an image into memory and return the information
*
* @param[in] filename File to load
* @param[in] flags Flags
* @param[in] mats Reference to C++ vector<Mat> object to hold the images
*
*/
static bool
imreadmulti_(const String& filename, int flags, std::vector<Mat>& mats)
{
/// Search for the relevant decoder to handle the imagery
ImageDecoder decoder;
#ifdef HAVE_GDAL
if (flags != IMREAD_UNCHANGED && (flags & IMREAD_LOAD_GDAL) == IMREAD_LOAD_GDAL){
decoder = GdalDecoder().newDecoder();
}
else{
#endif
decoder = findDecoder(filename);
#ifdef HAVE_GDAL
}
#endif
/// if no decoder was found, return nothing.
if (!decoder){
return 0;
}
/// set the filename in the driver
decoder->setSource(filename);
// read the header to make sure it succeeds
if (!decoder->readHeader())
return 0;
for (;;)
{
// grab the decoded type
int type = decoder->type();
if( (flags & IMREAD_LOAD_GDAL) != IMREAD_LOAD_GDAL && flags != IMREAD_UNCHANGED )
{
if ((flags & CV_LOAD_IMAGE_ANYDEPTH) == 0)
type = CV_MAKETYPE(CV_8U, CV_MAT_CN(type));
if ((flags & CV_LOAD_IMAGE_COLOR) != 0 ||
((flags & CV_LOAD_IMAGE_ANYCOLOR) != 0 && CV_MAT_CN(type) > 1))
type = CV_MAKETYPE(CV_MAT_DEPTH(type), 3);
else
type = CV_MAKETYPE(CV_MAT_DEPTH(type), 1);
}
// read the image data
Mat mat(decoder->height(), decoder->width(), type);
if (!decoder->readData(mat))
{
// optionally rotate the data if EXIF' orientation flag says so
if( (flags & IMREAD_IGNORE_ORIENTATION) == 0 && flags != IMREAD_UNCHANGED )
{
ApplyExifOrientation(filename, mat);
}
break;
}
mats.push_back(mat);
if (!decoder->nextPage())
{
break;
}
}
return !mats.empty();
}