private static void randomize_boxes(BoxLabel[] b, int n) { int i; for (i = 0; i < n; ++i) { BoxLabel swap = b[i]; int index = Utils.Rand.Next() % n; b[i] = b[index]; b[index] = swap; } }
public static BoxLabel[] read_boxes(string filename, ref int n) { if (!File.Exists(filename)) { Utils.file_error(filename); } float x, y, h, w; int id; int count = 0; var lines = File.ReadAllLines(filename); BoxLabel[] boxes = new BoxLabel[lines.Length]; for (var i = 0; i < lines.Length; ++i) { var numbers = lines[i].Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (numbers.Length != 5) { continue; } id = int.Parse(numbers[0]); x = float.Parse(numbers[1]); y = float.Parse(numbers[2]); w = float.Parse(numbers[3]); h = float.Parse(numbers[4]); boxes[i] = new BoxLabel(); boxes[i].Id = id; boxes[i].X = x; boxes[i].Y = y; boxes[i].H = h; boxes[i].W = w; boxes[i].Left = x - w / 2; boxes[i].Right = x + w / 2; boxes[i].Top = y - h / 2; boxes[i].Bottom = y + h / 2; ++count; } n = count; return(boxes); }