Ask Your Question

mp352's profile - activity

2016-11-30 08:03:51 -0600 received badge  Student (source)
2016-11-14 03:04:42 -0600 received badge  Famous Question (source)
2016-02-03 02:09:16 -0600 received badge  Notable Question (source)
2015-09-16 02:32:03 -0600 received badge  Popular Question (source)
2014-11-06 05:34:52 -0600 asked a question Mat_<uchar>

Hi,

could someone please explain what the code listed below.

Mat_<uchar>::iterator

I tried to understand the tutorial of anpr in Mastering CV but my c++ capabilities are very low. Exists a comparable object or function in Java?

Thanks Manuel

2014-11-05 10:18:34 -0600 received badge  Scholar (source)
2014-11-05 10:18:29 -0600 received badge  Supporter (source)
2014-11-05 10:16:52 -0600 received badge  Critic (source)
2014-11-05 10:04:06 -0600 commented answer OpenCV Error: Assertion failed

Thanks for answering. I have checked the koordinates, widths and heights of the detected rects. One of them has a calculated koordinate r.width+r.x which is wider than the orignial. The original has a width of 505px and one of the rects 507px. How could I avoid this exception?

thanks

2014-11-05 09:03:36 -0600 asked a question OpenCV Error: Assertion failed

Hi,

hopefully my english is good enough for describing my problem. I am working only a short time on opencv. In a little project I tried to detect the number plates from cars. The detection works very well. Only the last function in my script throws an exception.

I tried to create a new mat from the picture and the rectangle but that throws the following exception: OpenCV Error: Assertion failed (0 <= roi.x && 0 <= roi.width && roi.x + roi.width <= m.cols && 0 <= roi.y && 0 <= roi.height && roi.y + roi.height <= m.rows) in cv::Mat::Mat, file ........\opencv\modules\core\src\matrix.cpp, line 323 Exception in thread "main" CvException [org.opencv.core.CvException: cv::Exception: ........\opencv\modules\core\src\matrix.cpp:323: error: (-215) 0 <= roi.x && 0 <= roi.width && roi.x + roi.width <= m.cols && 0 <= roi.y && 0 <= roi.height && roi.y + roi.height <= m.rows in function cv::Mat::Mat

But the detection works fine. the picture shows that the script creates rectangles around them. image description

Could somebody help me?

/*

* To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package demoOpenCV;

import java.util.ArrayList; import java.util.Iterator; import java.util.ListIterator; import org.opencv.core.Core; import org.opencv.core.CvType; import org.opencv.core.Mat; import org.opencv.core.MatOfPoint; import org.opencv.core.MatOfPoint2f; import org.opencv.core.Point; import org.opencv.core.Rect; import org.opencv.core.MatOfRect; import org.opencv.core.RotatedRect; import org.opencv.core.Scalar; import org.opencv.core.Size; import org.opencv.highgui.Highgui; import org.opencv.imgproc.Imgproc; import static org.opencv.imgproc.Imgproc.MORPH_RECT;

/**


  • @author Manuel */ public class NumberPlate {

    public void run() { System.out.println("Kennzeichenerkennung is running...");

    Mat img = Highgui.imread("c:/tmp/plate2.jpg");
    Mat kopie = new Mat();
    img.copyTo(kopie);
    
    Mat img_grey = new Mat();
    
    Mat img_sobel = new Mat();
    
    Mat img_threshold = new Mat();
    
    Mat element = Imgproc.getStructuringElement(MORPH_RECT, new Size(17, 3));
    
    ArrayList<RotatedRect> rects = new ArrayList<RotatedRect>();
    ArrayList<MatOfPoint> contors = new ArrayList<MatOfPoint>();
    
    Mat schild;
    
    Imgproc.cvtColor(img, img_grey, Imgproc.COLOR_BGR2GRAY);
    
    Imgproc.blur(img_grey, img_grey, new Size(5, 5));
    
    Imgproc.Sobel(img_grey, img_sobel, CvType.CV_8U, 1, 0, 3, 1, 0);
    
    Imgproc.threshold(img_sobel, img_threshold, 0, 255,
            ((Imgproc.THRESH_OTSU) + (Imgproc.THRESH_BINARY)));
    
    Imgproc.morphologyEx(img_threshold, img_threshold, Imgproc.MORPH_CLOSE, element);
    
    Imgproc.findContours(img_threshold, contors, new Mat(), Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_NONE);
    
    ListIterator<MatOfPoint> it = contors.listIterator();
    while (it.hasNext()) {
        MatOfPoint2f mp2f = new MatOfPoint2f(it.next().toArray());
        RotatedRect mr = Imgproc.minAreaRect(mp2f);
        double area = Math.abs(Imgproc.contourArea(mp2f));
    
    
    double bbArea = mr.size.area();            
    double ratio = area / bbArea;            
    if ((ratio &lt; 0.45) || (bbArea &lt; 400)) {                
        it.remove();                
    } else {                
        rects.add(mr);                
    }
    
    } for (Iterator<RotatedRect> it1 = rects.iterator(); it1.hasNext();) { RotatedRect roRe = it1.next(); Rect r = roRe.boundingRect();
    Core.rectangle(kopie, new Point((r.x), (r.y)),
            new Point((r.x + r.width), (r.y + r.height)),
            new Scalar(0, 0, 255));
    
    ***schild = kopie.submat(r);***
    Imgproc.blur ...
(more)