python - expected string or Unicode object, Photo found in django -
here want read image db , apply operations on image noise remove .... , appy pytesseract text
def getdata(request): img = photo.objects.get(id=1) #wrapper = filewrapper(open(img.file)) # read image opencv img = cv2.imread(img) # apply dilation , erosion remove 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) # b,g,r rgb_img = cv2.merge([r,g,b]) # switch rgb # denoising dst = cv2.fastnlmeansdenoisingcolored(img,none,10,10,7,21) img = cv2.cvtcolor(dst, cv2.color_bgr2gray) # apply threshold image black , white img = cv2.adaptivethreshold(img, 127, cv2.adaptive_thresh_gaussian_c, cv2.thresh_binary, 11,2) new_image = cv2.blur(img, (1, 1))
the error comes cv2.imread(img) because imread take string or unicode parameter uri of image, using django model class quite different.
assuming photo class model has imagefield field named image fix issue changing
img = cv2.imread(img) to like
img = cv2.imread(img.image.url)
Comments
Post a Comment