python - 如何使用带有 Streamlit 的按钮显示文件夹中的图像?
问题描述
我想使用按钮在我的流线型 Web 应用程序中显示图像。
因此,每当用户单击按钮时,图像都必须显示在流光网络应用程序上。
下面给出的代码:
feature_choice2 = st.sidebar.multiselect("Plot Size", task2)
if st.button('Find Blueprint'):
if feature_choice2 == '3-marla':
imagee = cv2.imread('Floor_plans/3-marla.png')
cv2.imshow('Image', imagee)
st.image(imagee, caption='3 marla plot')
解决方案
Streamlit 不会以自然形式上传图像,因此必须将其转换为数组然后使用它。希望这可以帮助:
import cv2
import numpy as np
import streamlit as st
uploaded_file = st.file_uploader("Choose a image file", type="jpg")
if uploaded_file is not None:
# Convert the file to an opencv image.
file_bytes = np.asarray(bytearray(uploaded_file.read()), dtype=np.uint8)
opencv_image = cv2.imdecode(file_bytes, 1)
# Now do something with the image! For example, let's display it:
st.image(opencv_image, channels="BGR")
推荐阅读
- java - 使用椭圆曲线 ElGamal 加密 AES 密钥
- django - 图像不会加载到 Django 中的模板,而是存储到媒体文件中
- julia - 在 julia 中使用 GSL.jl 集成例程:integration_qawc
- ios - 在 iOS 13 上滚动到顶部时,工具栏项目重置为故事板默认值
- mongoose - Nestjs原始mongodb查询
- c++ - 为什么并行执行策略这么慢
- javascript - 如何滚动焦点组件以查看在 React JS 中显示的屏幕键盘?
- mongoose - GraphQL 在 mongoose 回调中返回 Null
- sql-server - 会话阻止自己
- scheme - 有什么方法可以在 Scheme/Racket 中映射具有多个参数的函数?