本文整理汇总了C++中Mat_::channels方法的典型用法代码示例。如果您正苦于以下问题:C++ Mat_::channels方法的具体用法?C++ Mat_::channels怎么用?C++ Mat_::channels使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mat_
的用法示例。
在下文中一共展示了Mat_::channels方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: readMatFromFile
void readMatFromFile(const string& fileName, Mat_<float>& m)
{
CV_Assert(m.channels() == 1);
if(NULL == m.data){
DEBUGMSG("Mat can not be alloced memory");
return;
}
FILE* fp = fopen(fileName.c_str(), "r");
if(NULL == fp){
string msg = "open " + fileName + " error";
DEBUGMSG(msg);
return;
}
int rows = m.rows, cols = m.cols;
float* mPtr;
for(int i = 0; i < rows; ++i){
mPtr = m.ptr<float>(i);
for(int j = 0; j < cols; ++j){
fscanf(fp, "%f,", mPtr+j);
}
}
fclose(fp);
}
示例2:
bool c_FourierTransfrom::ifftw_complex_3d(const Mat_<Vec6d> &_input,
Mat_<Vec6d> &_output)
{
size_t height = _input.rows;
size_t width = _input.cols;
size_t n_channels = _input.channels() / 2;
size_t n_pixels = height * width;
size_t n_data = n_pixels * n_channels;
fftw_complex *in, *out;
fftw_plan p;
in = (fftw_complex *)fftw_malloc(sizeof(fftw_complex) * n_data);
out = (fftw_complex *)fftw_malloc(sizeof(fftw_complex) * n_data);
p = fftw_plan_dft_3d(height, width, n_channels, in, out, FFTW_BACKWARD,
FFTW_ESTIMATE);
/*!< prepare the data */
for (size_t i_row = 0; i_row < height; ++i_row)
{
const Vec3d *p = _input.ptr<Vec3d>(i_row);
for (size_t i_col = 0; i_col < width; ++i_col)
{
size_t index = i_row * width + i_col;
for (size_t k = 0; k < n_channels; ++k)
{
in[n_pixels * k + index][0] = p[i_col][k];
in[n_pixels * k + index][1] = p[i_col][k + n_channels];
}
#if 0
in[index][0] = p[i_col][4];
in[index][1] = p[i_col][5];
in[n_pixels + index][0] = p[i_col][2];
in[n_pixels + index][1] = p[i_col][3];
in[n_pixels * 2 + index][0] = p[i_col][0];
in[n_pixels * 2 + index][1] = p[i_col][1];
#endif
}
}
fftw_execute(p);
/*!< write back data */
_output = Mat_<Vec6d>::zeros(_input.size());
for (size_t i_row = 0; i_row < height; ++i_row)
{
Vec6d *p = _output.ptr<Vec6d>(i_row);
for (size_t i_col = 0; i_col < width; ++i_col)
{
size_t index = i_row * width + i_col;
for (size_t k = 0; k < n_channels; ++k)
{
p[i_col][k] = out[n_pixels * k + index][0];
p[i_col][k + n_channels] = out[n_pixels * k + index][1];
}
#if 0
p[i_col][0] = out[n_pixels * 2 + index][0];
p[i_col][1] = out[n_pixels + index][0];
p[i_col][2] = out[index][0];
p[i_col][3] = out[n_pixels * 2 + index][1];
p[i_col][4] = out[n_pixels + index][1];
p[i_col][5] = out[index][1];
#endif
}
}
_output /= n_data;
fftw_destroy_plan(p);
fftw_free(in);
fftw_free(out);
return true;
}