├── 1.png ├── 2.png ├── 3.png ├── 4.png ├── 5.png ├── 6.png ├── 7.png ├── 8.png ├── arrow.png ├── background.png ├── keras_model.h5 ├── labels.txt ├── app.py └── Readme.md /1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhineshkumarai2213/Design-project-01/HEAD/1.png -------------------------------------------------------------------------------- /2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhineshkumarai2213/Design-project-01/HEAD/2.png -------------------------------------------------------------------------------- /3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhineshkumarai2213/Design-project-01/HEAD/3.png -------------------------------------------------------------------------------- /4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhineshkumarai2213/Design-project-01/HEAD/4.png -------------------------------------------------------------------------------- /5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhineshkumarai2213/Design-project-01/HEAD/5.png -------------------------------------------------------------------------------- /6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhineshkumarai2213/Design-project-01/HEAD/6.png -------------------------------------------------------------------------------- /7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhineshkumarai2213/Design-project-01/HEAD/7.png -------------------------------------------------------------------------------- /8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhineshkumarai2213/Design-project-01/HEAD/8.png -------------------------------------------------------------------------------- /arrow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhineshkumarai2213/Design-project-01/HEAD/arrow.png -------------------------------------------------------------------------------- /background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhineshkumarai2213/Design-project-01/HEAD/background.png -------------------------------------------------------------------------------- /keras_model.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhineshkumarai2213/Design-project-01/HEAD/keras_model.h5 -------------------------------------------------------------------------------- /labels.txt: -------------------------------------------------------------------------------- 1 | 0 Nothing 2 | 1 Zip-top cans 3 | 2 Newspaper 4 | 3 Old shoes 5 | 4 Watercolor pen 6 | 5 Disinfectant 7 | 6 Battery 8 | 7 Vegetable leaf 9 | 8 Apple 10 | -------------------------------------------------------------------------------- /app.py: -------------------------------------------------------------------------------- 1 | import os 2 | import cvzone 3 | from cvzone.ClassificationModule import Classifier 4 | import cv2 5 | 6 | # Try accessing the camera 7 | cap = cv2.VideoCapture(0) # Changed to 0 for default camera 8 | 9 | if not cap.isOpened(): 10 | raise RuntimeError("Error: Cannot access the camera. Check if the camera is connected and working.") 11 | 12 | # Load model and labels 13 | classifier = Classifier('Resources/Model/keras_model.h5', 'Resources/Model/labels.txt') 14 | imgArrow = cv2.imread('Resources/arrow.png', cv2.IMREAD_UNCHANGED) 15 | classIDBin = 0 16 | 17 | # Import all the waste images 18 | imgWasteList = [] 19 | pathFolderWaste = "Resources/Waste" 20 | pathList = os.listdir(pathFolderWaste) 21 | for path in pathList: 22 | imgWasteList.append(cv2.imread(os.path.join(pathFolderWaste, path), cv2.IMREAD_UNCHANGED)) 23 | 24 | # Import all the bin images 25 | imgBinsList = [] 26 | pathFolderBins = "Resources/Bins" 27 | pathList = os.listdir(pathFolderBins) 28 | for path in pathList: 29 | imgBinsList.append(cv2.imread(os.path.join(pathFolderBins, path), cv2.IMREAD_UNCHANGED)) 30 | 31 | # Class to bin mapping 32 | classDic = {0: None, 33 | 1: 0, 34 | 2: 0, 35 | 3: 3, 36 | 4: 3, 37 | 5: 1, 38 | 6: 1, 39 | 7: 2, 40 | 8: 2} 41 | 42 | while True: 43 | # Read frame from the camera 44 | ret, img = cap.read() 45 | 46 | if not ret: 47 | print("Error: Failed to capture image.") 48 | break 49 | 50 | imgResize = cv2.resize(img, (454, 340)) # Resize for display 51 | 52 | # Background image for displaying the results 53 | imgBackground = cv2.imread('Resources/background.png') 54 | 55 | # Get prediction from the classifier 56 | prediction = classifier.getPrediction(img) 57 | classID = prediction[1] 58 | 59 | print(f"Predicted class ID: {classID}") 60 | 61 | # If we have a valid class prediction (not 'None') 62 | if classID != 0: 63 | # Overlay the appropriate waste image and arrow on the background 64 | imgBackground = cvzone.overlayPNG(imgBackground, imgWasteList[classID - 1], (909, 127)) 65 | imgBackground = cvzone.overlayPNG(imgBackground, imgArrow, (978, 320)) 66 | 67 | # Get corresponding bin based on the class ID 68 | classIDBin = classDic.get(classID, 0) 69 | 70 | # Overlay the bin image on the background 71 | imgBackground = cvzone.overlayPNG(imgBackground, imgBinsList[classIDBin], (895, 374)) 72 | 73 | # Overlay the resized camera image 74 | imgBackground[148:148 + 340, 159:159 + 454] = imgResize 75 | 76 | # Display the resulting frame 77 | cv2.imshow("Output", imgBackground) 78 | 79 | # Break the loop on pressing 'q' 80 | if cv2.waitKey(1) & 0xFF == ord('q'): 81 | break 82 | 83 | # Release the camera and close any open windows 84 | cap.release() 85 | cv2.destroyAllWindows() 86 | -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Garbage Classifier for Waste Management 4 | 5 | This project is an image classification system that classifies garbage into specific categories (e.g., recyclable, hazardous, food, or residual waste) and suggests the appropriate bin for disposal. The system uses a webcam to capture images, a pre-trained TensorFlow model for classification, and OpenCV for visualization. 6 | 7 | --- 8 | 9 | ## Features 10 | - **Real-Time Classification**: Uses a webcam to capture real-time video frames. 11 | - **Waste Categories**: Identifies the type of waste and assigns it to a specific category. 12 | - **Categories**: Recyclable, Hazardous, Food, Residual. 13 | - **Bin Suggestions**: Displays the appropriate bin for each waste category. 14 | - **User-Friendly Interface**: Overlays classification results and visuals on a custom background image. 15 | 16 | --- 17 | 18 | ## Requirements 19 | 20 | Ensure you have the following installed before running the project: 21 | 22 | ### Software and Libraries: 23 | 1. **Python**: Version 3.10 or higher. 24 | 2. **TensorFlow**: Version 2.18.0. 25 | 3. **OpenCV**: Version 4.10.0. 26 | 4. **cvzone**: A utility for computer vision tasks. 27 | 28 | ### Hardware: 29 | 1. A webcam (internal or external). 30 | 2. A computer capable of running Python and TensorFlow. 31 | 32 | ### Additional Files: 33 | 1. **Pre-trained TensorFlow Model**: 34 | - `keras_model.h5`: The trained model for waste classification. 35 | - `labels.txt`: A text file containing class labels for the model. 36 | 2. **Resources Folder**: 37 | - `Waste/`: Contains images of different types of waste. 38 | - `Bins/`: Contains images of different bins. 39 | - `arrow.png`: Visual cue for bin suggestions. 40 | - `background.png`: Custom background for the interface. 41 | 42 | --- 43 | 44 | ## Folder Structure 45 | 46 | ```plaintext 47 | Resources/ 48 | │ 49 | ├── Model/ 50 | │ ├── keras_model.h5 # Pre-trained classification model. 51 | │ └── labels.txt # Class labels for the model. 52 | │ 53 | ├── Waste/ 54 | │ └── [Waste images...] # PNG images representing various waste items. 55 | │ 56 | ├── Bins/ 57 | │ └── [Bin images...] # PNG images of corresponding bins. 58 | │ 59 | ├── arrow.png # Arrow image for bin indication. 60 | └── background.png # Background image for the display interface. 61 | ``` 62 | 63 | --- 64 | 65 | ## Installation 66 | 67 | Follow these steps to set up the project on your local system: 68 | 69 | 1. Clone the repository or download the project folder: 70 | ```bash 71 | git clone 72 | cd 73 | ``` 74 | 2. Install the required libraries: 75 | ```bash 76 | pip install tensorflow==2.18.0 opencv-python==4.10.0 cvzone 77 | ``` 78 | 3. Ensure the **Resources** folder is in the same directory as your Python script. 79 | 80 | --- 81 | 82 | ## How to Run 83 | 84 | 1. Connect your webcam to the computer. 85 | 2. Open the terminal in the project directory. 86 | 3. Run the Python script: 87 | ```bash 88 | python app.py 89 | ``` 90 | 4. The program will start capturing real-time video from the webcam. 91 | 5. Place an object in front of the camera to classify it. The system will: 92 | - Display the waste item on the screen. 93 | - Show the suggested bin for disposal. 94 | 95 | --- 96 | 97 | ## Troubleshooting 98 | 99 | ### **Camera Issues**: 100 | - If you see `Camera index out of range` or similar errors: 101 | 1. Ensure your webcam is connected and not in use by another application. 102 | 2. Try changing the camera index in the code: 103 | ```python 104 | cap = cv2.VideoCapture(0) # Change 0 to 1 or 2 if necessary. 105 | ``` 106 | 107 | ### **Model Issues**: 108 | - If the model does not classify the object: 109 | 1. Ensure `keras_model.h5` and `labels.txt` are present in the `Resources/Model` folder. 110 | 2. Verify that the model and label files match the categories in `classDic`. 111 | 112 | ### **Library Errors**: 113 | - If you encounter errors related to TensorFlow or OpenCV: 114 | - Reinstall the libraries: 115 | ```bash 116 | pip install tensorflow==2.18.0 opencv-python==4.10.0 117 | ``` 118 | 119 | --- 120 | 121 | ## Future Enhancements 122 | 123 | - Improve classification accuracy by retraining the model with more data. 124 | - Add a GUI to make the system more user-friendly. 125 | - Extend the waste categories for broader use cases. 126 | - Enable voice feedback for bin suggestions. 127 | 128 | --- 129 | 130 | ## Credits 131 | 132 | - **Libraries Used**: TensorFlow, OpenCV, cvzone. 133 | - **Model Training**: Pre-trained MobileNetV2 model used for waste classification. 134 | 135 | --- 136 | 137 | ## License 138 | 139 | This project is licensed under the [MIT License](LICENSE). 140 | 141 | --- 142 | --------------------------------------------------------------------------------