将不规则网格重映射为规则网格



我正在使用remap函数将不规则网格(650 xyz坐标)映射到规则网格(从-5….5步骤1/160开始的160x160点),但我似乎无法使其工作。顺便说一下,我使用的插值是双三次插值。有人能告诉我这样做是否可能吗?提前谢谢。

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 );是浮动的,但当您填充它时,您使用mat.at<double>(i,j) = 5. * value;。我不知道它是否能解决你的问题,但它应该被纠正。

最新更新