Exemplo n.º 1
0
 def get_projection(self, rows_expected=1):
     binary = cv2.adaptiveThreshold(
         self.image, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY_INV,
         Projection.to_odd(self.get_stroke_width(1) * 2), 5)
     # th, binary = cv2.threshold(self.image, 127, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)
     self.latest_reference_image = binary
     binary[binary > 0] = 1
     vector = np.sum(binary, axis=1 - self.orientation)
     assert len(vector) == self.measurement
     return Projection.normalize(vector)
Exemplo n.º 2
0
 def get_projection(self, rows_expected=1):
     binary = cv2.adaptiveThreshold(
         self.image,
         255,
         cv2.ADAPTIVE_THRESH_MEAN_C,
         cv2.THRESH_BINARY_INV,
         Projection.to_odd(self.get_stroke_width(1) * 2),
         5)
     # th, binary = cv2.threshold(self.image, 127, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)
     self.latest_reference_image = binary
     binary[binary > 0] = 1
     vector = np.sum(binary, axis=1-self.orientation)
     assert len(vector) == self.measurement
     return Projection.normalize(vector)
Exemplo n.º 3
0
    def get_projection(self, interpolation_type=cv2.INTER_CUBIC):
        """List of average pixel values along the axis

        >>> arr = cv2.imread('assets/img/doctests/digits.jpg', 0)
        >>> # horizontal
        >>> bins = ColorfulProjection(arr, Projection.TYPE_HORIZONTAL)
        >>> bins.get_projection()[3]
        0.0043103448275862068
        >>> # bins.debug("colorful horizontal")
        >>>
        >>> # vertical
        >>> bins = ColorfulProjection(arr, Projection.TYPE_VERTICAL)
        >>> bins.get_projection()[3]
        0.047008547008547008
        >>> # bins.debug("colorful vertical")
        """
        new_shape = (1, self.measurement
                     ) if self.orientation == self.TYPE_HORIZONTAL else (
                         self.measurement, 1)
        vector = cv2.resize(self.image,
                            new_shape,
                            interpolation=interpolation_type).flatten()
        vector = 255 - vector
        assert len(vector) == self.measurement
        return Projection.normalize(vector)
Exemplo n.º 4
0
    def get_projection(self, interpolation_type=cv2.INTER_CUBIC):
        """List of average pixel values along the axis

        >>> arr = cv2.imread('assets/img/doctests/digits.jpg', 0)
        >>> # horizontal
        >>> bins = ColorfulProjection(arr, Projection.TYPE_HORIZONTAL)
        >>> bins.get_projection()[3]
        0.0043103448275862068
        >>> # bins.debug("colorful horizontal")
        >>>
        >>> # vertical
        >>> bins = ColorfulProjection(arr, Projection.TYPE_VERTICAL)
        >>> bins.get_projection()[3]
        0.047008547008547008
        >>> # bins.debug("colorful vertical")
        """
        new_shape = (1, self.measurement) if self.orientation == self.TYPE_HORIZONTAL else (self.measurement, 1)
        vector = cv2.resize(self.image, new_shape, interpolation=interpolation_type).flatten()
        vector = 255 - vector
        assert len(vector) == self.measurement
        return Projection.normalize(vector)