簡體   English   中英

在Android中我如何使用openCV計算圖像中的行數

[英]In android how do I count the number of lines in a image using openCV

這是我嘗試的方法。我將輸出作為Imageview對象的img2中的灰度圖像輸出。

問題在於lines.cols()將所有內容都視為一行。

我希望計數准確地如第一張圖所示(我的意思是分隔停車場的行,汽車可以在其中占用的行)中顯示的較大行數。 我的輸出圖像有人可以指導我如何獲取確切的停車位我使用過openCV 2.4版,過去2天我一直在努力

 public String getCount() {

    Bitmap bitmap = BitmapFactory.decodeResource(getApplicationContext().getResources(), R.drawable.park);
    mat = new Mat();
    edges = new Mat();
    Mat mRgba = new Mat(612, 816, CvType.CV_8UC1);
    Mat lines = new Mat();

    Utils.bitmapToMat(bitmap, mat);
    Imgproc.Canny(mat, edges, 50, 90);

    int threshold = 50;
    int minLineSize = 20;
    int lineGap = 20;

    Imgproc.HoughLinesP(edges, lines, 1, Math.PI / 180, threshold, minLineSize, lineGap);

    int count = lines.cols();
    int coun= lines.rows();
    System.out.println("count = " + count);
    System.out.println("coun = " + coun);
    String cou = String.valueOf(count);

    for (int x = 0; x < lines.cols(); x++) {
        double[] vec = lines.get(0, x);
        double x1 = vec[0],
                y1 = vec[1],
                x2 = vec[2],
                y2 = vec[3];

        Point start = new Point(x1, y1);
        Point end = new Point(x2, y2);
        Core.line(mRgba, start, end, new Scalar(255, 0, 0), 3);

    }

    Bitmap bmp = Bitmap.createBitmap(mRgba.cols(), mRgba.rows(), Bitmap.Config.ARGB_8888);
    Utils.matToBitmap(mRgba, bmp);
    bitmap = bmp;

    Drawable d = new BitmapDrawable(Resources.getSystem(), bitmap);
    img2.setImageDrawable(d);

    return cou;
}

您應該修改有關OpenCV計數的眾多答案之一,其中每種不同情況下的檢測類型都不同。 您應該為停車線制作自己的模型。 檢查其中的一些方法/檢測器Haar級聯分類器潛在的SVMWord of Bag

您還可以修改一些對其他東西有用的答案,例如下面對於硬幣的答案,只有您應該搜索停車線的形狀而不是硬幣:

http://answers.opencv.org/question/36111/how-to-count-number-of-coins-in-android-opencv/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM