Esempio n. 1
0
def string2txt(image, string):
    roi = String.extractROI(image, string, False)
    bgr = roi.cropped
    gray = cv2.cvtColor(bgr, cv2.COLOR_BGR2GRAY)
    laplacian = Laplacian(gray)
    lthr = cv2.adaptiveThreshold(laplacian, 255.0,
                                 cv2.ADAPTIVE_THRESH_GAUSSIAN_C,
                                 cv2.THRESH_BINARY_INV,
                                 ADAPTIVE_THRESH_BLOCK_SIZE,
                                 ADAPTIVE_THRESH_WEIGHT)
    dog = DoG(gray)
    compose = maskize(lthr, dog)
    ###
    img_contour, contours, npaHierarchy = cv2.findContours(
        compose, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
    cv2.drawContours(img_contour, contours, -1, SCALAR_WHITE, -1)
    chars = find_possible_chars(contours, False)
    chars = innerfiltering(chars)
    chars.sort(key=lambda char: char.brX)
    img_char = drawChars(gray.shape, "size-filtering", chars)
    compose = maskize(img_contour, 255 - img_char)
    #showResult("compose",compose)
    ### OCR
    ocrresult, count = string.ocr2(compose, chars)
    string.meaningfulcharcount = count
    return ocrresult
 def makeCompose(self):
     self.gray = cv2.cvtColor(self.resultimg, cv2.COLOR_BGR2GRAY)
     if self.mode == "Yellow":
         self.gray = 255 - self.gray
     # DOG
     equalized_image = cv2.equalizeHist(self.gray)
     self.DoG = DoG(equalized_image)  #Difference of Gaussians
     self.compose = maskize(self.thr, self.DoG)
 def preprocess(self, mode="Blue"):
     gray = cv2.cvtColor(self.bgr, cv2.COLOR_BGR2GRAY)
     if mode == "Blue":
         self.mode = "Blue"
         self.gray = gray  #iicontrast(gray)#contrast(gray)#equalized_image = cv2.equalizeHist(self.gray)
     else:
         self.mode = "Yellow"
         self.gray = 255 - gray
     self.DoG = DoG(self.gray)  #Difference of Gaussians
     self.laplacian = Laplacian(self.gray, needcontrast=False)
     self.thr = AdaptiveThreshold(self.laplacian)
     self.thr = maskize(self.thr, self.DoG)
Esempio n. 4
0
 def preprocess(self, image):
     self.bgr = image
     gray = cv2.cvtColor(self.bgr, cv2.COLOR_BGR2GRAY)
     self.gray = icontrast(255 - gray)
     self.laplacian = Laplacian(gray)
     #self.sobel = Sobel(gray)
     #self.entropy = Entropy(gray)
     #self.garbor = Garbor(gray)
     self.DoG = DoG(gray)
     self.lthr = AdaptiveThreshold(self.laplacian)
     self.tophat = tophatmask(gray)
     #tophatblackhat(gray)
     masks = []
     #masks.append(self.tophat)
     masks.append(self.DoG)
     self.compose = maskize(self.lthr, masks)
     self.contour = np.zeros((self.compose.shape[:2]), np.uint8)