private double ShortestDistance(MyConnectedComponentsAnalysisFast.MyBlob char_blob)
 {
     double min_distance = Double.MaxValue;
     Point a = char_blob.mass_center;
     for (int i = 0; i < _char_list.Count; i++)
     {
         Point b = _char_list[i].mass_center;
         double distance = Math.Sqrt((a.X - b.X) * (a.X - b.X) + (a.Y - b.Y) * (a.Y - b.Y));
         if (distance < min_distance)
             min_distance = distance;
     }
     return min_distance;
 }
        public void AddChar(MyConnectedComponentsAnalysisFast.MyBlob char_blob)
        {
            if (_char_list.Contains(char_blob)) return;
            for (int i = 0; i < _char_list.Count; i++)
                if (Distance(_char_list[i].mass_center, char_blob.mass_center) < 3)
                    return;
            _mean_height = (_mean_height * _char_list.Count + char_blob.bbx.Height);
            _mean_width = (_mean_width * _char_list.Count + char_blob.bbx.Width);
            _char_list.Add(char_blob);
            _mean_height /= (double)_char_list.Count;
            _mean_width /= (double)_char_list.Count;
            // Extend bbx
            if (_bbx.Width == 0)
                _bbx = char_blob.bbx;
            else
            {
                int x = _bbx.X, y = _bbx.Y, xx = _bbx.X + _bbx.Width - 1, yy = _bbx.Y + _bbx.Height - 1;
                int x1 = char_blob.bbx.X, y1 = char_blob.bbx.Y, xx1 = char_blob.bbx.X + char_blob.bbx.Width - 1, yy1 = char_blob.bbx.Y + char_blob.bbx.Height - 1;

                int x2, y2, xx2, yy2;

                if (x < x1) x2 = x;
                else x2 = x1;
                if (y < y1) y2 = y;
                else y2 = y1;

                if (xx < xx1) xx2 = xx1;
                else xx2 = xx;
                if (yy < yy1) yy2 = yy1;
                else yy2 = yy;

                _bbx.X = x2; _bbx.Y = y2;
                _bbx.Width = xx2 - x2 + 1;
                _bbx.Height = yy2 - y2 + 1;

            }
        }