perf_jpeg.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // This file is part of OpenCV project.
  2. // It is subject to the license terms in the LICENSE file found in the top-level directory
  3. // of this distribution and at http://opencv.org/license.html
  4. #include "perf_precomp.hpp"
  5. namespace opencv_test
  6. {
  7. #ifdef HAVE_JPEG
  8. using namespace perf;
  9. PERF_TEST(JPEG, Decode)
  10. {
  11. String filename = getDataPath("stitching/boat1.jpg");
  12. FILE *f = fopen(filename.c_str(), "rb");
  13. fseek(f, 0, SEEK_END);
  14. long len = ftell(f);
  15. fseek(f, 0, SEEK_SET);
  16. vector<uchar> file_buf((size_t)len);
  17. EXPECT_EQ(len, (long)fread(&file_buf[0], 1, (size_t)len, f));
  18. fclose(f); f = NULL;
  19. TEST_CYCLE() imdecode(file_buf, IMREAD_UNCHANGED);
  20. SANITY_CHECK_NOTHING();
  21. }
  22. PERF_TEST(JPEG, Decode_rgb)
  23. {
  24. String filename = getDataPath("stitching/boat1.jpg");
  25. FILE *f = fopen(filename.c_str(), "rb");
  26. fseek(f, 0, SEEK_END);
  27. long len = ftell(f);
  28. fseek(f, 0, SEEK_SET);
  29. vector<uchar> file_buf((size_t)len);
  30. EXPECT_EQ(len, (long)fread(&file_buf[0], 1, (size_t)len, f));
  31. fclose(f); f = NULL;
  32. TEST_CYCLE() imdecode(file_buf, IMREAD_COLOR_RGB);
  33. SANITY_CHECK_NOTHING();
  34. }
  35. PERF_TEST(JPEG, Encode)
  36. {
  37. String filename = getDataPath("stitching/boat1.jpg");
  38. cv::Mat src = imread(filename);
  39. vector<uchar> buf;
  40. TEST_CYCLE() imencode(".jpg", src, buf);
  41. SANITY_CHECK_NOTHING();
  42. }
  43. #endif // HAVE_JPEG
  44. } // namespace