Team Ai
Apppublic

HeyMengxu/ComputerVision

sourceHugging Faceupdated 3y agoView on Hugging Face
0likes
app.py41 linesDownload Raw Back to root
1 2import cv23import numpy as np4import gradio as gr5 6def detect_sky(image_path):7 8  img = cv2.imread(image_path)9 10  hsv_img = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)11 12  h, s, v = cv2.split(hsv_img)13  v = cv2.equalizeHist(v)14  mer_img = cv2.merge((h, s, v))15 16  iLow = np.array([100, 43, 46])17  iHigh = np.array([124, 255, 255])18 19  rng_img = cv2.inRange(mer_img, iLow, iHigh)20 21  kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (10, 10))22  erode_img = cv2.erode(rng_img, kernel)23  dlt_img = cv2.dilate(erode_img, kernel)24 25  ret, mask = cv2.threshold(dlt_img, 150, 255, cv2.THRESH_BINARY)26  notmask = cv2.bitwise_not(mask)27  frontpic = cv2.bitwise_and(img, img, mask=notmask)28   29  # Convert the image to RGB format (Gradio expects RGB)30  result_rgb = cv2.cvtColor(frontpic, cv2.COLOR_BGR2RGB)31 32    # Encode the image as bytes33    #_, result_bytes = cv2.imencode('.png', result_rgb)34    # Convert bytes to a NumPy array35  return result_rgb36  37 38demo = gr.Interface(fn=detect_sky,inputs=gr.Image(type="filepath"),outputs="image")39 40# Launch the Gradio interface in Colab41demo.launch()