Projects Inventory

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.
    • Advertisement
    • #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:

Compilation and Execution:

Compile with OpenCV:

Run the Program:

 

Exit mobile version