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