Item_Counter / app.py
Vageesh1's picture
Update app.py
1cca976
import streamlit as st
import skimage.io as io
from PIL import Image
import numpy as np
import cv2
def ui():
st.markdown("# Items counter")
uploaded_file = st.file_uploader("Upload an Image", type=['png', 'jpeg', 'jpg'])
if uploaded_file is not None:
image = Image.open(uploaded_file)
img_array = np.array(image)
gray = cv2.cvtColor(img_array, cv2.COLOR_BGR2GRAY)
blur = cv2.GaussianBlur(gray, (11, 11), 0)
canny = cv2.Canny(blur, 30, 150, 3)
dilated = cv2.dilate(canny, (1, 1), iterations=0)
(cnt, hierarchy) = cv2.findContours(
dilated.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
rgb = cv2.cvtColor(img_array, cv2.COLOR_BGR2RGB)
cv2.drawContours(rgb, cnt, -1, (0, 255, 0), 2)
st.image(rgb, width = 500, channels = 'RGB')
st.markdown(f"Counted Items are:{len(cnt)}")
if __name__ == '__main__':
ui()