大家好,明天萝卜哥用Python做了一个网页版的“P图软件”,大抵的流程在于咱们能够将上传的照片进行黑白解决、铅笔素描解决、模糊化解决等一系列操作,具体如下

上面咱们来看一下该整个网页是怎么写的

网页左侧的工具栏局部

首先第一步在于导入咱们所须要用到的模块,代码如下

import streamlit as stimport numpy as npimport cv2from PIL import Image, ImageEnhance

咱们先设计到网页当中的题目和右边的工具栏,右边的工具栏局部代码如下

st.sidebar.markdown('<p class="font">My First Photo Converter App</p>', unsafe_allow_html=True)with st.sidebar.expander("About the App"):     st.write("""        Use this simple app to convert your favorite photo to a pencil sketch, a grayscale image or an image with blurring effect.  \n  \nThis app was created by Junxin as a side project to learn Streamlit and computer vision. Hope you enjoy!     """)

首先在工具栏当中增加的是对于该利用的介绍,通过调用streamlit模块当中的sidebar办法来生成一个下拉框,在通过点击“+”键来关上,

而后则是5个单选框,代码如下

filter = st.sidebar.radio('Covert your photo to:', ['Original', 'Gray Image', 'Black and White', 'Pencil Sketch', 'Blur Effect'])

单选框是通过sidebar办法来实现的,当中增加上别离是哪些的单选项,

紧接着是最初的“感激反馈”的局部,代码如下

st.sidebar.title(' ')st.sidebar.markdown(' ')st.sidebar.subheader('Please help us improve!')with st.sidebar.form(key='columns_in_form',clear_on_submit=True):     rating=st.slider("Please rate the app", min_value=1, max_value=5, value=3,help='Drag the slider to rate the app. This is a 1-5 rating scale where 5 is the highest rating')    text=st.text_input(label='Please leave your feedback here')    submitted = st.form_submit_button('Submit')    if submitted:      .......

网页注释的题目局部

题目局部的代码如下

with col1:    st.markdown(""" <style> .font {    font-size:35px ; font-family: 'Cooper Black'; color: #FF9633;}     </style> """, unsafe_allow_html=True)    st.markdown('<p class="font">Upload your photo here...</p>', unsafe_allow_html=True)

当然除此之外,咱们须要的是上传图片的性能,代码如下

uploaded_file = st.file_uploader("", type=['jpg', 'png', 'jpeg'])

这里调用的是streamlit模块当中的file_uploader办法,其中容许上传的有三种文件格式,别离是jpgpng以及jpeg

接下去便是上传图片的解决逻辑局部,代码如下,

with col2:    filter = st.sidebar.radio('Covert your photo to:', ['Original', 'Gray Image', 'Black and White', 'Pencil Sketch', 'Blur Effect'])    if filter == 'Gray Image':        converted_img = np.array(image.convert('RGB'))        gray_scale = cv2.cvtColor(converted_img, cv2.COLOR_RGB2GRAY)            ......    elif filter == 'Black and White':            ......    elif filter == 'Pencil Sketch':            ......    elif filter == 'Blur Effect':            ......    else:        st.image(image, width=300)

以上就是本次分享的所有内容,如果你感觉文章还不错,欢送关注公众号:Python编程学习圈,每日干货分享,发送“J”还可支付大量学习材料。或是返回编程学习网,理解更多编程技术常识。