Advertisement
jack06215

[OpenCV] read image

Jul 8th, 2020
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. cv::Mat imread_limitedWidth(cv::String filename, int length_limit, int imread_flag)
  2. {
  3.     // Load an image
  4.     cv::Mat image = imread(filename, imread_flag);
  5.  
  6.     if (image.empty())
  7.     {
  8.         std::cerr << "Cannot open image" << std::endl;
  9.         return image;
  10.     }
  11.  
  12.     // Resize if image length is bigger than 10000 px
  13.     if (image.rows > 1000 | image.cols > 1000)
  14.     {
  15.         std::cout << "imread_resize:: Limit the image size to 1000 px in length" << std::endl;
  16.         double fx = length_limit / static_cast<double>(image.cols);
  17.         double newHeight = static_cast<double>(image.rows) * fx;
  18.         double fy = newHeight / image.rows;
  19.         cv::resize(image, image, cv::Size(0, 0), fx, fy);
  20.     }
  21.  
  22.     return image;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement