Merge pull request 'Update image processing procedure' (#3) from Yun/videocr:master into master

Reviewed-on: #3
This commit is contained in:
Pradana AUMARS 2021-07-14 18:48:31 +02:00
commit 92d131ecd6

View File

@ -62,15 +62,14 @@ class Video:
if not self.use_fullframe: if not self.use_fullframe:
# only use bottom half of the frame by default # only use bottom half of the frame by default
img = img[self.height // 2:, :] img = img[self.height // 2:, :]
# dilate and resize img = cv2.dilate(img, np.ones((2, 2), np.uint8))
img=cv2.resize(cv2.dilate(img, np.ones((2, 2), np.uint8)), self.resize_dim, interpolation=cv2.INTER_AREA) _, img = cv2.threshold(img, 215, 255, cv2.THRESH_BINARY)
color_mask = cv2.inRange(img, (255, 255, 255), (255, 255, 255))
# mask to filter out non gray-like pixels/pixels that are not bright enough img = cv2.bitwise_and(img, img, mask=color_mask)
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV) img = cv2.erode(img, np.ones((2, 2), np.uint8))
color_mask = cv2.inRange(hsv, (0, 0, 190), (179, 20, 255)) img = cv2.bitwise_not(img)
img = cv2.resize(img, self.resize_dim, interpolation=cv2.INTER_AREA)
# apply mask, inverse image so it's black text on white background, add borders to top and bottom img = cv2.copyMakeBorder(img, 20, 20, 0, 0, cv2.BORDER_CONSTANT, None, (255,255,255))
img = cv2.copyMakeBorder(cv2.bitwise_not(cv2.bitwise_and(img, img, mask=color_mask)), 10, 10, 0, 0, cv2.BORDER_CONSTANT, None, (255,255,255))
config = '--tessdata-dir "{}" --psm 7 -c preserve_interword_spaces=1'.format(constants.TESSDATA_DIR) config = '--tessdata-dir "{}" --psm 7 -c preserve_interword_spaces=1'.format(constants.TESSDATA_DIR)
try: try:
return pytesseract.image_to_data(img, lang=self.lang, config=config) return pytesseract.image_to_data(img, lang=self.lang, config=config)