本文整理汇总了C++中cv::Mat::col方法的典型用法代码示例。如果您正苦于以下问题:C++ Mat::col方法的具体用法?C++ Mat::col怎么用?C++ Mat::col使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cv::Mat
的用法示例。
在下文中一共展示了Mat::col方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sharpen_OLD
// How to do sharpening without explicitly using a convolution filter and cv::filter2D
void RFeatures::sharpen_OLD( const cv::Mat &img, cv::Mat &out)
{
out.create( img.size(), img.type()); // Allocate if necessary
int channels = img.channels();
int nc = img.cols * channels;
for ( int j = 1; j < img.rows-1; ++j) // All rows except first and last
{
const uchar* previous = img.ptr<const uchar>(j-1); // Previous row
const uchar* current = img.ptr<const uchar>(j); // Current row
const uchar* next = img.ptr<const uchar>(j+1); // Next row
uchar* output = out.ptr<uchar>(j); // Output row
for ( int i = channels; i < nc - channels; ++i) // All columns except first and last
{
uchar v = 5*current[i] - current[i-channels] - current[i+channels] - previous[i] - next[i];
*output++ = cv::saturate_cast<uchar>(v);
} // end for
} // end for
// Set the unprocesses pixels to 0
cv::Scalar s(0);
if (img.channels() == 3)
s = cv::Scalar(0,0,0);
out.row(0).setTo( s);
out.row(out.rows-1).setTo( s);
out.col(0).setTo( s);
out.col(out.cols-1).setTo( s);
} // end sharpen_OLD
示例2: sharpen2
void sharpen2(const cv::Mat& image, cv::Mat& result)
{
result.create(image.size(), image.type()); // allocate if necessary
int step = image.step1();
const uchar* previous = image.data; // ptr to previous row
const uchar* current = image.data + step; // ptr to current row
const uchar* next = image.data + 2 * step; // ptr to next row
uchar* output = result.data + step; // ptr to output row
for (int j = 1; j < image.rows - 1; j++)
{ // for each row (except first and last)
for (int i = 1; i < image.cols - 1; i++)
{ // for each column (except first and last)
output[i] = cv::saturate_cast<uchar>(5 * current[i] - current[i - 1] - current[i + 1] -
previous[i] - next[i]);
}
previous += step;
current += step;
next += step;
output += step;
}
// Set the unprocess pixels to 0
result.row(0).setTo(cv::Scalar(0));
result.row(result.rows - 1).setTo(cv::Scalar(0));
result.col(0).setTo(cv::Scalar(0));
result.col(result.cols - 1).setTo(cv::Scalar(0));
}
示例3: optimizeEmat
void optimizeEmat (cv::Mat p1, cv::Mat p2, cv::Mat K, cv::Mat *E)
// input: p1, p2, normalized image points correspondences
{
int n = p1.cols;
double* measurement = new double[n];
for (int i=0; i<n; ++i)
measurement[i] = 0;
double opts[LM_OPTS_SZ], info[LM_INFO_SZ];
opts[0]=LM_INIT_MU*0.5; //
opts[1]=1E-50;
opts[2]=1E-100; // original 1e-50
opts[3]=1E-20;
opts[4]= -LM_DIFF_DELTA;
int matIter = 100;
cv::Mat R1, R2, t;
decEssential (E, &R1, &R2, &t);
cv::Mat Rt = // find true R and t
findTrueRt(R1,R2,t,mat2cvpt(p1.col(0)),mat2cvpt(p2.col(0)));
if(Rt.cols < 3) return;
cv::Mat R = Rt.colRange(0,3);
t = Rt.col(3);
Matrix3d Rx;
Rx << R.at<double>(0,0), R.at<double>(0,1), R.at<double>(0,2),
R.at<double>(1,0), R.at<double>(1,1), R.at<double>(1,2),
R.at<double>(2,0), R.at<double>(2,1), R.at<double>(2,2);
Quaterniond q(Rx);
double para[7] = {q.w(), q.x(), q.y(), q.z(), t.at<double>(0),
t.at<double>(1), t.at<double>(2)};
data_optimizeEmat data;
data.p1 = p1;
data.p2 = p2;
data.K = K;
int ret = dlevmar_dif(costfun_optimizeEmat, para, measurement, 7, n,
matIter, opts, info, NULL, NULL, (void*)&data);
delete[] measurement;
q.w() = para[0];
q.x() = para[1];
q.y() = para[2];
q.z() = para[3];
q.normalize();
for (int i=0; i<3; ++i)
for (int j=0; j<3; ++j)
R.at<double>(i,j) = q.matrix()(i,j);
cv::Mat tx = (cv::Mat_<double>(3,3)<< 0, -para[6], para[5],
para[6], 0 , -para[4],
-para[5], para[4], 0 );
tx = tx/sqrt(para[4]*para[4]+para[5]*para[5]+para[6]*para[6]);
*E = tx * R;
// cout<<" "<<R<<endl<<para[4]<<"\t"<<para[5]<<"\t"<<para[6]<<endl;
}
示例4: sharpen
void sharpen(const cv::Mat& image, cv::Mat& result){
// allocate if necessary
result.create(global::image.size(), global::image.type());
std::cout << "Size: " << global::image.size() << std::endl;
std::cout << "Cols: " << global::image.cols << "\n" << "Rows: " << global::image.rows << std::endl;
for (int j=1; j<global::image.rows-1; j++){ // for all rows except first and last
const uchar* previous = global::image.ptr<const uchar>(j-1); // previous row
const uchar* current = global::image.ptr<const uchar>(j); // current row
const uchar* next = global::image.ptr<const uchar>(j+1); // next row
uchar* output = result.ptr<uchar>(j); // output row
for (int i=1; i<global::image.cols-1; i++){
*output = cv::saturate_cast<uchar>(5*current[i]-current[i-1]-current[i+1]-previous[i]-next[i]);
output++;
}
}
// set unprocessed pixels to 0
result.row(0).setTo(cv::Scalar(0));
result.row(result.rows-1).setTo(cv::Scalar(0));
result.col(0).setTo(cv::Scalar(0));
result.col(result.cols-1).setTo(cv::Scalar(0));
}
示例5: sharpen
void Processor::sharpen(const cv::Mat &image, cv::Mat &result) {
startTimer();
// allocate if necessary
result.create(image.rows, image.cols, image.type());
for (int j = 1; j < image.rows - 1; j++) { // for all rows
// (except first and last)
const uchar* previous = image.ptr<const uchar>(j - 1); // previous row
const uchar* current = image.ptr<const uchar>(j); // current row
const uchar* next = image.ptr<const uchar>(j + 1); // next row
uchar* output = result.ptr<uchar>(j); // output row
for (int i = 1; i < image.cols - 1; i++) {
for (int k = 0; k < image.channels(); k++) {
result.at<cv::Vec3b>(j, i)[k] = cv::saturate_cast<uchar>(
5 * image.at<cv::Vec3b>(j, i)[k]
- image.at<cv::Vec3b>(j, i - 1)[k]
- image.at<cv::Vec3b>(j, i + 1)[k]
- image.at<cv::Vec3b>(j - 1, i)[k]
- image.at<cv::Vec3b>(j + 1, i)[k]);
}
}
}
// Set the unprocess pixels to 0
result.row(0).setTo(cv::Scalar(0));
result.row(result.rows - 1).setTo(cv::Scalar(0));
result.col(0).setTo(cv::Scalar(0));
result.col(result.cols - 1).setTo(cv::Scalar(0));
stopTimer("Sharpen");
}
示例6: sharpen
void sharpen(const cv::Mat& image, cv::Mat& result)
{
//allocate if necessary
result.create(image.size(),image.type());
for(int j= 1; j < image.rows-1; ++j) { // for all rows
// except the first and last row
const uchar* previous =
image.ptr<uchar>(j-1);
const uchar* current =
image.ptr<uchar>(j);
const uchar* next =
image.ptr<uchar>(j+1);
uchar* output = result.ptr<uchar>(j); // output row
for(int i= 1; i < (image.cols-1) * image.channels(); ++i) {
// stature_cast: avoid the mathematical expression applied on the pixels leads to a
// result that goes out of the range of the permited pixel value( 0 - 255)
*output ++ = cv::saturate_cast<uchar>(5 * current[i] - current[i-1] - current[i+1] -
previous[i] - next[i]);
}
}
//set the unprocess pixels to zero
result.row(0).setTo(cv::Scalar(0));
result.row(result.rows-1).setTo(cv::Scalar(0));
result.col(0).setTo(cv::Scalar(0));
result.col(result.cols-1).setTo(cv::Scalar(0));
}
示例7: _M
// M - step
// Improves the mean, covariance, and weight of each gaussian using
// the responsibilites computed in the E step
void GMM::_M(const cv::Mat &gamma, const cv::Mat &samples)
{
for(int k = 0; k < _Gaussians.size(); k++)
{
// Get the kth gaussian responsibilities
cv::Mat gammak = gamma.col(k);
// Compute Nk, the sum of all responsibilties for this gaussian
double Nk = cv::sum(gammak)[0];
// Update the mean
cv::Mat uNew = cv::Mat::zeros(gammak.cols, 1, CV_64F);
for(int n = 0; n < gammak.rows; n++)
{
uNew += gammak.at<double>(n, 1) * samples.col(n);
}
uNew /= Nk;
_Gaussians[k].Mean() = uNew;
// Update the covariance
cv::Mat sigmaNew = cv::Mat::zeros(gammak.rows, gammak.rows, CV_64F);
for(int n = 0; n < gammak.rows; n++)
{
cv::Mat meanDistance = samples.col(n) - uNew;
sigmaNew += gammak.at<double>(n, 1) * (meanDistance * meanDistance.t());
}
sigmaNew /= Nk;
_Gaussians[k].Covariance() = sigmaNew;
// Udpate weight
_Gaussians[k].Weight() = Nk / samples.cols;
}
}
示例8: sharpen
void sharpen(cv::Mat &image, cv::Mat &out)
{
out.create(image.size(), image.type());
for(int j=1; j < image.rows-1;j++)
{
const uchar* previous = image.ptr<const uchar>(j-1);
const uchar* current = image.ptr<const uchar>(j);
const uchar* next = image.ptr<const uchar>(j+1);
uchar* output = out.ptr<uchar>(j);
for(int i=1; i<image.cols-1; i++)
{
*output++=cv::saturate_cast<uchar>(
5*current[i]-current[i-1]
-current[i+1]-previous[1]-next[1]);
}
}
out.row(0).setTo(cv::Scalar(0));
out.row(out.rows-1).setTo(cv::Scalar(0));
out.col(0).setTo(cv::Scalar(0));
out.col(out.cols-1).setTo(cv::Scalar(0));
}
示例9: sparse_base
vector<pair<int, double>> OMP(cv::Mat x, cv::Mat base, int coeff_count)
{
vector<pair<int, double>> result;
cv::Mat residual = x.clone();
for (int i = 0; i < coeff_count; ++i)
{
int max_index = 0;
double max_value = 0;
for (int j = 0; j < base.cols; ++j)
{
double current_value = abs(
static_cast<cv::Mat>(residual.t() * base.col(j)).at<double>(0));
if (current_value > max_value)
{
max_value = current_value;
max_index = j;
}
}
result.push_back(make_pair(max_index, 0));
cv::Mat sparse_base(base.rows, result.size(), CV_64FC1);
for (int j = 0; j < result.size(); ++j)
base.col(result[j].first).copyTo(sparse_base.col(j));
cv::Mat beta;
cv::solve(sparse_base.t() * sparse_base,
sparse_base.t() * x, beta, cv::DECOMP_SVD);
for (int j = 0; j < result.size(); ++j)
result[j].second = beta.at<double>(j);
residual -= sparse_base * beta;
}
return result;
}
示例10: ShuffleDataset
/* This function will rearrange dataset for training in a random order. This step is
* necessary to make training more accurate.
*/
void LetterClassifier::ShuffleDataset(cv::Mat &training_data, cv::Mat &label_mat, int numIter)
{
/* initialize random seed: */
srand(time(NULL));
int x = 0, y = 0;
assert(training_data.cols == label_mat.rows);
int numData = training_data.cols;
if (numIter <= 0)
numIter = numData;
if (training_data.type() != CV_32FC1)
training_data.convertTo(training_data, CV_32FC1);
cv::Mat temp_data_mat(training_data.rows, 1, CV_32FC1);
cv::Mat temp_label_mat(1, 1, CV_32FC1);
// Interate 'numIter' to rearrange dataset
for (int n = 0; n < numIter; n++)
{
x = (rand() % numData);
y = (rand() % numData);
// swap data
training_data.col(x).copyTo(temp_data_mat.col(0));
training_data.col(y).copyTo(training_data.col(x));
temp_data_mat.col(0).copyTo(training_data.col(y));
// swap label
label_mat.row(x).copyTo(temp_label_mat.row(0));
label_mat.row(y).copyTo(label_mat.row(x));
temp_label_mat.row(0).copyTo(label_mat.row(y));
}
}
示例11: update
// Update stage
void ParticleFilter::update(cv::Mat measurement)
{
// Propose indicators
std::vector<int> indicators = resample(gmm.weight, gmm.nParticles);
std::vector<double> weights;
wsum = 0;
int i;
std::vector<state_params> temp;
for (int j = 0; j < gmm.nParticles; j++) //update KF for each track using indicator samples
{
i = indicators[j];
gmm.KFtracker[i].predict(gmm.tracks[j].state,gmm.tracks[j].cov);
weights.push_back(mvnpdf(measurement.col(j),gmm.KFtracker[i].H*gmm.tracks[j].state+gmm.KFtracker[i].BH,gmm.KFtracker[i].H*gmm.tracks[j].cov*gmm.KFtracker[i].H.t()+gmm.KFtracker[i].R));
wsum = wsum + weights[j];
gmm.KFtracker[i].update(measurement.col(j),gmm.tracks[j].state,gmm.tracks[j].cov);
temp.push_back(gmm.tracks[j]);
}
for (int i = 0; i < (int)gmm.tracks.size(); i++)
{
weights[i] = weights[i]/wsum;
}
// Re-sample tracks
indicators.clear();
indicators = resample(weights, gmm.nParticles);
for (int j = 0; j < gmm.nParticles; j++) //update KF for each track using indicator samples
{
gmm.tracks[j] = temp[indicators[j]];
}
wsum = 1.0;
}
示例12: sharpen
void sharpen(const cv::Mat& image, cv::Mat& result)
{
result.create(image.size(), image.type()); // allocate if necessary
for (int j = 1; j < image.rows - 1; j++)
{ // for all rows (except first and last)
const uchar* previous = image.ptr<const uchar>(j - 1); // previous row
const uchar* current = image.ptr<const uchar>(j); // current row
const uchar* next = image.ptr<const uchar>(j + 1); // next row
uchar* output = result.ptr<uchar>(j); // output row
for (int i = 1; i < image.cols - 1; i++)
{
*output++ = cv::saturate_cast<uchar>(5 * current[i] - current[i - 1] - current[i + 1] -
previous[i] - next[i]);
// output[i]=
//cv::saturate_cast<uchar>(5*current[i]-current[i-1]-current[i+1]-previous[i]-next[i]);
}
}
// Set the unprocess pixels to 0
result.row(0).setTo(cv::Scalar(0));
result.row(result.rows - 1).setTo(cv::Scalar(0));
result.col(0).setTo(cv::Scalar(0));
result.col(result.cols - 1).setTo(cv::Scalar(0));
}
示例13: performBlendX
void AlphaBlender::performBlendX(const cv::Mat& image1,const cv::Mat& image2,cv::Mat& outputImage){
double alpha=1,beta=0;
for(int i=0;i<image1.cols;i++){
beta=(double)i/(image1.cols-1);
alpha=1-beta;
cv::addWeighted(image1.col(i),alpha,image2.col(i),beta,0,outputImage.col(i));
}
}
示例14: warpAffine
inline
cv::Mat
opt_feat::Shift_Image( cv::Mat src_in, int num_pixels_x, int num_pixels_y)
{
cv::Mat img_out;
cv::Mat rot_mat = (cv::Mat_<double>(2,3) << 1, 0, num_pixels_x, 0, 1, num_pixels_y);
warpAffine( src_in, img_out, rot_mat, src_in.size() );
if (num_pixels_x>0) //Move right
{
cv::Mat col = src_in.col(0);
cv::Mat row = src_in.row(0);
for (int i=0; i<abs(num_pixels_x); ++i)
{
col.col(0).copyTo(img_out.col(i));
}
for (int i=0; i<abs(num_pixels_y); ++i)
{
row.row(0).copyTo(img_out.row(i));
//src_in.copyTo(img_out,crop);
}
}
if (num_pixels_x<0) //Move left
{
int w = src_in.size().width;
int h = src_in.size().height;
cv::Mat col = src_in.col(w-1);
cv::Mat row = src_in.row(h-1);
for (int i=w-abs(num_pixels_x) ; i<w; ++i)
{
col.col(0).copyTo(img_out.col(i));
//row.row(0).copyTo(img_out.row(i));
}
for (int i=h-abs(num_pixels_y) ; i<h; ++i)
{
//col.col(0).copyTo(img_out.col(i));
row.row(0).copyTo(img_out.row(i));
}
}
return img_out;
}
示例15: drawBgImage
void drawBgImage(cv::Mat & render, cv::Mat & bgImage, float yaw, float fov, int nBeams) {
int bgImageStart = bgImage.cols - yaw*nBeams/fov;
for(int c = 0; c<render.cols; c++) {
int cBgImage = bgImageStart + c;
if(cBgImage >= bgImage.cols) cBgImage -= bgImage.cols;
bgImage.col(cBgImage).copyTo(render.col(c));
}
}