如何使用java OpenCV检测行外的矩形

时间:2017-07-21 13:48:45

标签: java opencv

我正试图从我检测到的线条中找到此停车图像中的矩形。我想绘制这些矩形。我该怎么做?有什么帮助吗? Parking image

public void detectRect(){
        Bitmap bmp1 = BitmapFactory.decodeResource(MainActivity.this.getResources(),R.drawable.parking_beta2);
        Mat hsvImage = new Mat();
        Mat srcRect = new Mat();
        Utils.bitmapToMat(bmp1,srcRect);

        Imgproc.cvtColor(srcRect,hsvImage,Imgproc.COLOR_BGR2HSV);// convert to HSV color space
        List<Mat> channels = new ArrayList<Mat>();
        for(int i = 0; i < hsvImage.channels(); i++) {
            Mat channel = new Mat();
            channels.add(channel);
        }
        Core.split(hsvImage, channels);

        Mat hueImage = channels.get(0);
        Mat hueMask = new Mat();
        Core.inRange(hueImage, new Scalar(92,0,0), new Scalar(93.5,0,0),hueMask);



        Mat lines = new Mat();
        Imgproc.HoughLinesP(hueMask,lines,1,Math.PI/180,10,10,50);

        for (int x = 0; x < lines.rows(); x++) {
            double[] vec = lines.get(x, 0);
            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);

            Imgproc.line(srcRect, start, end, new Scalar(255, 255, 0), 2);
        }

        Utils.matToBitmap(srcRect, bmp1); // transform the Mat to bmp
        ImageView frame = (ImageView) findViewById(R.id.myimage);
        frame.setImageBitmap(bmp1); // display image

0 个答案:

没有答案