- Introduction
- Features
- Prerequisites
- Installation
- Usage
- Script Explanation
- Output
- Example
- License
- Acknowledgements
This project focuses on detecting and prioritizing red and blue houses in aerial images, distinguishing between those that are on fire (brown areas) and those that are safe on grass (green areas). Using OpenCV and Python, the program processes images to highlight areas of interest, classify the houses, and assign rescue priorities based on their color and condition. Blue houses have a higher priority than red ones, with an added emphasis on those that are on fire.
- Color Change: Converts brown areas to yellow and green areas to blue in the provided images for better visualization.
- House Detection and Classification: Detects houses and classifies them based on color (red or blue) and state (on fire or on grass).
- Priority Calculation: Assigns rescue priorities based on the number and condition of the houses.
- Sorting: Sorts the images based on the calculated rescue priority for efficient response planning.
- Python 3.x
- OpenCV
- NumPy
-
Clone the repository:
git clone https://github.com/Mugta1/UAS-1.git cd UAS-1
-
Install the required libraries:
pip install numpy opencv-python
- Place your images in the
photos
directory. - Run the script:
python final.py
- Purpose: Modifies the colors in the image to enhance visualization by converting brown areas to yellow and green areas to blue.
- Parameters:
i
: Path to the input image.
- Process:
- Reads the image and converts it from BGR to HSV color space.
- Creates masks to detect brown and green areas using predefined HSV color ranges.
- Changes the color of detected brown areas to yellow and green areas to blue.
- Converts the modified HSV image back to BGR color space.
- Displays the edited image using OpenCV's
imshow
function.
- Purpose: Detects houses, determines if they are on fire or not, and calculates various metrics related to house priority for rescue.
- Parameters:
i
: Path to the input image.
- Process:
- Reads the image and applies a bilateral filter for noise reduction.
- Splits the image into its BGR components and applies binary thresholding.
- Creates a mask to detect green areas, representing unburnt regions.
- Performs morphological transformations on the green mask and inverts it to identify non-green areas.
- Uses the Canny edge detector to find edges in the green mask and thresholded images.
- Identifies contours in the edge-detected images to count the number of red and blue houses.
- Calculates the number of red and blue houses on fire and on grass.
- Computes total houses on fire, total houses on grass, and assigns rescue priorities.
- Appends the calculated values to respective lists and dictionaries for further use.
- Purpose: Combines the
colorchange
andvalues
functions to fully process each image. - Parameters:
i
: Path to the input image.
- Process:
- Calls the
colorchange
function to modify the colors in the image. - Calls the
values
function to detect houses and calculate metrics. - Closes all OpenCV windows after processing.
- Calls the
- Code:
def final(i): colorchange(i) values(i) cv.destroyAllWindows()
- Process:
- Defines a list of image paths to be processed.
- Iterates over each image path, calling the
final
function to process each image. - Sorts the images based on the priority ratios calculated in the
values
function. - Prints the results for total houses on fire and on grass, priority values, priority ratios, and the sorted list of image paths.
- Code:
imglist = ['photos/1.png', 'photos/2.png', 'photos/3.png', 'photos/4.png', 'photos/5.png', 'photos/6.png', 'photos/7.png', 'photos/8.png', 'photos/10.png', 'photos/11.png'] for i in imglist: final(i) sortedkeys = sorted(dictxyz, key=dictxyz.get, reverse=True) print('2.', second) print('3.', third) print('4.', fourth) print('5.', sortedkeys)
- Second Output: List of total houses on fire and on grass for each image.
- Third Output: List of priority values for houses on fire and on grass for each image.
- Fourth Output: List of priority ratios for each image.
- Fifth Output: Sorted list of image paths based on the priority ratios.
# Output Example
2. [[1, 2], [2, 3], ...]
3. [[1, 4], [3,
5], ...]
4. [0.5, 0.6, ...]
5. ['photos/2.png', 'photos/5.png', ...]
Feel free to contribute to this project by forking the repository and submitting pull requests!
This project is licensed under the MIT License. See the LICENSE file for details.
- OpenCV: For providing extensive documentation and tutorials which were instrumental in developing the image processing components of this project.
- NumPy: For its powerful array manipulation capabilities which facilitated the handling of image data.
- Python: For being the versatile programming language that made this project possible.