2017-07-26 32 views
-3

在这里,我想读取数据库的形象和我的形象上涂抹一些操作,例如噪音删除发现的....最后我会APPY pytesseract来获取文本期望的字符串或Unicode对象,照片在Django

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)) 
+0

什么是你的问题? – Antwane

+0

请考虑编辑怎么样,你从django.db进口车型 类照片(models.Model)定义了'Photo'类模型,正是你的堆栈跟踪是什么,等等 – mrnfrancesco

+0

你的问题添加信息: 文件=模型。 ImageField的() 描述= models.CharField(MAX_LENGTH = 255,空=真) UPLOADED_AT = models.DateTimeField(auto_now_add = TRUE) 类元: verbose_name = '照片' verbose_name_plural = '照片' 我想从照片中获取文字 – pratap

回答

1

这个错误来自cv2.imread(img)因为imread采取与图像的URI一个stringunicode参数,但您使用的是Django的模型类,这是完全不同的。

假设你Photo类模型有一个ImageField场名为image你能解决您的问题改变

img = cv2.imread(img) 

喜欢的东西

img = cv2.imread(img.image.url) 
相关问题