DataPackage.h 2.1 KB

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