How to detect rectangles from strings using java OpenCV

I am trying to find rectangles in this park image from the lines I have found. And I want to draw these rectangles. How should I do it? Any help please? 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

      

+3
java opencv


source to share


No one has answered this question yet

Check out similar questions:

3799
How do I read / convert an InputStream to a string in Java?
3324
How to generate random integers in a specific range in Java?
3073
How to efficiently loop over each entry in a Java map?
2853
How can I convert String to int in Java?
2171
How to determine if an array contains a specific value in Java?
2108
How can I call one constructor from another in Java?
1915
How do I declare and initialize an array in Java?
1818
How to get enum value from string value in Java?
1729
How to break out of nested loops in Java?
1541
How to split a string in Java



All Articles
Loading...
X
Show
Funny
Dev
Pics