本文整理汇总了C++中cv::Mat_::create方法的典型用法代码示例。如果您正苦于以下问题:C++ Mat_::create方法的具体用法?C++ Mat_::create怎么用?C++ Mat_::create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cv::Mat_
的用法示例。
在下文中一共展示了Mat_::create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: paste_images_gallery
void paste_images_gallery(const std::vector<cv::Mat_<T> > & in,
cv::Mat_<T> & out,
int gallerycols, T background_color,
bool draw_borders = false, cv::Scalar border_color = CV_RGB(0,0,0)) {
if (in.size() == 0) {
out.create(0, 0);
return;
}
int cols1 = in[0].cols, rows1 = in[0].rows, nimgs = in.size();
// prepare output
int galleryrows = std::ceil(1. * nimgs / gallerycols);
out.create(rows1 * galleryrows, cols1 * gallerycols);
// printf("nimgs:%i, gallerycols:%i, galleryrows:%i\n", nimgs, gallerycols, galleryrows);
out.setTo(background_color);
// paste images
for (int img_idx = 0; img_idx < nimgs; ++img_idx) {
int galleryx = img_idx % gallerycols, galleryy = img_idx / gallerycols;
cv::Rect roi(galleryx * cols1, galleryy * rows1, cols1, rows1);
// printf("### out:%ix%i, roi %i:'%s'\n", out.cols, out.rows, img_idx, geometry_utils::print_rect(roi).c_str());
if (cols1 != in[img_idx].cols || rows1 != in[img_idx].rows) {
printf("Image %i of size (%ix%i), different from (%ix%i), skipping it.\n",
img_idx, in[img_idx].cols, in[img_idx].rows, cols1, rows1);
cv::line(out, roi.tl(), roi.br(), border_color, 2);
cv::line(out, roi.br(), roi.tl(), border_color, 2);
}
else
in[img_idx].copyTo( out(roi) );
if (draw_borders)
cv::rectangle(out, roi, border_color, 1);
} // end loop img_idx
} // end paste_images_gallery<_T>
示例2: euler
//===========================================================================
// Get the 2D shape (in image space) from global and local parameters
void PDM::CalcShape2D(cv::Mat_<double>& out_shape, const cv::Mat_<double>& params_local, const cv::Vec6d& params_global) const
{
int n = this->NumberOfPoints();
double s = params_global[0]; // scaling factor
double tx = params_global[4]; // x offset
double ty = params_global[5]; // y offset
// get the rotation matrix from the euler angles
cv::Vec3d euler(params_global[1], params_global[2], params_global[3]);
cv::Matx33d currRot = Euler2RotationMatrix(euler);
// get the 3D shape of the object
cv::Mat_<double> Shape_3D = mean_shape + princ_comp * params_local;
// create the 2D shape matrix (if it has not been defined yet)
if((out_shape.rows != mean_shape.rows) || (out_shape.cols != 1))
{
out_shape.create(2*n,1);
}
// for every vertex
for(int i = 0; i < n; i++)
{
// Transform this using the weak-perspective mapping to 2D from 3D
out_shape.at<double>(i ,0) = s * ( currRot(0,0) * Shape_3D.at<double>(i, 0) + currRot(0,1) * Shape_3D.at<double>(i+n ,0) + currRot(0,2) * Shape_3D.at<double>(i+n*2,0) ) + tx;
out_shape.at<double>(i+n,0) = s * ( currRot(1,0) * Shape_3D.at<double>(i, 0) + currRot(1,1) * Shape_3D.at<double>(i+n ,0) + currRot(1,2) * Shape_3D.at<double>(i+n*2,0) ) + ty;
}
}
示例3: assert
// static
cv::Mat_<float> CrossValidator::createCrossValidationMatrix( const vector< const vector<cv::Mat_<float> >* >& rowVectors,
cv::Mat_<int>& labels)
{
assert( !rowVectors.empty());
cv::Mat_<float> vecs;
labels.create( 0,1);
for ( int label = 0; label < rowVectors.size(); ++label)
{
assert( rowVectors[label] != 0);
const vector<cv::Mat_<float> >& rvecs = *rowVectors[label];
assert( !rvecs.empty());
const int colDim = rvecs[0].cols; // Should be the length of each row vector in this class
if ( vecs.empty())
vecs.create(0, colDim);
assert( colDim == vecs.cols); // Ensure this class's row vector length matches what's already stored
for ( int i = 0; i < rvecs.size(); ++i)
{
const cv::Mat_<float>& rv = rvecs[i];
if ( rv.rows != 1 || rv.cols != colDim)
{
std::cerr << "ERROR feature vector size: " << rv.size() << std::endl;
assert( rv.rows == 1 && rv.cols == colDim);
} // end if
vecs.push_back( rv); // Append the row vector to the bottom of the matrix
labels.push_back(label); // Set this vector's class label
} // end for
} // end for
labels = labels.t(); // Make row vector
return vecs;
} // end createCrossValidationMatrix
示例4: Response
//===========================================================================
void Multi_SVR_patch_expert::Response(const cv::Mat_<float> &area_of_interest, cv::Mat_<float> &response)
{
int response_height = area_of_interest.rows - height + 1;
int response_width = area_of_interest.cols - width + 1;
if(response.rows != response_height || response.cols != response_width)
{
response.create(response_height, response_width);
}
// For the purposes of the experiment only use the response of normal intensity, for fair comparison
if(svr_patch_experts.size() == 1)
{
svr_patch_experts[0].Response(area_of_interest, response);
}
else
{
// responses from multiple patch experts these can be gradients, LBPs etc.
response.setTo(1.0);
cv::Mat_<float> modality_resp(response_height, response_width);
for(size_t i = 0; i < svr_patch_experts.size(); i++)
{
svr_patch_experts[i].Response(area_of_interest, modality_resp);
response = response.mul(modality_resp);
}
}
}
示例5: encode
void EncoderBoFSoft::encode(const cv::Mat_<float>& descriptors, cv::Mat_<float>& encoded)
{
int ndata = descriptors.rows;
int ndim = descriptors.cols;
if ( ndim != this->_m_nDim)
{
throw std::runtime_error("dimension not match when encode");
}
encoded.create(ndata,this->_m_nCode);
encoded.setTo(0.0f);
//encoded.zeros(ndata,this->_m_nCode);
#pragma omp parallel for
for(int i=0;i<ndata;i++)
{
Mat index,dist;
this->_m_pTree->findNearest(descriptors.row(i),_m_nz,INT_MAX,index,noArray(),dist);
Scalar mean,std;
cv::meanStdDev(dist,mean,std);
cv::divide(std(0),dist,dist);
for(int j=0;j<_m_nz;j++)
{
encoded(i,index.at<int>(j)) = dist.at<float>(j);
}
}
}
示例6: serialize
void serialize(Archive & ar, ::cv::Mat_<T>& m, const unsigned int version)
{
if(Archive::is_loading::value == true)
{
int cols, rows;
size_t elem_size, elem_type;
ar & cols;
ar & rows;
ar & elem_size;
ar & elem_type;
m.create(rows, cols);
size_t data_size = m.cols * m.rows * elem_size;
ar & boost::serialization::make_array(m.ptr(), data_size);
}
else
{
size_t elem_size = m.elemSize();
size_t elem_type = m.type();
ar & m.cols;
ar & m.rows;
ar & elem_size;
ar & elem_type;
const size_t data_size = m.cols * m.rows * elem_size;
ar & boost::serialization::make_array(m.ptr(), data_size);
}
}
示例7: cameraPose
void CameraGeometry::cameraPose ( cv::Mat_<double> &tvec )
{
tvec.create ( 3,1 );
tvec ( 0,0 ) = mInvExt ( 0,3 );
tvec ( 1,0 ) = mInvExt ( 1,3 );
tvec ( 2,0 ) = mInvExt ( 2,3 );
}
示例8: detectMultiScale
void DetectorLatentSVMOpencv::detectMultiScale(const cv::Mat& img, std::vector<cv::Rect>& boxes, cv::Mat_<float>& confidence, double scaleFactor
, double maxSize, double minSize)
{
double r = 1.0;
Mat imgBGR = img.clone();
if (img.cols > this->_m_intMaxSize)
{
r = double(_m_intMaxSize) / img.cols;
cv::resize(imgBGR,imgBGR,Size(),r,r);
}
LatentSvmDetector detector(this->_m_vecModelFilenames);
vector<LatentSvmDetector::ObjectDetection> detections;
detector.detect(imgBGR,detections);
vector<float> confs;
for(int i=0;i<(int)detections.size();i++)
{
if ( detections[i].score > this->_m_fltThresh)
{
Rect rect = detections[i].rect;
boxes.push_back(Rect(int(rect.x/r),int(rect.y/r),int(rect.width/r),int(rect.height/r)));
confs.push_back(detections[i].score);
}
}
confidence.create((int)confs.size(),1);
for(int i=0;i<confs.size();i++)
{
confidence(i) = confs[i];
}
}
示例9: convertQImageToMat
void convertQImageToMat(QImage &img_qt, cv::Mat_<cv::Vec3b>& img_cv)
{
img_cv.create(img_qt.height(), img_qt.width());
img_qt.convertToFormat(QImage::Format_RGB32);
int lineNum = 0;
int height = img_qt.height();
int width = img_qt.width();
uchar *imgBits = img_qt.bits();
for (int i = 0; i < height; i++)
{
lineNum = i* width * 4;
for (int j = 0; j < width; j++)
{
img_cv(i, j)[2] = imgBits[lineNum + j * 4 + 2];
img_cv(i, j)[1] = imgBits[lineNum + j * 4 + 1];
img_cv(i, j)[0] = imgBits[lineNum + j * 4 + 0];
}
}
}
示例10: Response
//===========================================================================
void CCNF_patch_expert::Response(cv::Mat_<float> &area_of_interest, cv::Mat_<float> &response)
{
int response_height = area_of_interest.rows - height + 1;
int response_width = area_of_interest.cols - width + 1;
if(response.rows != response_height || response.cols != response_width)
{
response.create(response_height, response_width);
}
response.setTo(0);
// the placeholder for the DFT of the image, the integral image, and squared integral image so they don't get recalculated for every response
cv::Mat_<double> area_of_interest_dft;
cv::Mat integral_image, integral_image_sq;
cv::Mat_<float> neuron_response;
// responses from the neural layers
for(size_t i = 0; i < neurons.size(); i++)
{
// Do not bother with neuron response if the alpha is tiny and will not contribute much to overall result
if(neurons[i].alpha > 1e-4)
{
neurons[i].Response(area_of_interest, area_of_interest_dft, integral_image, integral_image_sq, neuron_response);
response = response + neuron_response;
}
}
int s_to_use = -1;
// Find the matching sigma
for(size_t i=0; i < window_sizes.size(); ++i)
{
if(window_sizes[i] == response_height)
{
// Found the correct sigma
s_to_use = i;
break;
}
}
cv::Mat_<float> resp_vec_f = response.reshape(1, response_height * response_width);
cv::Mat out = Sigmas[s_to_use] * resp_vec_f;
response = out.reshape(1, response_height);
// Making sure the response does not have negative numbers
double min;
minMaxIdx(response, &min, 0);
if(min < 0)
{
response = response - min;
}
}
示例11: row
void DistanceTransform<T>::compute(const cv::Mat_<T>& score_in, const PenaltyFunction& fx, const PenaltyFunction& fy, const cv::Point os, cv::Mat_<T>& score_out, cv::Mat_<int>& Ix, cv::Mat_<int>& Iy) const {
// get the dimensionality of the score
const size_t M = score_in.rows;
const size_t N = score_in.cols;
// allocate the output and working matrices
score_out.create(cv::Size(M, N));
Ix.create(cv::Size(N, M));
Iy.create(cv::Size(M, N));
cv::Mat_<T> score_tmp(cv::Size(N, M));
// compute the distance transform across the rows
for (size_t m = 0; m < M; ++m) {
computeRow(score_in[m], score_tmp[m], Ix[m], N, fx, os.x);
}
// transpose the intermediate matrices
transpose(score_tmp, score_tmp);
// compute the distance transform down the columns
for (size_t n = 0; n < N; ++n) {
computeRow(score_tmp[n], score_out[n], Iy[n], M, fy, os.y);
}
// transpose back to the original layout
transpose(score_out, score_out);
transpose(Iy, Iy);
// get argmins
cv::Mat_<int> row(cv::Size(N, 1));
int * const row_ptr = row[0];
for (size_t m = 0; m < M; ++m) {
int * const Iy_ptr = Iy[m];
int * const Ix_ptr = Ix[m];
for (size_t n = 0; n < N; ++n) {
row_ptr[n] = Iy_ptr[Ix_ptr[n]];
}
for (size_t n = 0; n < N; ++n) {
Iy_ptr[n] = row_ptr[n];
}
}
}
示例12: getPixelProbability
void SegmenterHumanSimple::getPixelProbability(const cv::Mat& img, cv::Mat_<float>& prob, vector<Rect> faces)
{
prob.create(img.rows,img.cols);
prob.setTo(0.3f);
for(int i=0;i<faces.size();i++)
{
Rect rect = faces[i];
rect = UtilsOpencv::ScaleRect(rect,Rect(0,0,img.cols,img.rows),1.2,1.5,1.2,1.2);
prob(Rect(rect.x,rect.y,rect.width,img.rows-rect.y)) = 0.7f;
}
}
示例13: ResponseDepth
void Multi_SVR_patch_expert::ResponseDepth(const cv::Mat_<float>& area_of_interest, cv::Mat_<float>& response)
{
int response_height = area_of_interest.rows - height + 1;
int response_width = area_of_interest.cols - width + 1;
if(response.rows != response_height || response.cols != response_width)
{
response.create(response_height, response_width);
}
// With depth patch experts only do raw data modality
svr_patch_experts[0].ResponseDepth(area_of_interest, response);
}
示例14: quaterion
int CameraGeometry::quaterion ( cv::Mat_<double> &quat, bool update )
{
quat.create ( 4,1 );
if ( update ) computePoseMatrix4x4 ( mExt );
double w = mExt ( 0,0 ) + mExt ( 1,1 ) + mExt ( 2,2 ) + 1;
if ( w < 0.0 ) return 1;
w = sqrt ( w );
quat ( 0,0 ) = ( mExt ( 2,1 ) - mExt ( 1,2 ) ) / ( w*2.0 );
quat ( 1,0 ) = ( mExt ( 0,2 ) - mExt ( 2,0 ) ) / ( w*2.0 );
quat ( 2,0 ) = ( mExt ( 1,0 ) - mExt ( 0,1 ) ) / ( w*2.0 );
quat ( 3,0 ) = w / 2.0;
return 0;
}
示例15: TheBoxFilterArrayForm
void CostBoxFilter::TheBoxFilterArrayForm( const cv::Mat_<float> &bIn, cv::Mat_<float> &bOut, int radius )
{
int height, width, iy, ix;
height = bIn.rows;
width = bIn.cols;
bOut.create(height, width);
cv::Mat_<float> cumHorSum(height, width);
float *horSum = new float [width];
for (iy=0; iy<height; ++iy)
{
float s = 0.0f;
for (ix=0; ix<width; ++ix)
{
s += bIn[iy][ix];
horSum[ix] = s;
}
for (ix=0; ix<=radius; ++ix)
cumHorSum[iy][ix] = horSum[ix+radius];
for (; ix<width-radius; ++ix)
cumHorSum[iy][ix] = horSum[ix+radius]-horSum[ix-radius-1];
for (; ix<width; ++ix)
cumHorSum[iy][ix] = horSum[width-1]-horSum[ix-radius-1];
}
float *colSum = new float [height];
for (ix=0; ix<width; ++ix)
{
float s = 0.0f;
for (iy=0; iy<height; ++iy)
{
s += cumHorSum[iy][ix];
colSum[iy] = s;
}
for (iy=0; iy<=radius; ++iy)
bOut[iy][ix] = colSum[iy+radius];
for (; iy<height-radius; ++iy)
bOut[iy][ix] = colSum[iy+radius]-colSum[iy-radius-1];
for (; iy<height; ++iy)
bOut[iy][ix] = colSum[height-1]-colSum[iy-radius-1];
}
delete [] horSum;
delete [] colSum;
}