不规则重映射到正常电网 [英] remap irregular to regular grid

查看:127
本文介绍了不规则重映射到正常电网的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用重映射函数将不规则网格(650 xyz-坐标)映射为常规网格(从-5 .... 5步骤1/160算起160x160点),但我似乎无法得到它加工。顺便说一下,我使用的插值是双三次的。有人可以告诉我是否可以这样做吗?感谢提前。

I'm using the remap function to map a irregular grid( 650 xyz-coordinates ) to a regular one ( 160x160 points from -5....5 step 1/160) but I can't seem to get it working. By the way the interpolation that I use is bicubic. Can someone please tell me if it's even possible to do it like this? thanks in advance.

using namespace cv;
using namespace POINTS;

std::ofstream file;
Mat src(400,3,CV_32F);
Mat dst(160,160,CV_32F);
Mat map_x;
Mat map_y;
int ind = 0;

Mat matx( 400, 1, CV_32F, &pointsx );
Mat maty( 400, 1, CV_32F, &pointsy );
Mat matz( 400, 1, CV_32F, &pointsz );


void matrixDump( const Mat* mat );
void createMatrix( Mat* mat );

int main()
{

 hconcat( matx, maty, matx );
 hconcat( matx, matz, src );

 map_x.create( 160,160, CV_32FC1 );
 map_y.create( 160, 160, CV_32FC1 );

 createMatrix( &map_x );
 createMatrix( &map_y );
 Mat T = map_y.t();
 remap( src, dst, map_x, T, CV_INTER_CUBIC, BORDER_CONSTANT, Scalar(0, 0, 0) );

 return 0;
}


void matrixDump( const Mat* mat )
{
    file.open("interpolation.txt");

    for( int i=0; i<mat->rows ; i++ )
    {
       for( int j=0; j<mat->cols;j++)
       {
           file << mat->at<float>(i,j) << " " ;
       }
    }
    file.close();
}


void createMatrix( Mat* mat )
{ 
   for( int i=0; i<mat->rows; i++)
   {
       for( int j=0; j<mat->cols; j++ )
       {
           float value = -1. + (j*2./(mat->rows-1));
           mat->at<float>(i,j) = 5. * value;
       }
   }
}


推荐答案

map_x.create(160,160,CV_32FC1); 是float,但是当您填充它时,使用 mat.at< double>(i, j)= 5. *值; 。我不知道它是否能解决您的问题,但应该纠正。

map_x.create( 160,160, CV_32FC1 ); is float but when you fill it you use mat.at<double>(i,j) = 5. * value; . I don't know if it solve your problem, but it should be corrected.

这篇关于不规则重映射到正常电网的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆