Quantcast
Channel: OpenCV Q&A Forum - RSS feed
Viewing all articles
Browse latest Browse all 4615

Focus stacking with C++ are not the same as in Java

$
0
0
Firstly, sorry for my english, it's not my mother tongue I have to implement a system of focus stacking in a software, I found an algorithm on Github in Java and I transcribed it in C ++ but the result is not as good. I use OpenCV Thank you in advance PS : if you have a better algorithm in C ++, I do not refuse ^^ C++ result : https://image.noelshack.com/fichiers/2019/15/4/1554990509-test.jpg Java result : https://image.noelshack.com/fichiers/2019/15/4/1554990509-fusion.png Java code : https://github.com/LucasLelaidier/Focus-stacking-java/blame/master/FocusStacking.java My code : FocusStacking::FocusStacking(vector img) : m_img(img) { } Mat FocusStacking::laplacien(Mat image) { int kernel_size = 5; int blur_size = 5; Mat gray; cvtColor(image, gray, COLOR_BGR2GRAY); Mat gauss; Size size(blur_size, blur_size); GaussianBlur(gray, gauss, size, 0); Mat laplace; Laplacian(gauss, laplace, CV_64F, kernel_size, 1, 0); Mat absolute; convertScaleAbs(laplace, absolute); return absolute; } Mat FocusStacking::work() { vector laps; for (unsigned i = 0 ; i < m_img.size() ; i++) { laps.push_back(laplacien(m_img[i])); } Mat stack = Mat(laps[0].size(), m_img[0].type(), double(0)); int index; int indexValue; for(int y = 0 ; y < laps[0].cols ; y++) { for(int x = 0 ; x < laps[0].rows ; x++) { index = -1; indexValue = -1; for(unsigned int i = 0 ; i < laps.size(); i++) { if(indexValue < 0 || laps[i].at(x,y)[0] > indexValue) { indexValue = laps[i].at(x,y)[0]; index = static_cast(i); } } stack.at(x,y) = m_img[static_cast(index)].at(x,y); } } return stack; }

Viewing all articles
Browse latest Browse all 4615


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>