python - 如何从数据库(sqlite Django)而不是本地文件中读取图像?
问题描述
- OpenCV => 3.4,操作系统/平台 => Ubuntu18.4,编译器 => Pycharm2018,Django => 2.1.2
我正在尝试从数据库中获取图像并对图像进行编码以进行人脸识别。
模型
from django.db import models
class Image(models.Model):
name = models.CharField(max_length=500)
imagefile = models.FileField(upload_to='images/', null=True, verbose_name="")
def __str__(self):
return self.name + ": " + str(self.imagefile)
读取图像
from .models import Image
import cv2
lastimage = Image.objects.last()
imagefile = lastimage.imagefile
image = cv2.imread(imagefile)
cv2.imshow('image',image)
错误 得到这个错误
异常类型:TypeError
异常值:内置操作的参数类型错误
解决方案
这是我创建 AI Web 项目时的方法:
np.ndarray <=( cv2.imencode| cv2.imdecode) => buff <==> base64
推荐阅读
- apache-spark - 如何根据多个排名条件合并到 Delta Lake?
- c# - 如何通过 Serializer 正确动态创建自定义 JSON
- java - zip4J 异常解压缩密码保护的 zip 文件
- html - 简单灯箱未正确缩放
- wolfram-mathematica - 在 Mathematica 中设置默认绘图设置——颜色、虚线、线宽
- kubernetes - 如何在 istio 1.8.3 中收集 Envoy 输出的访问日志
- css - 如何以跨浏览器的方式在 CSS 中指定日文字体?
- python - 在线“Zybooks”编码中的 Python EOFerror
- python - 接收空数据帧以解决纸浆优化问题
- oracle - 我可以为 ASM 创建 Oracle 数据库链接吗?