2016-11-25 19 views
0

我想使用圖像評估來檢測傳送帶的最小移動(分辨率:31x512,圖像速率:每秒1000次)。皮帶啓動的時刻對我很重要。是否有可能識別OpenCV中噪點圖像之間的最小變化?

如果我做簡歷::兩個連續圖像之間absdiff,我獲得非常嘈雜的結果:

enter image description here

根據電機的機械旋轉傳感器,運動從這裏開始:

enter image description here

我試圖通過級聯的侵蝕和擴張來限制abs-diff圖像,但是我可以在此圖像中檢測到比第二個太晚的最早變化:

enter image description here

以前是否可以找到更改? 這裏是(根據馬達傳感器)的圖像,而不改變該序列:

enter image description here

在該序列中的運動開始的中間圖像中:

enter image description here

+1

1000圖像...不是更好連接到發射的信號PLC從輸送機? – Miki

+0

這是爲了測試,相機系統和傳送帶的時間戳是否同步。在生產系統中,相機(實際上是倫琴)不用於測量運動。 –

回答

0

看起來像I」我發現了一個適用於我的情況的解決方案。 而不是比較空間域的圖像變化,應該應用互相關:

我將兩個圖像轉換爲DFT,乘以DFT-Mats並轉換回來。最大像素值是相關性的中心。只要圖像相同,max-pix保持在相同的位置,否則移動。

實際工作代碼使用3個圖像,圖像1,2和2,3之間2 DFT相乘結果:每秒

Mat img1_(512, 32, CV_16UC1); 
Mat img2_(512, 32, CV_16UC1); 
Mat img3_(512, 32, CV_16UC1); 
//read the data in the images wohever you want. I read from MHD-file 

//Set ROI (if required) 
Mat img1 = img1_(cv::Rect(0,200,32,100)); 
Mat img2 = img2_(cv::Rect(0,200,32,100)); 
Mat img3 = img3_(cv::Rect(0,200,32,100)); 

//Float mats for DFT 
Mat img1f; 
Mat img2f; 
Mat img3f; 

//DFT and produtcts mats 
Mat dft1,dft2,dft3,dftproduct,dftproduct2; 

//Calculate DFT of both images 
img1.convertTo(img1f, CV_32FC1); 
cv::dft(img1f, dft1); 

img2.convertTo(img3f, CV_32FC1); 
cv::dft(img3f, dft3); 

img3.convertTo(img2f, CV_32FC1); 
cv::dft(img2f, dft2); 

//Multiply DFT Mats 
cv::mulSpectrums(dft1,dft2,dftproduct,true); 
cv::mulSpectrums(dft2,dft3,dftproduct2,true); 

//Convert back to space domain 
cv::Mat result,result2; 
cv::idft(dftproduct,result); 
cv::idft(dftproduct2,result2); 

//Not sure if required, I needed it for visualizing 
cv::normalize(result, result, 0, 255, NORM_MINMAX, CV_8UC1); 
cv::normalize(result2, result2, 0, 255, NORM_MINMAX, CV_8UC1); 



//Find maxima positions 
double dummy; 
Point locdummy; Point maxLoc1; Point maxLoc2; 
cv::minMaxLoc(result, &dummy, &dummy, &locdummy, &maxLoc1); 
cv::minMaxLoc(result2, &dummy, &dummy, &locdummy, &maxLoc2); 

//Calculate products simply fot having one value to compare 
int maxlocProd1 = maxLoc1.x*maxLoc1.y; 
int maxlocProd2 = maxLoc2.x*maxLoc2.y; 

//Calculate absolute difference of the products. Not 0 means movement 
int absPosDiff = std::abs(maxlocProd2-maxlocProd1); 


if (absPosDiff>0) 
{ 
    std::cout << id<< std::endl; 
    break; 
} 
相關問題