super_res.cpp 601 B

1234567891011121314151617181920212223242526272829303132
  1. #include <string>
  2. #include <opencv2/opencv.hpp>
  3. #include <opencv2/dnn_superres.hpp>
  4. int main(){
  5. // Read image
  6. cv::Mat img = cv::imread("image.png");
  7. // Make DNN Super resolution instance
  8. cv::dnn_superres::DnnSuperResImpl sr;
  9. // Read the model
  10. std::string model_path = "ESPCN_x4.pb";
  11. sr.readModel(model_path);
  12. // Set the model by passing the value and the upsampling ratio
  13. sr.setModel("espcn", 4);
  14. // Creating a blank Mat for result
  15. cv::Mat result;
  16. // Upscale the input image
  17. sr.upsample(img, result);
  18. // Write the final image
  19. cv::imwrite("output.png",result);
  20. return 0;
  21. }