Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from PIL import Image
|
| 3 |
+
import numpy as np
|
| 4 |
+
from tensorflow.keras.applications.vgg19 import VGG19
|
| 5 |
+
from tensorflow.keras.preprocessing import image
|
| 6 |
+
from tensorflow.keras.applications.vgg19 import preprocess_input, decode_predictions
|
| 7 |
+
import numpy as np
|
| 8 |
+
import cv2
|
| 9 |
+
import os
|
| 10 |
+
|
| 11 |
+
def load_image(img_path):
|
| 12 |
+
img = cv2.imread(img_path)
|
| 13 |
+
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
|
| 14 |
+
return img
|
| 15 |
+
|
| 16 |
+
def preprocess(img):
|
| 17 |
+
img = cv2.resize(img, (224, 224))
|
| 18 |
+
img = img.astype('float32')
|
| 19 |
+
img = preprocess_input(img)
|
| 20 |
+
return img
|
| 21 |
+
|
| 22 |
+
def predict(img_path):
|
| 23 |
+
img = load_image(img_path)
|
| 24 |
+
img = preprocess(img)
|
| 25 |
+
img = np.expand_dims(img, axis=0)
|
| 26 |
+
model = VGG19(weights='imagenet')
|
| 27 |
+
preds = model.predict(img)
|
| 28 |
+
return decode_predictions(preds, top=3)[0]
|
| 29 |
+
|
| 30 |
+
def display_images(image_order):
|
| 31 |
+
for i in range(len(image_order)):
|
| 32 |
+
st.write(f'Image {i+1}:')
|
| 33 |
+
st.image(images[image_order[i]-1])
|
| 34 |
+
st.text_input(f'Input for Image {i+1}')
|
| 35 |
+
st.text_area(f'Output for Image {i+1}')
|
| 36 |
+
|
| 37 |
+
def photo():
|
| 38 |
+
st.header("Thresholding, Edge Detection and Contours")
|
| 39 |
+
if st.button('See Original Image of Tom'):
|
| 40 |
+
original = Image.open('tom.jpg')
|
| 41 |
+
st.image(original, use_column_width=True)
|
| 42 |
+
|
| 43 |
+
image = cv2.imread('tom.jpg')
|
| 44 |
+
image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
| 45 |
+
x = st.slider('Change Threshold value',min_value = 50,max_value = 255)
|
| 46 |
+
ret,thresh1 = cv2.threshold(image,x,255,cv2.THRESH_BINARY)
|
| 47 |
+
thresh1 = thresh1.astype(np.float64)
|
| 48 |
+
st.image(thresh1, use_column_width=True,clamp = True)
|
| 49 |
+
|
| 50 |
+
st.text("Bar Chart of the image")
|
| 51 |
+
histr = cv2.calcHist([image],[0],None,[256],[0,256])
|
| 52 |
+
st.bar_chart(histr)
|
| 53 |
+
|
| 54 |
+
st.text("Press the button below to view Canny Edge Detection Technique")
|
| 55 |
+
if st.button('Canny Edge Detector'):
|
| 56 |
+
image = load_image("jerry.jpg")
|
| 57 |
+
edges = cv2.Canny(image,50,300)
|
| 58 |
+
cv2.imwrite('edges.jpg',edges)
|
| 59 |
+
st.image(edges,use_column_width=True,clamp=True)
|
| 60 |
+
|
| 61 |
+
y = st.slider('Change Value to increase or decrease contours',min_value = 50,max_value = 255)
|
| 62 |
+
|
| 63 |
+
if st.button('Contours'):
|
| 64 |
+
im = load_image("jerry1.jpg")
|
| 65 |
+
imgray = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
|
| 66 |
+
ret,thresh =
|