histogram.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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 <opencv2/imgproc.hpp>
  5. #include <opencv2/imgcodecs.hpp>
  6. #include <cstdint>
  7. #include <array>
  8. #include <iostream>
  9. #include "raw_pixels.hpp"
  10. #define IMG_ROWS 100
  11. #define IMG_COLS 100
  12. static_assert(IMG_ROWS * IMG_COLS <= RAW_PIXELS_SIZE, "Incompatible size");
  13. int main(void)
  14. {
  15. // Number of experiment runs
  16. int no_runs = 2;
  17. // https://docs.opencv.org/4.x/d3/d63/classcv_1_1Mat.html
  18. cv::Mat src_new(IMG_ROWS, IMG_COLS, CV_8UC1, (void *)raw_pixels);
  19. // Set parameters
  20. int imgCount = 1;
  21. const int channels[] = {0};
  22. cv::Mat mask = cv::Mat();
  23. cv::Mat hist;
  24. int dims = 1;
  25. const int hist_sizes[] = {256};
  26. float Range[] = {0,256};
  27. const float *ranges[] = {Range};
  28. // Run calc Hist
  29. for(int i=0; i < no_runs; i++){
  30. std::cout << "Running iteration # "<< i << std::endl;
  31. cv::calcHist(&src_new, imgCount, channels, mask, hist, dims, hist_sizes, ranges);
  32. }
  33. return 0;
  34. }