Skip to content Skip to sidebar Skip to footer

Letters Blurry / Fuzzy After Crop Function

after attempting to crop my image in several locations by saving the list of coordinates to an array the letters in the cropped area become extremely blurry and I cannot figure out

Solution 1:

import numpy as np
import cv2
import matplotlib.pyplot as plt

im2 = cv2.imread('norm1_zps89266edb.jpg')
im = im2.copy()

gray = cv2.cvtColor(im,cv2.COLOR_BGR2GRAY)
blur = cv2.GaussianBlur(gray,(5,5),0)
ret3,thresh = cv2.threshold(blur,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)

#we ony want the external contours
contours,hierarchy = cv2.findContours(thresh.copy(),cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE) 
#extract the countours with area > 50
squares = [cnt for cnt in contours if cv2.contourArea(cnt) > 50]

#mask array with the same shape as img (but only 1 channel)
mask = np.zeros((im.shape[0], im.shape[1]))
#draw the contours filled with 255 values. 
cv2.drawContours(mask,squares,-1,255,-1)

newImage = np.where(mask==255, thresh, 255)

plt.imshow(newImage)
plt.show()

cv2.imwrite("cropped.jpg", newImage)

output:
http://i44.tinypic.com/8yak93.jpg


Post a Comment for "Letters Blurry / Fuzzy After Crop Function"