2013-12-14 35 views
-1

我正在做一個類似於iOS中的HDR的多個圖像的項目。我已經設法通過相機獲得3張不同曝光的圖像,現在我想對齊它們,因爲在拍攝期間,他的手必須動搖,並且導致所有3張圖像具有稍微不同的對準。iOS和OpenCV:圖像註冊/對齊

我已經導入了OpenCV框架,我一直在探索OpenCV中的函數來對齊/註冊圖像,但什麼都沒發現。 OpenCV中實際上有一個函數來實現這個功能嗎?如果沒有,有沒有其他的選擇?

謝謝!

回答

2

沒有名爲像對齊,你需要做/執行它自己,或者找到一個已經實現的一個功能。

這是一個解決方案。

您需要從所有3張圖像中提取關鍵點並嘗試匹配它們。確保您的關鍵點提取技術對光照變化不變,因爲由於不同的曝光,所有光強度值都有不同的亮度值。你需要匹配你的關鍵點並找到一些差距。然後,您可以使用視差來調整圖像。

請記住,這個答案是如此膚淺,首先你需要做一些關於關鍵點/描述符提取和關鍵點/描述符匹配的研究。

祝你好運!

+0

好的,謝謝你的信息! – yonasstephen

+0

嗨@yonasstephen!你有沒有找到解決方案? – gasparuff

3

在OpenCV 3.0中,您可以使用findTransformECC。我已經從LearnOpenCV.com複製了ECC Image Alignment代碼,其中爲了對齊顏色通道解決了非常類似的問題。該文章還包含Python中的代碼。希望這可以幫助。

// Read the images to be aligned 
Mat im1 = imread("images/image1.jpg"); 
Mat im2 = imread("images/image2.jpg"); 

// Convert images to gray scale; 
Mat im1_gray, im2_gray; 
cvtColor(im1, im1_gray, CV_BGR2GRAY); 
cvtColor(im2, im2_gray, CV_BGR2GRAY); 

// Define the motion model 
const int warp_mode = MOTION_EUCLIDEAN; 

// Set a 2x3 or 3x3 warp matrix depending on the motion model. 
Mat warp_matrix; 

// Initialize the matrix to identity 
if (warp_mode == MOTION_HOMOGRAPHY) 
    warp_matrix = Mat::eye(3, 3, CV_32F); 
else 
    warp_matrix = Mat::eye(2, 3, CV_32F); 

// Specify the number of iterations. 
int number_of_iterations = 5000; 

// Specify the threshold of the increment 
// in the correlation coefficient between two iterations 
double termination_eps = 1e-10; 

// Define termination criteria 
TermCriteria criteria (TermCriteria::COUNT+TermCriteria::EPS, number_of_iterations, termination_eps); 

// Run the ECC algorithm. The results are stored in warp_matrix. 
findTransformECC(
      im1_gray, 
      im2_gray, 
      warp_matrix, 
      warp_mode, 
      criteria 
     ); 

// Storage for warped image. 
Mat im2_aligned; 

if (warp_mode != MOTION_HOMOGRAPHY) 
    // Use warpAffine for Translation, Euclidean and Affine 
    warpAffine(im2, im2_aligned, warp_matrix, im1.size(), INTER_LINEAR + WARP_INVERSE_MAP); 
else 
    // Use warpPerspective for Homography 
    warpPerspective (im2, im2_aligned, warp_matrix, im1.size(),INTER_LINEAR + WARP_INVERSE_MAP); 

// Show final result 
imshow("Image 1", im1); 
imshow("Image 2", im2); 
imshow("Image 2 Aligned", im2_aligned); 
waitKey(0);