This project implements a producer-consumer model using C++ to process images in parallel. Producers read images from a directory, and consumers apply transformations using OpenCV, saving the processed images to another directory.
- Multithreaded producer-consumer model.
- Safe concurrent access to the buffer using mutex and condition variables.
- Image processing with OpenCV (e.g., bitwise NOT operation).
- Configurable number of producers, consumers, and delays.
- Execution time measurement for performance evaluation.
- C++17 compatible compiler.
- OpenCV library.
- CMake (minimum version 3.5).
-
Clone the repository:
git clone <repository_url> cd <repository_directory>
-
Create a build directory and navigate to it:
mkdir build && cd build
-
Run CMake to generate build files:
cmake ..
-
Build the project:
make
-
Run the executable:
./Buffer <Initial_Directory_Images_Path> <Result_Directory_Images_Path>
- main.cpp: Contains the main logic for setting up producers and consumers.
- Image.hpp / Image.cpp: Defines the
Imageclass for handling image-related operations. - Buffer.hpp: Template-based thread-safe buffer for producer-consumer operations.
- CMakeLists.txt: Configuration for building the project with CMake.
The following parameters can be adjusted in main.cpp:
- NUM_PRODUCERS: Number of producer threads (default: 5).
- NUM_CONSUMERS: Number of consumer threads (default: 5).
- PRODUCER_DELAY_TO_PRODUCE: Delay in nanoseconds for producers (default: 1).
- CONSUMER_DELAY_TO_CONSUME: Delay in nanoseconds for consumers (default: 3).
The program includes checks for:
- Command-line arguments: Ensures exactly two arguments are passed for input and output directories.
- Directory validation: Verifies the provided directories exist and contain valid images.
- Buffer capacity: Prevents overflows by limiting the buffer size to the predefined capacity.
./Buffer /path/to/input/images /path/to/output/images- If invalid paths are provided or directories are empty, the program exits with an appropriate error message.
- If no image files with supported extensions (
png,jpg) are found, the program notifies the user.
- Ensure the input directory contains images with valid extensions (
png,jpg). - The output directory must have write permissions.
- The OpenCV library must be properly installed and linked.
This project is licensed under the MIT License. See the LICENSE file for details.
- OpenCV library for image processing.
- C++ Standard Library for threading and synchronization tools.