如何使用java OpenCV检测线外矩形

如何使用java OpenCV检测线外矩形,java,opencv,Java,Opencv,我试图从我检测到的线条中找到停车场图像中的矩形。我想画这些矩形。我怎么做?需要帮忙吗? public void detectRect(){ 位图bmp1=BitmapFactory.decodeResource(MainActivity.this.getResources(),R.drawable.parking_beta2); Mat hsvImage=新Mat(); Mat srcRect=新Mat(); 位映射器(bmp1,srrect); Imgproc.cvtColor(srrect

我试图从我检测到的线条中找到停车场图像中的矩形。我想画这些矩形。我怎么做?需要帮忙吗?

public void detectRect(){
位图bmp1=BitmapFactory.decodeResource(MainActivity.this.getResources(),R.drawable.parking_beta2);
Mat hsvImage=新Mat();
Mat srcRect=新Mat();
位映射器(bmp1,srrect);
Imgproc.cvtColor(srrect、hsvImage、Imgproc.COLOR_BGR2HSV);//转换为HSV颜色空间
列表通道=新的ArrayList();
对于(int i=0;i
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