Q:

Return contours neatly - OpenCV/Java

I have this image below as a reference for studying a future project that I will create, using findContours(). I was successful in practically everything, but I had a problem and another question (which is not a problem, but can be improved). The problem is that the contours are not in the right order, as in the image, whose "H" should return first, "i" second, "n" third and so on. He returns to me, "niodHe". What am I missing from the code below? Or what should I add to fix this?

      Mat image = Imgcodecs.imread("C:\\Users\\deskadmin\\Desktop\\CONSTRUCAO\\1.png");
      Mat original = image.clone();
      Mat imageHSV = new Mat(image.size(), CvType.CV_8UC4);
      Mat imageBlurr = new Mat(image.size(), CvType.CV_8UC4);
      Mat imageA = new Mat(image.size(), CvType.CV_32F);
      Imgproc.cvtColor(image, imageHSV, Imgproc.COLOR_BGR2GRAY);
      Imgproc.GaussianBlur(imageHSV, imageBlurr, new Size(5,5), 0);
      Imgproc.adaptiveThreshold(imageBlurr, imageA, 255,Imgproc.ADAPTIVE_THRESH_MEAN_C, Imgproc.THRESH_BINARY,7, 5);

      List<MatOfPoint> contours = new ArrayList<MatOfPoint>();    
      Imgproc.findContours(imageA, contours, new Mat(), Imgproc.RETR_LIST,Imgproc.CHAIN_APPROX_SIMPLE);
      //Collections.sort(contours, Comparator.comparingDouble(Imgproc::contourArea));
      for(int i = 0, j = 2; i < (contours.size()-1); i++, j++){
         System.out.println("Imgproc.contourArea(contours.get(i)): "+Imgproc.contourArea(contours.get(i)));
       //if(Imgproc.contourArea(contours.get(i)) > 50 ){
        Rect rect = Imgproc.boundingRect(contours.get(i));
         //if(rect.height < 100 & rect.height > 11){
          Imgproc.rectangle(image, new Point(rect.x,rect.y), new Point(rect.x+rect.width,rect.y+rect.height),new Scalar(0,0,255));
          Mat roi = original.submat(rect);
          Imgcodecs.imwrite("C:\\Users\\deskadmin\\Desktop\\CONSTRUCAO\\"+j+".png",roi);
         //}else if (rect.height >= 100){
          //Mat roi = image.submat(rect);
          //Imgcodecs.imwrite("C:\\Users\\deskadmin\\Desktop\\CONSTRUCAO\\marcacao.png",roi);
          //}
       //}
      }

A:

findContours() processes the image from the bottom to the top AND right to the left, if I'm not mistaken. 
Simply create a bounding box around each contour and add them to a list. 
Later, sort them by using their x,y position and you'll have the letters in the order that you would like to read them.

