Commit 68a9552b authored by Charuka_IT18114454's avatar Charuka_IT18114454

add gussian tresold for python to get correct result from captured image

parent 9e7302b2
import numpy as np import numpy as np
import cv2 import cv2
from PIL import Image from PIL import Image, ImageEnhance
import base64 import base64
import io import io
...@@ -9,8 +9,17 @@ def main(data): ...@@ -9,8 +9,17 @@ def main(data):
np_data = np.fromstring(decoded_data,np.uint8) np_data = np.fromstring(decoded_data,np.uint8)
img = cv2.imdecode(np_data,cv2.IMREAD_UNCHANGED) img = cv2.imdecode(np_data,cv2.IMREAD_UNCHANGED)
img_gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) img_gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
pil_im = Image.fromarray(img_gray)
kernel = np.ones((1, 1), np.uint8)
pil_im = cv2.dilate(img_gray, kernel, iterations=1)
pil_im = cv2.erode(pil_im, kernel, iterations=1)
# pil_im = cv2.adaptiveThreshold(cv2.medianBlur(pil_im, 5), 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 31, 5)
pil_im = cv2.threshold(cv2.GaussianBlur(pil_im, (9, 9), 0), 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)[1]
pil_im = Image.fromarray(pil_im)
buff = io.BytesIO() buff = io.BytesIO()
pil_im.save(buff,format="PNG") pil_im.save(buff,format="PNG")
img_str = base64.b64encode(buff.getvalue()) img_str = base64.b64encode(buff.getvalue())
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment