CvException Android

asked 2015-05-27 12:34:44 -0600

Good afternoon , I'm trying to make an example Number Plate Recognition Using SVM and Neural Networks book Mastering OpenCV with Practical Computer Vision Projects on Android, but is giving error in floodfill function. Could anyone help me ?

My Code:

 // convert image to gray
        Imgproc.cvtColor(this.mRgba, this.mGray, Imgproc.COLOR_BGR2GRAY);

        // remove possible noise generated by the camera
        //Imgproc.GaussianBlur(this.mGray, this.mGray, new Size(5, 5), 0, 0);
        Imgproc.blur(this.mGray, this.mGray, new Size(5, 5));

        // find the vertical edges
        // object have high density of vertical lines
        // xorder = 1, yorder = 0, ksize = 3
        Imgproc.Sobel(this.mGray, this.mSobel, CvType.CV_8U, 1, 0, 3, 1, 0);

        // threshold filter
        // obtain a binary image with a threshold value obtained through Otsu's method
        Imgproc.threshold(this.mSobel, this.mThreshold, 0, 255, Imgproc.THRESH_OTSU + Imgproc.THRESH_BINARY);

        this.mElement = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(17, 3));
        Imgproc.morphologyEx(this.mThreshold, this.mThreshold, Imgproc.MORPH_CLOSE, this.mElement);

        // find contours of possibles object
        List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
        List<RotatedRect> rects = new ArrayList<RotatedRect>();

        Imgproc.findContours(this.mThreshold, contours, new Mat(), Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_NONE);

        for (int i = 0; i < contours.size(); i++) {

            //Convert contours(i) from MatOfPoint to MatOfPoint2f
            MatOfPoint2f temp = new MatOfPoint2f(contours.get(i).toArray());
            RotatedRect mr = Imgproc.minAreaRect(temp);

            if (verifySizes(mr)) {
                contours.remove(i);
            } else {
                rects.add(mr);
            }
        }

        // initialize rand and get 5 points around center for floodfill algorithm
        Random random = new Random();
        for(int i=0; i< rects.size(); i++) {

            // for better rect cropping for each possible box
            // make floodfill algorithm because the plate has white background
            // and then we can retrieve more clearly the contour box

            // get the min size between width and height
            double minSize = (rects.get(i).size.width < rects.get(i).size.height) ? rects.get(i).size.width : rects.get(i).size.height;
            minSize = minSize - minSize *0.5;

            // initialize floodfill parameters and variables
            this.mask.create(this.mRgba.rows() + 2, this.mRgba.cols() + 2, CvType.CV_8UC1);
            this.mask.setTo(new Scalar(0,0,0));

            int loDiff = 30;
            int upDiff = 30;
            int connectivity = 4;
            int newMaskVal = 255;
            int NumSeeds = 10;
            int flags = connectivity + (newMaskVal << 8) + Imgproc.FLOODFILL_FIXED_RANGE + Imgproc.FLOODFILL_MASK_ONLY;

            Rect ccomp = new Rect();

            for (int j = 0; j < NumSeeds; j++) {
                Point seed = new Point();
                seed.x = Math.round(rects.get(i).center.x + random.nextDouble() % (int)minSize-(minSize/2));
                seed.y = Math.round(rects.get(i).center.y + random.nextDouble() % (int)minSize-(minSize/2));

                // Scalar(255,0,0) = color white
                int area = Imgproc.floodFill(this.mRgba, this.mask, seed, new Scalar(255,0,0), ccomp, new Scalar(loDiff, loDiff, loDiff), new Scalar(upDiff, upDiff, upDiff), flags);
            }
        }

Error on line: int area = Imgproc.floodFill(this.mRgba, this.mask, seed, new Scalar(255,0,0), ccomp, new Scalar(loDiff, loDiff, loDiff), new Scalar(upDiff, upDiff, upDiff), flags);

CvException [org.opencv.core.CvException: cv::Exception: /home/reports/ci/slave_desktop/50- SDK/opencv/modules/imgproc/src/floodfill.cpp:623: error: (-210) in function void cvFloodFill(CvArr, CvPoint, CvScalar, CvScalar, CvScalar, CvConnectedComp, int, CvArr*)]

edit retag flag offensive close merge delete