123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- #ifndef DATA_PACKAGE_H
- #define DATA_PACKAGE_H
- #include <iostream>
- #include <string>
- #include <stdexcept>
- #include "../AIManager/inferResult.h"
- #define RESIZE_WIDTH 640
- #define RESIZE_HEIGHT 640
- typedef struct DataPackage
- {
- int nDeviceID = 0;
- char *pJpegData{nullptr};
- int nJpegSize = 0;
- void *pRGBData{nullptr};
- int nWidth = 0;
- int nHeight = 0;
- void *pResizeData{nullptr};
- int nResizeWidth = RESIZE_WIDTH;
- int nResizeHeight = RESIZE_HEIGHT;
- int nResizeType = 0;
- // other infomation
- long nTimeStamp = 0.0;
- double dDegree = 0.0;
- // camera id
- int nCameraID = 0;
- // result
- int id = 0;
- int count = 0;
- object_detect_result_list Result;
- DataPackage(int width, int height)
- {
- if (allocResource(width, height))
- {
- nWidth = width;
- nHeight = height;
- }
- else
- {
- std::cerr << "allocResource failed" << std::endl;
- }
- }
- bool allocResource(int width, int height)
- {
- if (pJpegData == nullptr)
- {
- pJpegData = new char[width * height * 3];
- }
- // if (pRGBData == nullptr)
- // {
- // pRGBData = new unsigned char[width * height * 3];
- // if (pRGBData == nullptr)
- // {
- // return false;
- // }
- // }
- if (pResizeData == nullptr)
- {
- pResizeData = new unsigned char[nResizeWidth * nResizeHeight * 3];
- if (pResizeData == nullptr)
- {
- return false;
- }
- }
- return true;
- }
- void freeResource()
- {
- if (pJpegData != nullptr)
- {
- delete[] pJpegData;
- }
- if (pRGBData != nullptr)
- {
- delete[] (unsigned char *)pRGBData;
- pRGBData = nullptr;
- }
- if (pResizeData != nullptr)
- {
- delete[] (unsigned char *)pResizeData;
- pResizeData = nullptr;
- }
- }
- ~DataPackage()
- {
- freeResource();
- }
- } DATA_PACKAGE, *PDATA_PACKAGE;
- typedef DataPackage *DataPackagePtr;
- #endif // DATA_PACKAGE_H
|