2017-01-19 37 views
-1

我一直在試圖在JAVA中找到最好的和最簡單的方法 - 如何使用OpenCV檢測圖像中的迷宮,並計算圖像旋轉到水平位置的角點和角度。使用小方塊定義的OpenCV檢測圖像中物體的角點和角度?

迷宮由放置在角落的3個小黃紙方塊定義。

我發現這部分解決方案:How can I detect registration markers on paper using OpenCV? - 但我沒有能力將它修改爲我工作: -/

兩個測試圖像的情況:

Example image

Example image 2

感謝所有的幫助!

+0

認真嗎?你期待有人會爲你發明算法嗎? – Andremoniy

+0

謝謝你的幫助。 : -/ – Filip

+1

這是一個很酷的學習計算機視覺的項目,不要讓任何人給你解決方案,如果你自己發現它,這將意味着你知道更多的計算機視覺:)如果你有具體問題如何做有些事情,我們會幫助的。這是一個廣泛的問題。 –

回答

1

好的,謝謝你的鼓勵與我的問題。多虧了它,我發現這個部分soloution:

Mat mazeImage = Imgcodecs.imread("vzory/real_5.jpg"); //, Imgcodecs.CV_LOAD_IMAGE_COLOR 
    Mat hsv = new Mat(); 
    Mat treshold = new Mat(); 
    Mat hierarchy = new Mat(); 
    Imgproc.cvtColor(mazeImage, hsv, Imgproc.COLOR_BGR2HSV); 
    Core.inRange(hsv, new Scalar(20,135,135), new Scalar(30, 255, 255), treshold); 

    List<MatOfPoint> contours = new ArrayList<>(); 
    Imgproc.findContours(treshold, contours, hierarchy, Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_SIMPLE); 

    PointContourCollection pointContourCollection = new PointContourCollection(new PointContourComparator()); 

    for (MatOfPoint contour : contours) { 
     Point center = new Point(); 
     Moments moments = Imgproc.moments(contour); 
     center.x = (int) (moments.m10/moments.m00); 
     center.y = (int) (moments.m01/moments.m00); 

     double area = Imgproc.contourArea(contour); 

     if(area > 0.1){ 
      pointContourCollection.add(new PointContour(center, area, contour)); 
     } 
    } 

    Imgproc.drawContours(mazeImage, contours, -1, new Scalar(0, 255, 0), 5); 

類PointContourCollection - ArrayList中的延伸 - 店面只有黃色邊角與中心位置及其區域。 Corners按面積大小按PointContourComparator排序。 Partial result

+0

對我來說很好!爲什麼偏? –

+0

因爲我現在需要找到旋轉圖像水平位置的一些soloution。但有一個「小」問題 - labyrint可以旋轉四個不同的旋轉。我已經計算(現在)所有線的角度 - 但現在我需要找到soloution如何確定什麼樣的角度是「最佳」的方式來實現良好的旋轉。 :-) – Filip

+0

你想如何旋轉它? –