2015-06-23 201 views
0

我正在計算兩幅圖像的平均圖像,並且不知道在OpenCV中使用函數mean()的正確方法。如何獲得OpenCV中幾幅圖像的平均圖像(使用C++)?

Mat img1,img2,img3; 
img1=imread("picture1.jpg"); 
img2=imread("picture2.jpg");  
img3=mean(img1,img2); 

但是它說

R6010 
-abort() has been recalled 

我怎樣才能得到IMG1 & IMG2平均? 謝謝。

回答

2

根據OpenCV的文檔:

「功能平均計算數組元素的平均值M,獨立地對每個信道,並返回它:」

這意味着它應該返回你的標爲你的圖像的每一層,第二個參數是一個像素的面具,以執行計算

你是否簡單地試圖做這樣的事情?

img3 =(img1 + img2)* 0.5;

[編輯],以避免一些損失,如果值> 255,你應該將圖像轉換爲CV_32F,執行計算之前,再抹上你的結果將操作使用CV CV_8U ::的ConvertTo opencv documentation on ConvertTo

3

您可以使用cv::accumulate

Mat img3 = Mat::zeros(img1.size(), CV_32F); //larger depth to avoid saturation 
cv::accumulate(img1, img3); 
cv::accumulate(img2, img3); 
img3 = img3/2; 
相關問題