Ask Your Question

ChukkapalliSukhesh's profile - activity

2019-12-15 12:15:54 -0600 received badge  Famous Question (source)
2018-06-28 09:12:33 -0600 received badge  Notable Question (source)
2017-08-02 13:00:04 -0600 received badge  Popular Question (source)
2016-05-31 22:32:31 -0600 commented answer How to find borders and crop the image

Thank you very much

2016-05-31 22:32:12 -0600 received badge  Scholar (source)
2016-05-31 04:26:29 -0600 received badge  Supporter (source)
2016-05-29 23:30:24 -0600 received badge  Editor (source)
2016-05-29 23:03:10 -0600 asked a question How to find borders and crop the image

In my project, I am try to detect a handwritten character. How to find borders of image based on pixel colour and crop image. I wrote some code but it perfectly crops only at top left side written character. It cannot work proper for all images. My code is

    for (int x = 0; x < bt.getWidth(); x++) {
                    for (int y = 0; y < bt.getHeight(); y++) {




                        if (bt.getPixel(x, y) == Color.BLACK) {
                            if (xmin == 0 && xmax==0)
                                xmin = x;
                            if (ymin == 0 && ymax==0)
                                ymin = y;
                            if (x > xmax && x>xmin) {
                                xmax = x;
                            }
                            if (x < xmin && x < xmax) {
                                xmin = x;
                            }
                            if (y > ymax && y>ymin) {
                                ymax = y;
                            }
                            if (y < ymin && y < ymax) {
                                ymin = y;
                            }
                           // Log.i("pix bef","" + xmin + " " + ymin + " " + xmax + " " + ymax);
                            if((xmin+xmax)>bt.getWidth()){
                                xmax=bt.getWidth()-xmin;
                            }
                            if((ymin+ymax)>bt.getHeight()){
                                ymax=bt.getHeight()-ymin;
                            }
                        }

                    }
                }
                 Rect roi = new Rect(xmin, ymin, xmax, ymax);
                Mat cr = new Mat(mm, roi);

image description image description

The output is accurate at top left only. Getting much weight space at top right. Please solve how to eliminate extra weight space. Thank you.