【发布时间】:2019-01-08 13:53:20
【问题描述】:
我将 Python 3.6 和 Django 1.11 与 opencv 一起使用。
我想要实现的是,用户将上传一张照片,然后在基于新功能的操作上,我将在渲染模板上显示上传的图像直方图。到目前为止,我已经完成了以下操作:
import cv2
import numpy as np
from matplotlib import pyplot as plt
def show(request, id=None):
instance = get_object_or_404(Album, id=id)
img = cv2.imread(instance.photo.path)
color = ('b', 'g', 'r')
for i, col in enumerate(color):
histr = cv2.calcHist([img], [i], None, [256], [0, 256])
plt.plot(histr, color=col)
plt.xlim([0, 256])
# here plt.show() will open a new window with the histogram.
# but I want to show that plt histogram to the below rendered
# show.html template
context = {
'title': 'Detail',
'instance': instance,
'histogram': # here i want to pass the histogram as image
}
return render(request, 'album/show.html', context)
在我的 album/show.html 中,我想显示如下直方图:
<img class="card-img-top" src="{{ --define histogram src here-- }}"
alt="Card image cap">
有人知道如何实现吗?
提前致谢!
【问题讨论】:
标签: python django opencv histogram