Vageesh1 commited on
Commit
4097868
·
1 Parent(s): 62b5e41

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -0
app.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import skimage.io as io
3
+ from PIL import Image
4
+ import numpy as np
5
+ import cv2
6
+
7
+ def ui():
8
+ st.markdown("# Items counter")
9
+ uploaded_file = st.file_uploader("Upload an Image", type=['png', 'jpeg', 'jpg'])
10
+
11
+ if uploaded_file is not None:
12
+ image = Image.open(uploaded_file)
13
+ img_array = np.array(image)
14
+ gray = cv2.cvtColor(img_array, cv2.COLOR_BGR2GRAY)
15
+ blur = cv2.GaussianBlur(gray, (11, 11), 0)
16
+ canny = cv2.Canny(blur, 30, 150, 3)
17
+ dilated = cv2.dilate(canny, (1, 1), iterations=0)
18
+ (cnt, hierarchy) = cv2.findContours(
19
+ dilated.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
20
+ rgb = cv2.cvtColor(img_array, cv2.COLOR_BGR2RGB)
21
+ cv2.drawContours(rgb, cnt, -1, (0, 255, 0), 2)
22
+
23
+ st.image(rgb, width = 500, channels = 'RGB')
24
+ st.markdown("Counted Items are : ", len(cnt))
25
+
26
+ if __name__ == '__main__':
27
+ ui()