【发布时间】:2018-01-01 14:14:59
【问题描述】:
在这里,我想从 db 中读取图像并对我的图像应用一些操作,例如去噪 .... 最后我将应用 pytesseract 来获取文本
def GetData(request):
img = Photo.objects.get(id=1)
#wrapper = FileWrapper(open(img.file))
# Read image with opencv
img = cv2.imread(img)
# Apply dilation and erosion to remove some noise
kernel = np.ones((1, 1), np.uint8)
img = cv2.dilate(img, kernel, iterations=1)
img = cv2.erode(img, kernel, iterations=1)
b,g,r = cv2.split(img)
# get b,g,r
rgb_img = cv2.merge([r,g,b])
# switch it to rgb
# Denoising
dst = cv2.fastNlMeansDenoisingColored(img,None,10,10,7,21)
img = cv2.cvtColor(dst, cv2.COLOR_BGR2GRAY)
# Apply threshold to get image with only black and white
img = cv2.adaptiveThreshold(img, 127, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 11,2)
new_image = cv2.blur(img, (1, 1))
【问题讨论】:
-
你的问题是什么?
-
请考虑编辑您的问题,添加诸如您如何定义
Photo类模型、您的堆栈跟踪到底是什么等信息 -
from django.db import models class Photo(models.Model): file = models.ImageField() description = models.CharField(max_length=255, blank=True) upload_at = models.DateTimeField(auto_now_add =True) class Meta: verbose_name = 'photo' verbose_name_plural = 'photos' 我想从照片中获取文本