public int CompareTo(CoverSegmentCollection other) { var xMedianAvg = this.Average(a => a.Median); var yMedianAvg = other.Average(a => a.Median); int ret = xMedianAvg.CompareTo(yMedianAvg); if (ret != 0) { return(ret); } for (int i = 0; i < Count; ++i) { var xMedian = this[i].Median; var yMedian = other[i].Median; ret = xMedian.CompareTo(yMedian); if (ret != 0) { return(ret); } } return(0); }
internal static CoverSegmentCollection ComputeColorInfo(string filename, Color targetColor) { using (Mat mat = new Mat(filename, ImreadModes.Unchanged)) using (Mat normalized = new Mat()) { Cv2.Normalize(mat, normalized, 0, 255, NormTypes.MinMax); CoverSegmentCollection ret = new CoverSegmentCollection(); for (int y = 0; y < Specifications.VERTICAL_SEGMENT_COUNT; ++y) { for (int x = 0; x < Specifications.HORIZONTAL_SEGMENT_COUNT; ++x) { ret.Add(Median(normalized, x, y, Specifications.HORIZONTAL_SEGMENT_COUNT, Specifications.VERTICAL_SEGMENT_COUNT, (int)targetColor)); } } return(ret); } }
public static CoverSegmentCollection LoadColorMap(Guid bookID, Guid imageID, string path, CoverComparator.Color color) { var maps = ColorMapFacade.FindBy(bookID, imageID, (int)color); CoverSegmentCollection csc = new CoverSegmentCollection(); if (maps != null && maps.Count() == Specifications.VERTICAL_SEGMENT_COUNT * Specifications.HORIZONTAL_SEGMENT_COUNT) { csc.AddRange(maps.OrderBy(x => x.ValueOrder).Select(x => new CoverSegmentColorInfo(x.Value))); } else { var colorInfoList = ComputeColorInfo(path, color); Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, new Action(() => UpdateOrInsertColorMap(colorInfoList, bookID, imageID, color))); csc.AddRange(colorInfoList.Select(y => new CoverSegmentColorInfo(y.Median))); } return(csc); }