Photo Viewer Gaming Project in C++

Explanation:

  1. Include OpenCV and Standard Libraries:
    • #include <opencv2/opencv.hpp>: Includes the OpenCV core functionalities.
    • #include <iostream>: For input and output operations.
    • #include <vector>: For using the std::vector container.
    • #include <filesystem>: For directory and file handling in C++17.
  2. Show Image Function:
    • showImage(const cv::Mat& image, const std::string& windowName): Displays the image in a window named windowName. The cv::waitKey(0) function waits for a key press indefinitely.
  3. Load Image Paths Function:
    • loadImagePaths(const std::string& directory): Scans the specified directory for image files with extensions .jpg, .png, or .bmp. It returns a vector of file paths.
  4. Main Function:
    • Input Directory: Asks the user to input the path of the directory containing images.
    • Load Image Paths: Calls loadImagePaths to get all image file paths in the directory.
    • Image Viewing Loop: Displays images in a loop and allows navigation with key presses:
      • 'n': Next image.
      • 'p': Previous image.
      • 'q': Quit the viewer.
    • Key Handling: Uses cv::waitKey(0) to capture key presses and navigate through the images.
    • Window Cleanup: cv::destroyAllWindows(); closes all OpenCV windows when done.

Prerequisites:

  • OpenCV Library: Ensure OpenCV is installed and properly configured with your C++ project.
  • C++17 Support: The std::filesystem library requires C++17 or later.

Compilation and Execution:

Compile with OpenCV:

Run the Program:

 

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top