1

ボタンを使用して、streamlit Web アプリに画像を表示したいと考えています。

そのため、ユーザーがボタンをクリックするたびに、ストリームリット 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')
4

3 に答える 3

4

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")
于 2020-08-16T06:28:41.070 に答える
2

cv2.imshow別の別のウィンドウが開くため、ストリームライトで画像を表示している間は機能しません。

イメージ自体に何らかの操作を実行する予定がない限り、

from PIL import Image
import streamlit as st

feature_choice2 = st.sidebar.multiselect("Plot Size", task2)
if st.button('Find Blueprint'):
    if feature_choice2 == '3-marla':
        image = Image.open('./Floor_plans/3-marla.png')
        st.image(image, caption='3 marla plot',use_column_width=True)

注: これを機能させるには、ディレクトリ構造を次のようにする必要があります。

|- app.py # Your Streamlit Script
|- Floor_plans
   |- 3-marla.png
于 2021-02-09T18:37:58.217 に答える