我並不總是有正方形/長方形圖像,有時我也應該匹配圓形圖像。例如下面是2張圖片。 Ball是模板圖像,第二個是Source應該搜索模板的Source。我可以將模板的背景透明化,但是這會產生錯誤,使得白色會降低比賽分數,因爲您在源圖像上看到的球體周圍沒有白色。這些只是2個示例圖片。你有建議/解決方案嗎?Java中圓形圖像的OpenCV模板匹配
0
A
回答
0
如果你知道屬於模板的像素,可以寫你的匹配
總和的絕對差異試驗(僞代碼)
Mat I, T // image and template
vector<Point> template_pixels
Rect sliding_window
vector<double> match_rates
for all rows in image
update sliding_window
for all cols in image
update sliding_window
Mat W = I(sliding_window)
sum = 0
for all rows in template
for all cols in template
if(template_pixels contains pixel i)
sum += abs(W(i) - T(i))
end for
end for
match_rates.pushback(sum)
end for
end for
minMaxLoc(match_rates)
和在圖像行上使用多線程優化它
1
沒關係,你仍然可以使用matchTemplate()
並取得了優異的成績:
You can find a decent tutorial on OpenCV's documentation。順便說一句,這是在那裏共享的演示的輸出。
+0
模板匹配找到最佳結果,即使模板不在源中,它也會標記一個正方形。如果搜索到的圖像真的在源中,那麼得分就像0.9987 ...但在這種情況下,白人的得分將爲0.7 ...我會讓我們說1000個不同圖像的比較,一些會有綠色的一些會有藍色,一些灰色的背景。這將始終影響匹配分數。根據找到或未找到我的情況和具有隨機閾值的分數圖像設置閾值將是一個問題。我知道它會始終高於0.6 ...但仍然... – Anarkie 2014-11-07 13:24:00
2
我認爲你也可以使用直方圖反投影。在那裏你可以使用任意形狀的面具。用反投影圖像旋轉蒙版,您將在圖像中出現對象的區域檢測到峯值,如下面的圖像(顏色映射和縮放)所示。
背投影:
卷積:
編輯:
這是在此基礎上paper。我正在試驗它,並希望在博客中發佈。 這是用C++編寫的。
// model histogram: this is the football template
calcHist(&model32fc3, 1, (const int*)channels, modelMask, histModel, 3, (const int*)histSize, (const float**)ranges, true, false);
// image histogram
calcHist(&image32fc3, 1, (const int*)channels, Mat(), histImage, 3, (const int*)histSize, (const float**)ranges, true, false);
// ratio histogram
divide(histModel, histImage, histRatio);
cv::min(histRatio, 1.0, histRatio);
// backproject ratio histogram
calcBackProject(&image32fc3, 1, (const int*)channels, histRatio, backprj, (const float**)ranges);
// convolve the kernel with the backprojected image
filter2D(backprj, conv, CV_32F, modelMask);
相關問題
- 1. opencv黑色圖像匹配後模板
- 2. 在Java中匹配的Opencv Android模板
- 3. 我如何轉換圖像以匹配OpenCV中的圓形模型
- 4. opencv,模板匹配
- 5. OpenCV模板匹配
- 6. Opencv - 圓形圖像扭曲
- 7. OpenCV模板匹配的繪製矩形匹配
- 8. 模板匹配圖像C#
- 9. OpenCV的匹配圖像
- 10. OpenCV中與Python匹配模板
- 11. 模板匹配的OpenCV性能
- 12. 通過opencv匹配的3D模板
- 13. 在OpenCV中匹配相似的圖像
- 14. 在JAVA中的圓形運動圖像
- 15. 使用OpenCV進行模板匹配
- 16. OpenCV模板匹配和透明度
- 17. OpenCV匹配模板得分不高
- 18. 模板匹配 - 圖像減法
- 19. OpenCV的形狀相匹配
- 20. 模板匹配 - 不同尺寸的模板和圖像
- 21. 使用的模板圖像來匹配目標具有使用的OpenCV
- 22. 圓形圖像?
- 23. OpenCV中的圖像變形
- 24. Java匹配的圓括號
- 25. OpenCV中的形狀上下文匹配
- 26. 旋轉模板圖像並執行模板匹配
- 27. 圓形圖標圖像模糊
- 28. 模糊邊緣的圓形圖像
- 29. 在JAVA中使用Opencv模糊圖像
- 30. 如何使用OpenCV的匹配模板加載多個圖像和一個模板
我不知道python如果這是python我可能會試試:)我在berky寫這個。它是非常簡單但功能強大的語言 - 真棒,因爲你已經知道了 - 只是很難適應。8) – baci 2014-11-07 01:00:31
你是對的,Python有點不同。如果這是Java代碼,我肯定會+1。 – karlphillip 2014-11-07 01:01:44