コード例 #1
0
 def process(self, image, **kwargs):
     gray = GrayScale().apply(image)
     edges = Canny(low=kwargs["low"],
                   high=kwargs["high"],
                   size=kwargs["size"]).apply(gray)
     if kwargs["method"] == "normal":
         h_lines = cv2.HoughLines(edges, kwargs["rho"], kwargs["theta"],
                                  kwargs["threshold"])
         lines = []
         if h_lines is not None:
             for rho, theta in h_lines[:, 0]:
                 x1 = int(rho * np.cos(theta))
                 y1 = int(rho * np.sin(theta))
                 if x1 > y1:
                     y1 = 0
                 elif y1 > x1:
                     x1 = 0
                 x2 = (rho - image.shape[0] * np.sin(theta)) / np.cos(theta)
                 y2 = (rho - image.shape[1] * np.cos(theta)) / np.sin(theta)
                 if 0 <= x2 <= image.shape[1] or np.sin(theta) == 0:
                     y2 = image.shape[0]
                 elif 0 <= y2 <= image.shape[0] or np.cos(theta) == 0:
                     x2 = image.shape[1]
                 lines.append([[int(x1), int(y1)], [int(x2), int(y2)]])
     else:
         lines = cv2.HoughLines(
             edges,
             kwargs["rho"],
             kwargs["theta"],
             kwargs["threshold"],
             kwargs["min_size"],
             kwargs["max_gap"],
         )
     return {"lines": lines}
コード例 #2
0
ファイル: test_image.py プロジェクト: easycv/easycv
def test_compute():
    image = Image("tests/images/lenna.png", lazy=True)
    image = image.apply(GrayScale())
    assert image.pending.num_transforms() == 1
    computed = image.compute()
    assert computed.pending.num_transforms() == 0
    image.compute(in_place=True)
    assert image.pending.num_transforms() == 0
コード例 #3
0
 def process(self, image, **kwargs):
     blur = easycv.transforms.filter.Blur(method="median",
                                          size=kwargs["size"]).apply(image)
     gray = GrayScale().apply(blur)
     circles = cv2.HoughCircles(
         gray,
         cv2.HOUGH_GRADIENT,
         kwargs["dp"],
         kwargs["min_dist"],
         param1=kwargs["high"],
         param2=kwargs["threshold"],
         minRadius=kwargs["min_radius"],
         maxRadius=kwargs["max_radius"],
     )
     return {"circles": circles[0]}
コード例 #4
0
 def process(self, image, **kwargs):
     image = GrayScale().apply(image)
     if kwargs["method"] == "sobel":
         if kwargs["axis"] == "both":
             x = cv2.Sobel(image, cv2.CV_64F, 1, 0, ksize=kwargs["size"])
             y = cv2.Sobel(image, cv2.CV_64F, 1, 0, ksize=kwargs["size"])
             return (x**2 + y**2)**0.5
         if kwargs["axis"] == "x":
             return cv2.Sobel(image, cv2.CV_64F, 1, 0, ksize=kwargs["size"])
         else:
             return cv2.Sobel(image, cv2.CV_64F, 0, 1, ksize=kwargs["size"])
     elif kwargs["method"] == "laplace":
         return cv2.Laplacian(image, cv2.CV_64F)
     else:
         kernel = np.ones((kwargs["size"], kwargs["size"]), np.uint8)
         return cv2.morphologyEx(image, cv2.MORPH_GRADIENT, kernel)
コード例 #5
0
    def process(self, image, **kwargs):
        cascade = cv2.CascadeClassifier(kwargs["cascade"])
        gray = GrayScale().apply(image)
        detections = cascade.detectMultiScale(
            gray,
            scaleFactor=kwargs["scale"],
            minNeighbors=kwargs["min_neighbors"],
            minSize=kwargs["min_size"]
            if kwargs["min_size"] != "auto" else None,
            maxSize=kwargs["max_size"]
            if kwargs["max_size"] != "auto" else None,
        )

        rectangles = []
        for x, y, w, h in detections:
            rectangles.append([(x, y), (x + w, y + h)])

        return {"rectangles": rectangles}
コード例 #6
0
    def process(self, image, **kwargs):
        grayscale = GrayScale().apply(image)

        if kwargs["method"] == "laplace":
            sharpness = (easycv.transforms.edges.Gradient(
                method="laplace").apply(grayscale).var())
        else:
            h, w = grayscale.shape
            centerx, centery = (int(w / 2.0), int(h / 2.0))
            fft = np.fft.fft2(grayscale)
            fft_shift = np.fft.fftshift(fft)
            size = kwargs["size"]
            fft_shift[centery - size:centery + size,
                      centerx - size:centerx + size] = 0
            fft_shift = np.fft.ifftshift(fft_shift)
            recon = np.fft.ifft2(fft_shift)
            sharpness = np.mean(20 * np.log(np.abs(recon)))

        return {
            "sharpness": sharpness,
            "sharpen": sharpness >= kwargs["threshold"]
        }
コード例 #7
0
ファイル: test_image.py プロジェクト: easycv/easycv
def test_apply():
    image = Image("tests/images/lenna.png")
    pipe = Pipeline([Blur(), GrayScale()])
    image2 = image.apply(Blur()).apply(GrayScale())
    image = image.apply(pipe)
    assert image == image2
コード例 #8
0
ファイル: test_image.py プロジェクト: easycv/easycv
def test_pending():
    image = Image("tests/images/lenna.png", lazy=True)
    image = image.apply(FilterChannels(channels=[0, 1]))
    image.apply(GrayScale(), in_place=True)
    assert image.pending.num_transforms() == 2
コード例 #9
0
 def process(self, image, **kwargs):
     image = GrayScale().apply(image)
     x = cv2.Sobel(image, cv2.CV_64F, 1, 0, ksize=kwargs["size"])
     y = cv2.Sobel(image, cv2.CV_64F, 0, 1, ksize=kwargs["size"])
     return np.arctan2(x, y)