2020
10-04
10-04
Python flask框架如何显示图像到web页面
代码如下webfig1.pyfromflaskimportFlaskfromflaskimportrender_templateimportmatplotlib.pyplotaspltimportioimportbase64app=Flask(__name__)@app.route('/')defbuild_plot():img=io.BytesIO()y=[1,2,3,4,5]x=[0,2,1,3,4]plt.plot(x,y)plt.savefig(img,format='png')img.seek(0)plot_url=base64.b64encode(img.getvalue()).decode()returnrender_template('plot.html',plot_url=plot_...
继续阅读 >
感想我们在用jupyternotebook的时候,经常需要可视化一些东西,尤其是一些图像,我这里给个samplecode环境opencv-pythonmatplotlibnumpysampleimportosimportnumpyasnpfrommatplotlibimportpyplotasplt%matplotlibinlineimg_dir='/Users/eric/Documents/data/wheel_train_val/train/non_defect/'filename='00005.BMP_block_8.jpg'img=cv2.imread(img_dir+os.sep+filename)plt.imshow(img)plt.show()补充知识:jupy...