DataPackage.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #ifndef DATA_PACKAGE_H
  2. #define DATA_PACKAGE_H
  3. #include <iostream>
  4. #include <stdexcept>
  5. #include "../AIManager/inferResult.h"
  6. #define RESIZE_WIDTH 640
  7. #define RESIZE_HEIGHT 640
  8. typedef struct DataPackage
  9. {
  10. int nDeviceID = 0;
  11. void *pJpegData{nullptr};
  12. int nJpegSize = 0;
  13. void *pRGBData{nullptr};
  14. int nWidth = 0;
  15. int nHeight = 0;
  16. void *pResizeData{nullptr};
  17. int nResizeWidth = RESIZE_WIDTH;
  18. int nResizeHeight = RESIZE_HEIGHT;
  19. int nResizeType = 0;
  20. // other infomation
  21. long nTimeStamp = 0.0;
  22. double dDegree = 0.0;
  23. // result
  24. int id = 0;
  25. int count = 0;
  26. object_detect_result_list Result;
  27. DataPackage(int width, int height)
  28. {
  29. if (allocResource(width, height))
  30. {
  31. nWidth = width;
  32. nHeight = height;
  33. }
  34. else
  35. {
  36. std::cerr << "allocResource failed" << std::endl;
  37. }
  38. }
  39. bool allocResource(int width, int height)
  40. {
  41. if (pJpegData == nullptr)
  42. {
  43. pJpegData = new unsigned char[width * height * 3];
  44. if (pJpegData == nullptr)
  45. {
  46. return false;
  47. }
  48. }
  49. // if (pRGBData == nullptr)
  50. // {
  51. // pRGBData = new unsigned char[width * height * 3];
  52. // if (pRGBData == nullptr)
  53. // {
  54. // return false;
  55. // }
  56. // }
  57. if (pResizeData == nullptr)
  58. {
  59. pResizeData = new unsigned char[nResizeWidth * nResizeHeight * 3];
  60. if (pResizeData == nullptr)
  61. {
  62. return false;
  63. }
  64. }
  65. return true;
  66. }
  67. void freeResource()
  68. {
  69. if (pJpegData != nullptr)
  70. {
  71. delete[] (unsigned char *)pJpegData;
  72. pJpegData = nullptr;
  73. }
  74. if (pRGBData != nullptr)
  75. {
  76. delete[] (unsigned char *)pRGBData;
  77. pRGBData = nullptr;
  78. }
  79. if (pResizeData != nullptr)
  80. {
  81. delete[] (unsigned char *)pResizeData;
  82. pResizeData = nullptr;
  83. }
  84. }
  85. ~DataPackage()
  86. {
  87. freeResource();
  88. }
  89. } DATA_PACKAGE, *PDATA_PACKAGE;
  90. typedef DataPackage *DataPackagePtr;
  91. #endif // DATA_PACKAGE_H