本文整理汇总了C++中InputArrayOfArrays类的典型用法代码示例。如果您正苦于以下问题:C++ InputArrayOfArrays类的具体用法?C++ InputArrayOfArrays怎么用?C++ InputArrayOfArrays使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了InputArrayOfArrays类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: computeShadowMasks
// Computes the shadows occlusion where we cannot reconstruct the model
void GrayCodePattern_Impl::computeShadowMasks( InputArrayOfArrays blackImages, InputArrayOfArrays whiteImages,
OutputArrayOfArrays shadowMasks ) const
{
std::vector<Mat>& whiteImages_ = *( std::vector<Mat>* ) whiteImages.getObj();
std::vector<Mat>& blackImages_ = *( std::vector<Mat>* ) blackImages.getObj();
std::vector<Mat>& shadowMasks_ = *( std::vector<Mat>* ) shadowMasks.getObj();
shadowMasks_.resize( whiteImages_.size() );
int cam_width = whiteImages_[0].cols;
int cam_height = whiteImages_[0].rows;
// TODO: parallelize for
for( int k = 0; k < (int) shadowMasks_.size(); k++ )
{
shadowMasks_[k] = Mat( cam_height, cam_width, CV_8U );
for( int i = 0; i < cam_width; i++ )
{
for( int j = 0; j < cam_height; j++ )
{
double white = whiteImages_[k].at<uchar>( Point( i, j ) );
double black = blackImages_[k].at<uchar>( Point( i, j ) );
if( abs(white - black) > blackThreshold )
{
shadowMasks_[k].at<uchar>( Point( i, j ) ) = ( uchar ) 1;
}
else
{
shadowMasks_[k].at<uchar>( Point( i, j ) ) = ( uchar ) 0;
}
}
}
}
}
示例2: run
virtual void run(InputArrayOfArrays _points2d)
{
std::vector<Mat> points2d;
_points2d.getMatVector(points2d);
CV_Assert( _points2d.total() >= 2 );
// Parse 2d points to Tracks
Tracks tracks;
parser_2D_tracks(points2d, tracks);
// Set libmv logs level
libmv_initLogging("");
if (libmv_reconstruction_options_.verbosity_level >= 0)
{
libmv_startDebugLogging();
libmv_setLoggingVerbosity(
libmv_reconstruction_options_.verbosity_level);
}
// Perform reconstruction
libmv_reconstruction_ =
*libmv_solveReconstruction(tracks,
&libmv_camera_intrinsics_options_,
&libmv_reconstruction_options_);
}
示例3: reconstruct
// Reconstruction function for API
void
reconstruct(const InputArrayOfArrays points2d, OutputArrayOfArrays projection_matrices, OutputArray points3d,
bool is_projective, bool has_outliers, bool is_sequence)
{
int nviews = points2d.total();
cv::Mat F;
// OpenCV data types
std::vector<cv::Mat> pts2d;
points2d.getMatVector(pts2d);
int depth = pts2d[0].depth();
// Projective reconstruction
if (is_projective)
{
// Two view reconstruction
if (nviews == 2)
{
// Get fundamental matrix
fundamental8Point(pts2d[0], pts2d[1], F, has_outliers);
// Get Projection matrices
cv::Mat P, Pp;
projectionsFromFundamental(F, P, Pp);
projection_matrices.create(2, 1, depth);
P.copyTo(projection_matrices.getMatRef(0));
Pp.copyTo(projection_matrices.getMatRef(1));
// Triangulate and find 3D points using inliers
triangulatePoints(points2d, projection_matrices, points3d);
}
}
// Affine reconstruction
else
{
// Two view reconstruction
if (nviews == 2)
{
}
else
{
}
}
}
示例4: extract
void descriptorExtractor::extract(InputArrayOfArrays inputimg, OutputArray feature, String feature_blob)
{
if (net_ready)
{
Blob<float>* input_layer = convnet->input_blobs()[0];
input_layer->Reshape(1, num_channels,
input_geometry.height, input_geometry.width);
/* Forward dimension change to all layers. */
convnet->Reshape();
std::vector<cv::Mat> input_channels;
wrapInput(&input_channels);
if (inputimg.kind() == 65536)
{/* this is a Mat */
Mat img = inputimg.getMat();
preprocess(img, &input_channels);
convnet->ForwardPrefilled();
/* Copy the output layer to a std::vector */
Blob<float>* output_layer = convnet->blob_by_name(feature_blob).get();
const float* begin = output_layer->cpu_data();
const float* end = begin + output_layer->channels();
std::vector<float> featureVec = std::vector<float>(begin, end);
cv::Mat feature_mat = cv::Mat(featureVec, true).t();
feature_mat.copyTo(feature);
}
else
{/* This is a vector<Mat> */
vector<Mat> img;
inputimg.getMatVector(img);
Mat feature_vector;
for (unsigned int i = 0; i < img.size(); ++i)
{
preprocess(img[i], &input_channels);
convnet->ForwardPrefilled();
/* Copy the output layer to a std::vector */
Blob<float>* output_layer = convnet->blob_by_name(feature_blob).get();
const float* begin = output_layer->cpu_data();
const float* end = begin + output_layer->channels();
std::vector<float> featureVec = std::vector<float>(begin, end);
if (i == 0)
{
feature_vector = cv::Mat(featureVec, true).t();
int dim_feature = feature_vector.cols;
feature_vector.resize(img.size(), dim_feature);
}
feature_vector.row(i) = cv::Mat(featureVec, true).t();
}
feature_vector.copyTo(feature);
}
}
else
std::cout << "Device must be set properly using constructor and the net must be set in advance using loadNet.";
};
示例5: collectCalibrationData
static void collectCalibrationData( InputArrayOfArrays objectPoints,
InputArrayOfArrays imagePoints1,
InputArrayOfArrays imagePoints2,
Mat& objPtMat, Mat& imgPtMat1, Mat* imgPtMat2,
Mat& npoints )
{
int nimages = (int)objectPoints.total();
int i, j = 0, ni = 0, total = 0;
CV_Assert(nimages > 0 && nimages == (int)imagePoints1.total() &&
(!imgPtMat2 || nimages == (int)imagePoints2.total()));
cout << " Number of Frames: " << nimages << endl;
for( i = 0; i < nimages; i++ )
{
cout << endl << "Object Points: " << endl;
printMatOBJ(objectPoints.getMat(i));
cout << endl << "Image Points: " << endl;
printMatIMG(imagePoints1.getMat(i));
ni = objectPoints.getMat(i).checkVector(3, CV_32F);
CV_Assert( ni >= 0 );
total += ni;
}
npoints.create(1, (int)nimages, CV_32S);
objPtMat.create(1, (int)total, CV_32FC3);
imgPtMat1.create(1, (int)total, CV_32FC2);
Point2f* imgPtData2 = 0;
if( imgPtMat2 )
{
imgPtMat2->create(1, (int)total, CV_32FC2);
imgPtData2 = imgPtMat2->ptr<Point2f>();
}
Point3f* objPtData = objPtMat.ptr<Point3f>();
Point2f* imgPtData1 = imgPtMat1.ptr<Point2f>();
for( i = 0; i < nimages; i++, j += ni )
{
Mat objpt = objectPoints.getMat(i);
Mat imgpt1 = imagePoints1.getMat(i);
ni = objpt.checkVector(3, CV_32F);
int ni1 = imgpt1.checkVector(2, CV_32F);
CV_Assert( ni > 0 && ni == ni1 );
npoints.at<int>(i) = ni;
memcpy( objPtData + j, objpt.data, ni*sizeof(objPtData[0]) );
memcpy( imgPtData1 + j, imgpt1.data, ni*sizeof(imgPtData1[0]) );
if( imgPtData2 )
{
Mat imgpt2 = imagePoints2.getMat(i);
int ni2 = imgpt2.checkVector(2, CV_32F);
CV_Assert( ni == ni2 );
memcpy( imgPtData2 + j, imgpt2.data, ni*sizeof(imgPtData2[0]) );
}
}
}
示例6: asRowMatrix
static Mat asRowMatrix(InputArrayOfArrays src, int rtype, double alpha=1, double beta=0) {
// make sure the input data is a vector of matrices or vector of vector
if(src.kind() != _InputArray::STD_VECTOR_MAT && src.kind() != _InputArray::STD_VECTOR_VECTOR) {
String error_message = "The data is expected as InputArray::STD_VECTOR_MAT (a std::vector<Mat>) or _InputArray::STD_VECTOR_VECTOR (a std::vector< std::vector<...> >).";
CV_Error(Error::StsBadArg, error_message);
}
// number of samples
size_t n = src.total();
// return empty matrix if no matrices given
if(n == 0)
return Mat();
// dimensionality of (reshaped) samples
size_t d = src.getMat(0).total();
// create data matrix
Mat data((int)n, (int)d, rtype);
// now copy data
for(unsigned int i = 0; i < n; i++) {
// make sure data can be reshaped, throw exception if not!
if(src.getMat(i).total() != d) {
String error_message = format("Wrong number of elements in matrix #%d! Expected %d was %d.", i, d, src.getMat(i).total());
CV_Error(Error::StsBadArg, error_message);
}
// get a hold of the current row
Mat xi = data.row(i);
// make reshape happy by cloning for non-continuous matrices
if(src.getMat(i).isContinuous()) {
src.getMat(i).reshape(1, 1).convertTo(xi, rtype, alpha, beta);
} else {
src.getMat(i).clone().reshape(1, 1).convertTo(xi, rtype, alpha, beta);
}
}
return data;
}
示例7: asColumnMatrix
//------------------------------------------------------------------------------
// libfacerec::asColumnMatrix
//------------------------------------------------------------------------------
Mat libfacerec::asColumnMatrix(InputArrayOfArrays src, int rtype, double alpha, double beta) {
// make sure the input data is a vector of matrices or vector of vector
if(src.kind() != _InputArray::STD_VECTOR_MAT && src.kind() != _InputArray::STD_VECTOR_VECTOR) {
CV_Error(CV_StsBadArg, "The data is expected as InputArray::STD_VECTOR_MAT (a std::vector<Mat>) or _InputArray::STD_VECTOR_VECTOR (a std::vector< vector<...> >).");
}
int n = (int) src.total();
// return empty matrix if no data given
if(n == 0)
return Mat();
// dimensionality of samples
int d = src.getMat(0).total();
// create data matrix
Mat data(d, n, rtype);
// now copy data
for(int i = 0; i < n; i++) {
// make sure data can be reshaped, throw exception if not!
if(src.getMat(i).total() != d) {
string error_message = format("Wrong number of elements in matrix #%d! Expected %d was %d.", i, d, src.getMat(i).total());
CV_Error(CV_StsBadArg, error_message);
}
// get a hold of the current row
Mat yi = data.col(i);
// make reshape happy by cloning for non-continuous matrices
if(src.getMat(i).isContinuous()) {
src.getMat(i).reshape(1, d).convertTo(yi, rtype, alpha, beta);
} else {
src.getMat(i).clone().reshape(1, d).convertTo(yi, rtype, alpha, beta);
}
}
return data;
}
示例8: train
//------------------------------------------------------------------------------
// Eigenfaces
//------------------------------------------------------------------------------
void Eigenfaces::train(InputArrayOfArrays _src, InputArray _local_labels) {
if(_src.total() == 0) {
String error_message = format("Empty training data was given. You'll need more than one sample to learn a model.");
CV_Error(Error::StsBadArg, error_message);
} else if(_local_labels.getMat().type() != CV_32SC1) {
String error_message = format("Labels must be given as integer (CV_32SC1). Expected %d, but was %d.", CV_32SC1, _local_labels.type());
CV_Error(Error::StsBadArg, error_message);
}
// make sure data has correct size
if(_src.total() > 1) {
for(int i = 1; i < static_cast<int>(_src.total()); i++) {
if(_src.getMat(i-1).total() != _src.getMat(i).total()) {
String error_message = format("In the Eigenfaces method all input samples (training images) must be of equal size! Expected %d pixels, but was %d pixels.", _src.getMat(i-1).total(), _src.getMat(i).total());
CV_Error(Error::StsUnsupportedFormat, error_message);
}
}
}
// get labels
Mat labels = _local_labels.getMat();
// observations in row
Mat data = asRowMatrix(_src, CV_64FC1);
// number of samples
int n = data.rows;
// assert there are as much samples as labels
if(static_cast<int>(labels.total()) != n) {
String error_message = format("The number of samples (src) must equal the number of labels (labels)! len(src)=%d, len(labels)=%d.", n, labels.total());
CV_Error(Error::StsBadArg, error_message);
}
// clear existing model data
_labels.release();
_projections.clear();
// clip number of components to be valid
if((_num_components <= 0) || (_num_components > n))
_num_components = n;
// perform the PCA
PCA pca(data, Mat(), PCA::DATA_AS_ROW, _num_components);
// copy the PCA results
_mean = pca.mean.reshape(1,1); // store the mean vector
_eigenvalues = pca.eigenvalues.clone(); // eigenvalues by row
transpose(pca.eigenvectors, _eigenvectors); // eigenvectors by column
// store labels for prediction
_labels = labels.clone();
// save projections
for(int sampleIdx = 0; sampleIdx < data.rows; sampleIdx++) {
Mat p = subspaceProject(_eigenvectors, _mean, data.row(sampleIdx));
_projections.push_back(p);
}
}
示例9: mixChannels
void cv::mixChannels(InputArrayOfArrays src, InputArrayOfArrays dst,
const vector<int>& fromTo)
{
if(fromTo.empty())
return;
int i, nsrc = (int)src.total(), ndst = (int)dst.total();
CV_Assert(fromTo.size()%2 == 0 && nsrc > 0 && ndst > 0);
cv::AutoBuffer<Mat> _buf(nsrc + ndst);
Mat* buf = _buf;
for( i = 0; i < nsrc; i++ )
buf[i] = src.getMat(i);
for( i = 0; i < ndst; i++ )
buf[nsrc + i] = dst.getMat(i);
mixChannels(&buf[0], nsrc, &buf[nsrc], ndst, &fromTo[0], fromTo.size()/2);
}
示例10: reconstruct
void
reconstruct(InputArrayOfArrays points2d, OutputArray Rs, OutputArray Ts, InputOutputArray K,
OutputArray points3d, bool is_projective)
{
const int nviews = points2d.total();
CV_Assert( nviews >= 2 );
// Projective reconstruction
if (is_projective)
{
// calls simple pipeline
reconstruct_(points2d, Rs, Ts, K, points3d);
}
// Affine reconstruction
else
{
// TODO: implement me
}
}
示例11: compute
void Feature2D::compute( InputArrayOfArrays _images,
std::vector<std::vector<KeyPoint> >& keypoints,
OutputArrayOfArrays _descriptors )
{
CV_INSTRUMENT_REGION();
if( !_descriptors.needed() )
return;
vector<Mat> images;
_images.getMatVector(images);
size_t i, nimages = images.size();
CV_Assert( keypoints.size() == nimages );
CV_Assert( _descriptors.kind() == _InputArray::STD_VECTOR_MAT );
vector<Mat>& descriptors = *(vector<Mat>*)_descriptors.getObj();
descriptors.resize(nimages);
for( i = 0; i < nimages; i++ )
{
compute(images[i], keypoints[i], descriptors[i]);
}
}
示例12: setChannels
void ACFFeatureEvaluatorImpl::setChannels(InputArrayOfArrays channels)
{
channels_.clear();
vector<Mat> ch;
channels.getMatVector(ch);
for( size_t i = 0; i < ch.size(); ++i )
{
const Mat &channel = ch[i];
Mat_<int> acf_channel = Mat_<int>::zeros(channel.rows / 4, channel.cols / 4);
for( int row = 0; row < channel.rows; row += 4 )
{
for( int col = 0; col < channel.cols; col += 4 )
{
int sum = 0;
for( int cell_row = row; cell_row < row + 4; ++cell_row )
for( int cell_col = col; cell_col < col + 4; ++cell_col )
sum += (int)channel.at<float>(cell_row, cell_col);
acf_channel(row / 4, col / 4) = sum;
}
}
channels_.push_back(acf_channel.clone());
}
}
示例13: update
void LBPH::update(InputArrayOfArrays _in_src, InputArray _in_labels) {
// got no data, just return
if(_in_src.total() == 0)
return;
this->train(_in_src, _in_labels, true);
}
示例14: getProjPixel
// For a (x,y) pixel of the camera returns the corresponding projector's pixel
bool GrayCodePattern_Impl::getProjPixel( InputArrayOfArrays patternImages, int x, int y, Point &projPix ) const
{
std::vector<Mat>& _patternImages = *( std::vector<Mat>* ) patternImages.getObj();
std::vector<uchar> grayCol;
std::vector<uchar> grayRow;
bool error = false;
int xDec, yDec;
// process column images
for( size_t count = 0; count < numOfColImgs; count++ )
{
// get pixel intensity for regular pattern projection and its inverse
double val1 = _patternImages[count * 2].at<uchar>( Point( x, y ) );
double val2 = _patternImages[count * 2 + 1].at<uchar>( Point( x, y ) );
// check if the intensity difference between the values of the normal and its inverse projection image is in a valid range
if( abs(val1 - val2) < whiteThreshold )
error = true;
// determine if projection pixel is on or off
if( val1 > val2 )
grayCol.push_back( 1 );
else
grayCol.push_back( 0 );
}
xDec = grayToDec( grayCol );
// process row images
for( size_t count = 0; count < numOfRowImgs; count++ )
{
// get pixel intensity for regular pattern projection and its inverse
double val1 = _patternImages[count * 2 + numOfColImgs * 2].at<uchar>( Point( x, y ) );
double val2 = _patternImages[count * 2 + numOfColImgs * 2 + 1].at<uchar>( Point( x, y ) );
// check if the intensity difference between the values of the normal and its inverse projection image is in a valid range
if( abs(val1 - val2) < whiteThreshold )
error = true;
// determine if projection pixel is on or off
if( val1 > val2 )
grayRow.push_back( 1 );
else
grayRow.push_back( 0 );
}
yDec = grayToDec( grayRow );
if( (yDec >= params.height || xDec >= params.width) )
{
error = true;
}
projPix.x = xDec;
projPix.y = yDec;
return error;
}
示例15: estimateTransform
Stitcher::Status Stitcher::estimateTransform(InputArrayOfArrays images, InputArrayOfArrays masks)
{
CV_INSTRUMENT_REGION();
images.getUMatVector(imgs_);
masks.getUMatVector(masks_);
Status status;
if ((status = matchImages()) != OK)
return status;
if ((status = estimateCameraParams()) != OK)
return status;
return OK;
}