2012-02-07 25 views
1

給定兩個將源圖像中的每個像素映射到目標圖像中的像素(R2到R2)的cv :: Mat矩陣,我想將源圖像變換爲目標圖像。我sucessfuly這樣做使用循環,但實在是太慢了:使用變換貼圖的OpenCV2變換圖像

cv::Mat srcImg(100,100,CV_8U); 

//fill... 

cv::Mat dstImg(100,100,CV_8U); 

//dst2src ->backprojection 

//these matrices indicates for each pixel in the destination image, where to map it from the source image 

cv::Mat x_dst2src(100,100,CV_64F); 

cv::Mat y_dst2src(100,100,CV_64F); 

//fill... 

for(int ydst=0; ydst!=100;++ydst) 

{ 

    for(int xdst=0; xdst!=100;++xdst) 
    { 
     double xsrc = x_dst2src.at<double>(ydst,xdst); 
     double ysrc = y_dst2src.at<double>(ydst,xdst); 
     double val = getBicubic(srcImg,xsrc,ysrc); 
     dstImg.at<double>(ydst,xdst) = val; 

    } 

} 

這個基本的代碼工作,但速度很慢(我的圖片比100×100大,我必須使用雙三次)。 謝謝,

-O-

回答

2

有這就是所謂的重映射一個很好的OpenCV的函數()。令人驚訝的是,這確實是這種轉變。

爲了加快速度,您應該尋找另一種功能,以一種比簡單位置圖更易於處理器的格式準備地圖。 (它類似於mapTransform(),請在remap()文檔的see also部分中查找它)

快樂重新映射!