Update app.py
Browse files
    	
        app.py
    CHANGED
    
    | 
         @@ -5,8 +5,6 @@ import cv2 
     | 
|
| 5 | 
         
             
            import numpy as np
         
     | 
| 6 | 
         
             
            from PIL import Image
         
     | 
| 7 | 
         
             
            from tensorflow.keras.models import load_model
         
     | 
| 8 | 
         
            -
            import tempfile
         
     | 
| 9 | 
         
            -
            import os
         
     | 
| 10 | 
         | 
| 11 | 
         
             
            # Title for the Streamlit App
         
     | 
| 12 | 
         
             
            st.title("Nepal Vehicle License Plate and Character Recognition")
         
     | 
| 
         @@ -95,32 +93,31 @@ if uploaded_file is not None: 
     | 
|
| 95 | 
         
             
                # Load image
         
     | 
| 96 | 
         
             
                image = Image.open(uploaded_file)
         
     | 
| 97 | 
         | 
| 98 | 
         
            -
                # Detect license plates 
     | 
| 99 | 
         
             
                with st.spinner("Processing image..."):
         
     | 
| 100 | 
         
             
                    cropped_plates, detected_image = detect_and_crop_license_plate(image)
         
     | 
| 101 | 
         | 
| 102 | 
         
            -
                    # Show the image with detected license plates
         
     | 
| 103 | 
         
            -
                    st.image(cv2.cvtColor(detected_image, cv2.COLOR_BGR2RGB), caption="Detected License Plates", use_container_width=True)
         
     | 
| 104 | 
         
            -
             
     | 
| 105 | 
         
             
                    if cropped_plates:
         
     | 
| 
         | 
|
| 106 | 
         
             
                        st.write(f"Detected {len(cropped_plates)} license plate(s).")
         
     | 
| 107 | 
         
            -
                        for idx, cropped_image in enumerate(cropped_plates, 1):
         
     | 
| 108 | 
         
            -
                            st.write(f"Processing License Plate {idx}:")
         
     | 
| 109 | 
         | 
| 110 | 
         
            -
             
     | 
| 111 | 
         
            -
                             
     | 
| 
         | 
|
| 112 | 
         | 
| 113 | 
         
             
                            if character_crops:
         
     | 
| 114 | 
         
            -
                                # Recognize characters
         
     | 
| 115 | 
         
             
                                recognized_characters = recognize_characters(character_crops)
         
     | 
| 116 | 
         
            -
             
     | 
| 117 | 
         
            -
                                # Show each cropped character and prediction
         
     | 
| 118 | 
         
            -
                                for i, char_crop in enumerate(character_crops):
         
     | 
| 119 | 
         
            -
                                    st.image(cv2.cvtColor(char_crop, cv2.COLOR_BGR2RGB), caption=f"Character {i+1}")
         
     | 
| 120 | 
         
            -
                                    st.write(f"Predicted Character: {recognized_characters[i]}")
         
     | 
| 121 | 
         
             
                            else:
         
     | 
| 122 | 
         
             
                                st.write("No characters detected in this license plate.")
         
     | 
| 123 | 
         
             
                    else:
         
     | 
| 124 | 
         
            -
                        st.write("No license plates detected.")
         
     | 
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 125 | 
         | 
| 126 | 
         
             
                st.success("Processing complete!")
         
     | 
| 
         | 
|
| 5 | 
         
             
            import numpy as np
         
     | 
| 6 | 
         
             
            from PIL import Image
         
     | 
| 7 | 
         
             
            from tensorflow.keras.models import load_model
         
     | 
| 
         | 
|
| 
         | 
|
| 8 | 
         | 
| 9 | 
         
             
            # Title for the Streamlit App
         
     | 
| 10 | 
         
             
            st.title("Nepal Vehicle License Plate and Character Recognition")
         
     | 
| 
         | 
|
| 93 | 
         
             
                # Load image
         
     | 
| 94 | 
         
             
                image = Image.open(uploaded_file)
         
     | 
| 95 | 
         | 
| 96 | 
         
            +
                # Detect license plates
         
     | 
| 97 | 
         
             
                with st.spinner("Processing image..."):
         
     | 
| 98 | 
         
             
                    cropped_plates, detected_image = detect_and_crop_license_plate(image)
         
     | 
| 99 | 
         | 
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 100 | 
         
             
                    if cropped_plates:
         
     | 
| 101 | 
         
            +
                        st.image(cv2.cvtColor(detected_image, cv2.COLOR_BGR2RGB), caption="Detected License Plates", use_container_width=True)
         
     | 
| 102 | 
         
             
                        st.write(f"Detected {len(cropped_plates)} license plate(s).")
         
     | 
| 
         | 
|
| 
         | 
|
| 103 | 
         | 
| 104 | 
         
            +
                        for idx, cropped_plate in enumerate(cropped_plates, 1):
         
     | 
| 105 | 
         
            +
                            st.write(f"Processing License Plate {idx}:")
         
     | 
| 106 | 
         
            +
                            character_crops = detect_and_crop_characters(cropped_plate)
         
     | 
| 107 | 
         | 
| 108 | 
         
             
                            if character_crops:
         
     | 
| 
         | 
|
| 109 | 
         
             
                                recognized_characters = recognize_characters(character_crops)
         
     | 
| 110 | 
         
            +
                                st.write("Recognized Characters:", "".join(recognized_characters))
         
     | 
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 111 | 
         
             
                            else:
         
     | 
| 112 | 
         
             
                                st.write("No characters detected in this license plate.")
         
     | 
| 113 | 
         
             
                    else:
         
     | 
| 114 | 
         
            +
                        st.write("No license plates detected. Running character detection on the full image.")
         
     | 
| 115 | 
         
            +
                        character_crops = detect_and_crop_characters(cv2.cvtColor(np.array(image), cv2.COLOR_RGB2BGR))
         
     | 
| 116 | 
         
            +
             
     | 
| 117 | 
         
            +
                        if character_crops:
         
     | 
| 118 | 
         
            +
                            recognized_characters = recognize_characters(character_crops)
         
     | 
| 119 | 
         
            +
                            st.write("Recognized Characters:", "".join(recognized_characters))
         
     | 
| 120 | 
         
            +
                        else:
         
     | 
| 121 | 
         
            +
                            st.write("No characters detected in the full image.")
         
     | 
| 122 | 
         | 
| 123 | 
         
             
                st.success("Processing complete!")
         
     |