ImageTest.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #ifndef IMAGE_TEST_H
  2. #define IMAGE_TEST_H
  3. #include <opencv4/opencv2/opencv.hpp>
  4. #include <string>
  5. #include <sys/time.h>
  6. #include <chrono>
  7. namespace ImageTest
  8. {
  9. void saveImageFromData(unsigned char *data, int width, int height, const std::string &filename = "./output.png");
  10. class HighResolutionTimer
  11. {
  12. public:
  13. // 开始计时
  14. void start()
  15. {
  16. start_time = std::chrono::high_resolution_clock::now();
  17. }
  18. // 停止计时
  19. void stop()
  20. {
  21. end_time = std::chrono::high_resolution_clock::now();
  22. }
  23. // 获取经过的时间(以秒为单位)
  24. double elapsed() const
  25. {
  26. return std::chrono::duration<double>(end_time - start_time).count();
  27. }
  28. // 获取经过的时间(以毫秒为单位)
  29. double elapsed_milliseconds() const
  30. {
  31. return std::chrono::duration<double, std::milli>(end_time - start_time).count();
  32. }
  33. // 获取经过的时间(以微秒为单位)
  34. double elapsed_microseconds() const
  35. {
  36. return std::chrono::duration<double, std::micro>(end_time - start_time).count();
  37. }
  38. private:
  39. std::chrono::high_resolution_clock::time_point start_time;
  40. std::chrono::high_resolution_clock::time_point end_time;
  41. };
  42. }
  43. #endif // IMAGE_TEST_H