Rect.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using Newtonsoft.Json;
  2. namespace DaJiaoYan.Models
  3. {
  4. public class Rect
  5. {
  6. private OpenCvSharp.Rect _rect;
  7. [JsonProperty(PropertyName = "x", NullValueHandling = NullValueHandling.Ignore)]
  8. public int X { get; set; }
  9. [JsonProperty(PropertyName = "y", NullValueHandling = NullValueHandling.Ignore)]
  10. public int Y { get; set; }
  11. [JsonProperty(PropertyName = "width", NullValueHandling = NullValueHandling.Ignore)]
  12. public int Width { get; set; }
  13. [JsonProperty(PropertyName = "height", NullValueHandling = NullValueHandling.Ignore)]
  14. public int Height { get; set; }
  15. /// <summary>
  16. /// ÇøÓòËùÔÚµÄÖ½ÕÅA/BÃæ
  17. /// </summary>
  18. [JsonProperty(PropertyName = "side", NullValueHandling = NullValueHandling.Ignore)]
  19. public string Side { get; set; }
  20. [JsonProperty(PropertyName = "uuid", NullValueHandling = NullValueHandling.Ignore)]
  21. public string UUID { get; set; }
  22. public Rect(int x, int y, int w, int h)
  23. {
  24. X = x; Y = y; Width = w; Height = h;
  25. }
  26. public OpenCvSharp.Rect CvRect
  27. {
  28. get
  29. {
  30. if (_rect == null || _rect.X != X || _rect.Y != Y || _rect.Width != Width || _rect.Height != Height)
  31. {
  32. _rect = new OpenCvSharp.Rect
  33. {
  34. X = X,
  35. Y = Y,
  36. Width = Width,
  37. Height = Height,
  38. };
  39. }
  40. return _rect;
  41. }
  42. }
  43. public bool Avaliable
  44. {
  45. get
  46. {
  47. return X >= 0 && Y >= 0 && Width > 0 && Height > 0;
  48. }
  49. }
  50. }
  51. }