本文整理汇总了C++中InputArray::getMat方法的典型用法代码示例。如果您正苦于以下问题:C++ InputArray::getMat方法的具体用法?C++ InputArray::getMat怎么用?C++ InputArray::getMat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类InputArray
的用法示例。
在下文中一共展示了InputArray::getMat方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
vector< pair< int, int > > FeatureShiCorner::genPoints( InputArray _image )
{
auto outVec = vector< pair< int, int > >();
const Mat image = _image.getMat();
const int height = image.rows - descRadius;
const int width = image.cols - descRadius;
int32_t val;
for( int y = descRadius; y < height; y++ )
{
for( int x = descRadius; x < width; x++ )
{
val = image.at< int32_t >( y, x );
if( val <= 0 ) { continue; }
outVec.push_back( make_pair( x, y ) );
}
}
return outVec;
}
示例2: isSymmetric
bool libfacerec::isSymmetric(InputArray src, double eps) {
Mat m = src.getMat();
switch (m.type()) {
case CV_8SC1: return isSymmetric_<char>(m); break;
case CV_8UC1:
return isSymmetric_<unsigned char>(m); break;
case CV_16SC1:
return isSymmetric_<short>(m); break;
case CV_16UC1:
return isSymmetric_<unsigned short>(m); break;
case CV_32SC1:
return isSymmetric_<int>(m); break;
case CV_32FC1:
return isSymmetric_<float>(m, eps); break;
case CV_64FC1:
return isSymmetric_<double>(m, eps); break;
default:
break;
}
return false;
}
示例3: getDistanceToId
int Dictionary::getDistanceToId(InputArray bits, int id, bool allRotations) const {
CV_Assert(id >= 0 && id < bytesList.rows);
unsigned int nRotations = 4;
if(!allRotations) nRotations = 1;
Mat candidateBytes = getByteListFromBits(bits.getMat());
int currentMinDistance = int(bits.total() * bits.total());
for(unsigned int r = 0; r < nRotations; r++) {
int currentHamming = cv::hal::normHamming(
bytesList.ptr(id) + r*candidateBytes.cols,
candidateBytes.ptr(),
candidateBytes.cols);
if(currentHamming < currentMinDistance) {
currentMinDistance = currentHamming;
}
}
return currentMinDistance;
}
示例4: removeBorder
void removeBorder(InputArray _src, OutputArray _dst, int top, int bottom, int left, int right)
{
CV_Assert( top >= 0 && bottom >= 0 && left >= 0 && right >= 0 );
Mat src = _src.getMat();
int type = src.type();
_dst.create( src.rows - top - bottom, src.cols - left - right, type );
Mat dst = _dst.getMat();
// if(top == 0 && left == 0 && bottom == 0 && right == 0)
// {
// if(src.data != dst.data || src.step != dst.step)
// src.copyTo(dst);
// return;
// }
if(src.data != dst.data || src.step != dst.step)
src(Range(top, src.rows - bottom), Range(left, src.cols-right)).copyTo(dst);
return;
}
示例5: predict
void Fisherfaces::predict(InputArray _src, Ptr<PredictCollector> collector) const {
Mat src = _src.getMat();
// check data alignment just for clearer exception messages
if(_projections.empty()) {
// throw error if no data (or simply return -1?)
String error_message = "This Fisherfaces model is not computed yet. Did you call Fisherfaces::train?";
CV_Error(Error::StsBadArg, error_message);
} else if(src.total() != (size_t) _eigenvectors.rows) {
String error_message = format("Wrong input image size. Reason: Training and Test images must be of equal size! Expected an image with %d elements, but got %d.", _eigenvectors.rows, src.total());
CV_Error(Error::StsBadArg, error_message);
}
// project into LDA subspace
Mat q = LDA::subspaceProject(_eigenvectors, _mean, src.reshape(1,1));
// find 1-nearest neighbor
collector->init((int)_projections.size());
for (size_t sampleIdx = 0; sampleIdx < _projections.size(); sampleIdx++) {
double dist = norm(_projections[sampleIdx], q, NORM_L2);
int label = _labels.at<int>((int)sampleIdx);
if (!collector->collect(label, dist))return;
}
}
示例6: diffSign
void diffSign(InputArray _src1, OutputArray _src2, OutputArray _dst)
{
CV_OCL_RUN(_dst.isUMat(),
ocl_diffSign(_src1, _src2, _dst))
Mat src1 = _src1.getMat(), src2 = _src2.getMat();
_dst.create(src1.size(), src1.type());
Mat dst = _dst.getMat();
const int count = src1.cols * src1.channels();
for (int y = 0; y < src1.rows; ++y)
{
const float * const src1Ptr = src1.ptr<float>(y);
const float * const src2Ptr = src2.ptr<float>(y);
float* dstPtr = dst.ptr<float>(y);
for (int x = 0; x < count; ++x)
dstPtr[x] = diffSign(src1Ptr[x], src2Ptr[x]);
}
}
示例7:
void
isotropicPreconditionerFromPoints( InputArray _points,
OutputArray _T )
{
const Mat points = _points.getMat();
const int depth = points.depth();
CV_Assert((points.dims == 2 || points.dims == 3) && (depth == CV_32F || depth == CV_64F));
_T.create(3, 3, depth);
Mat T = _T.getMat();
if ( depth == CV_32F )
{
isotropicPreconditionerFromPoints<float>(points, T);
}
else
{
isotropicPreconditionerFromPoints<double>(points, T);
}
}
示例8: arcLength
// calculates length of a curve (e.g. contour perimeter)
double cv::arcLength( InputArray _curve, bool is_closed )
{
Mat curve = _curve.getMat();
int count = curve.checkVector(2);
int depth = curve.depth();
CV_Assert( count >= 0 && (depth == CV_32F || depth == CV_32S));
double perimeter = 0;
int i, j = 0;
const int N = 16;
float buf[N];
if( count <= 1 )
return 0.;
bool is_float = depth == CV_32F;
int last = is_closed ? count-1 : 0;
const Point* pti = (const Point*)curve.data;
const Point2f* ptf = (const Point2f*)curve.data;
Point2f prev = is_float ? ptf[last] : Point2f((float)pti[last].x,(float)pti[last].y);
for( i = 0; i < count; i++ )
{
Point2f p = is_float ? ptf[i] : Point2f((float)pti[i].x,(float)pti[i].y);
float dx = p.x - prev.x, dy = p.y - prev.y;
buf[j] = dx*dx + dy*dy;
if( ++j == N || i == count-1 )
{
Mat bufmat(1, j, CV_32F, buf);
sqrt(bufmat, bufmat);
for( ; j > 0; j-- )
perimeter += buf[j-1];
}
prev = p;
}
return perimeter;
}
示例9: guiBilateralUpsample
void guiBilateralUpsample(InputArray srcimage, OutputArray dest, int resizeFactor)
{
string windowName = "bilateral";
namedWindow(windowName);
Mat src = srcimage.getMat();
int alpha = 0; createTrackbar("a",windowName, &alpha, 100);
int r = 3; createTrackbar("r",windowName, &r, 30);
int sc = 30; createTrackbar("sigma_color",windowName, &sc, 255);
int ss = 30; createTrackbar("sigma_space",windowName, &ss, 255);
int iter = 3; createTrackbar("iteration",windowName, &iter, 10);
int key = 0;
while(key!='q')
{
Mat srctemp;
src.copyTo(srctemp);
for(int i=0;i<iter;i++)
{
Mat tmp;
bilateralFilter(srctemp, tmp, 2*r+1, sc, ss, BORDER_REPLICATE);
tmp.copyTo(srctemp);
}
alphaBlend(srcimage, srctemp, alpha/100.0, srctemp);
resize(srctemp, dest, Size(src.cols*resizeFactor, src.rows*resizeFactor), 0,0, INTER_CUBIC);
imshow(windowName, dest);
key = waitKey(30);
if(key=='f')
{
alpha = (alpha != 0) ? 100:0;
setTrackbarPos("a", windowName, alpha);
}
}
destroyWindow(windowName);
}
示例10: guiContrast
void guiContrast(InputArray src_)
{
string window_name = "contrast";
Mat src = src_.getMat();
namedWindow(window_name);
int a = 10;
int b = 0;
cv::createTrackbar("a/10", window_name, &a, 1024);
cv::createTrackbar("b", window_name, &b, 256);
int key = 0;
cv::Mat show;
while (key != 'q')
{
show = a / 10.0*src + b;
imshow(window_name, show);
key = waitKey(33);
if (key == 'l')
{
a--;
setTrackbarPos("a/10", window_name, a);
}
if (key == 'j')
{
a++;
setTrackbarPos("a/10", window_name, a);
}
if (key == 'i')
{
b++;
setTrackbarPos("b", window_name, b);
}
if (key == 'k')
{
b--;
setTrackbarPos("b", window_name, b);
}
}
destroyWindow(window_name);
}
示例11: copyTo
void Mat::copyTo( OutputArray _dst, InputArray _mask ) const
{
Mat mask = _mask.getMat();
if( !mask.data )
{
copyTo(_dst);
return;
}
int cn = channels(), mcn = mask.channels();
CV_Assert( mask.depth() == CV_8U && (mcn == 1 || mcn == cn) );
bool colorMask = mcn > 1;
size_t esz = colorMask ? elemSize1() : elemSize();
BinaryFunc copymask = getCopyMaskFunc(esz);
uchar* data0 = _dst.getMat().data;
_dst.create( dims, size, type() );
Mat dst = _dst.getMat();
if( dst.data != data0 ) // do not leave dst uninitialized
dst = Scalar(0);
if( dims <= 2 )
{
CV_Assert( size() == mask.size() );
Size sz = getContinuousSize(*this, dst, mask, mcn);
copymask(data, step, mask.data, mask.step, dst.data, dst.step, sz, &esz);
return;
}
const Mat* arrays[] = { this, &dst, &mask, 0 };
uchar* ptrs[3];
NAryMatIterator it(arrays, ptrs);
Size sz((int)(it.size*mcn), 1);
for( size_t i = 0; i < it.nplanes; i++, ++it )
copymask(ptrs[0], 0, ptrs[2], 0, ptrs[1], 0, sz, &esz);
}
示例12: compute
// gliese581h suggested filling a cv::Mat with descriptors to enable BFmatcher compatibility
// speed-ups and enhancements by gliese581h
void LUCIDImpl::compute(InputArray _src, std::vector<KeyPoint> &keypoints, OutputArray _desc) {
cv::Mat src_input = _src.getMat();
if (src_input.empty())
return;
CV_Assert(src_input.depth() == CV_8U && src_input.channels() == 3);
Mat_<Vec3b> src;
blur(src_input, src, cv::Size(b_kernel, b_kernel));
int x, y, j, d, p, m = (l_kernel*2+1)*(l_kernel*2+1)*3, width = src.cols, height = src.rows, r, c;
Mat_<uchar> desc(static_cast<int>(keypoints.size()), m);
for (std::size_t i = 0; i < keypoints.size(); ++i) {
x = static_cast<int>(keypoints[i].pt.x)-l_kernel, y = static_cast<int>(keypoints[i].pt.y)-l_kernel, d = x+2*l_kernel, p = y+2*l_kernel, j = x, r = static_cast<int>(i), c = 0;
while (x <= d) {
Vec3b &pix = src((y < 0 ? height+y : y >= height ? y-height : y), (x < 0 ? width+x : x >= width ? x-width : x));
desc(r, c++) = pix[0];
desc(r, c++) = pix[1];
desc(r, c++) = pix[2];
++x;
if (x > d) {
if (y < p) {
++y;
x = j;
}
else
break;
}
}
}
if (_desc.needed())
sort(desc, _desc, SORT_EVERY_ROW | SORT_ASCENDING);
}
示例13: genDescriptor
FeatureValue FeatureShiCorner::genDescriptor( InputArray _image, vector< pair< int, int > > points )
{
//TODO: finish
auto out = FeatureValue();
for( auto point : points )
{
// every kSize x kSize a new feature
const int kSize = descRadius * 2 + 1;
const auto image = _image.getMat();
const auto height = image.rows;
const auto width = image.cols;
auto x = point.first;
auto y = point.second;
for( int fy = -kSize; fy <= kSize; fy++ )
{
for( int fx = -kSize; fx <= kSize; fx++ )
{
int xD = (x + fx);
int yD = (y + fy);
// not really needed since genPoints removes corners too
// to close to the image edges
if( (xD < 0) || (xD >= width) || (yD < 0) || (yD >= height) )
{
out.push_back( 0 );
}
else
{
out.push_back( (double) image.at< int32_t >( yD, xD ) );
}
}
}
}
return out;
}
示例14: computeImpl
void BriefDescriptorExtractor::computeImpl(InputArray image, std::vector<KeyPoint>& keypoints, OutputArray descriptors) const
{
// Construct integral image for fast smoothing (box filter)
Mat sum;
Mat grayImage = image.getMat();
if( image.type() != CV_8U ) cvtColor( image, grayImage, COLOR_BGR2GRAY );
///TODO allow the user to pass in a precomputed integral image
//if(image.type() == CV_32S)
// sum = image;
//else
integral( grayImage, sum, CV_32S);
//Remove keypoints very close to the border
KeyPointsFilter::runByImageBorder(keypoints, image.size(), PATCH_SIZE/2 + KERNEL_SIZE/2);
descriptors.create((int)keypoints.size(), bytes_, CV_8U);
descriptors.setTo(Scalar::all(0));
test_fn_(sum, keypoints, descriptors);
}
示例15: create
void cv::GlBuffer::copyFrom(InputArray mat_)
{
#ifndef HAVE_OPENGL
(void)mat_;
throw_nogl;
#else
int kind = mat_.kind();
Size _size = mat_.size();
int _type = mat_.type();
create(_size, _type);
switch (kind)
{
case _InputArray::OPENGL_BUFFER:
{
GlBuffer buf = mat_.getGlBuffer();
*this = buf;
break;
}
case _InputArray::GPU_MAT:
{
#if !defined HAVE_CUDA || defined(CUDA_DISABLER)
throw_nocuda;
#else
GpuMat d_mat = mat_.getGpuMat();
impl_->copyFrom(d_mat);
#endif
break;
}
default:
{
Mat mat = mat_.getMat();
impl_->copyFrom(mat, usage_);
}
}
#endif
}