Esempio n. 1
0
    def draw_corner_harris(self):
        img = Utils.fetch_image(ImageURL.CHESS)
        orig = img.copy()

        gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

        dts = cv2.cornerHarris(src=gray, blockSize=2, ksize=3, k=.0001)

        img[dts > 0.01 * dts.max()] = [0, 0, 255]
        return img, orig
Esempio n. 2
0
    def hough_circles_process(self):
        image = Utils.fetch_image(url=ImageURL.OPENCV_LOGO)
        orig = image.copy()
        circles = self.get_hough_circles(image)

        for [x, y, raduis] in circles[0, :]:
            cv2.circle(img=image,
                       center=(x, y),
                       radius=raduis,
                       color=(0, 0, 255),
                       thickness=2)

        return image, orig
Esempio n. 3
0
    def affin_rotate(self):
        src = Utils.fetch_image(ImageURL.RANDOM)
        orig = src.copy()
        srcTri = np.array([[0, 0], [src.shape[1] - 1, 0],
                           [0, src.shape[0] - 1]]).astype(np.float32)
        dstTri = np.array([[0, src.shape[1] * 0.33],
                           [src.shape[1] * 0.85, src.shape[0] * 0.25],
                           [src.shape[1] * 0.15,
                            src.shape[0] * 0.7]]).astype(np.float32)

        warp_mat = cv2.getAffineTransform(srcTri, dstTri)
        warp_dst = cv2.warpAffine(src, warp_mat, (src.shape[1], src.shape[0]))

        center = (warp_dst.shape[1] // 2, warp_dst.shape[0] // 2)

        angle = 90
        scale = 1
        rotated = cv2.getRotationMatrix2D(center, angle, scale)
        return src, orig
Esempio n. 4
0
    def contours_process(self):
        image = Utils.fetch_image(url=ImageURL.RANDOM)
        orig = image.copy()
        contours = self.get_contours(image)

        cv2.drawContours(image=image,
                         contours=contours,
                         contourIdx=-1,
                         color=(0, 0, 255),
                         thickness=3)

        cv2.putText(img=image,
                    text=f"contours: {str(len(contours))}",
                    org=(10, 40),
                    fontScale=1.2,
                    fontFace=cv2.FONT_HERSHEY_SIMPLEX,
                    color=(0, 0, 0),
                    thickness=2)
        return image, orig
Esempio n. 5
0
    def draw_good_features_to_track(self):
        img = Utils.fetch_image(ImageURL.CHESS)
        orig = img.copy()

        gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

        koseler = cv2.goodFeaturesToTrack(image=gray,
                                          maxCorners=50,
                                          qualityLevel=0.0001,
                                          minDistance=10)

        for kose in koseler:
            x, y = kose.ravel()
            cv2.circle(img=img,
                       center=(x, y),
                       radius=3,
                       color=(0, 0, 255),
                       thickness=-1)

        return img, orig
Esempio n. 6
0
    def hough_lines_process(self):

        image = Utils.fetch_image(url=ImageURL.BUILDING)
        orig = image.copy()

        lines = self.get_hough_lines(image)

        for rho, theta in lines[0]:
            a = np.cos(theta)
            b = np.sin(theta)
            x0 = a * rho
            y0 = b * rho
            x1 = int(x0 + 1000 * (-b))
            y1 = int(y0 + 1000 * (a))
            x2 = int(x0 - 1000 * (-b))
            y2 = int(y0 - 1000 * (a))

            cv2.line(image, (x1, y1), (x2, y2), (0, 0, 255), 2)

        return image, orig
Esempio n. 7
0
import cv2
from lib.utils import Utils
from lib.helpers import ImageURL

img = Utils.fetch_image(url=ImageURL.RANDOM)
print(img)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

Utils.show_image_compare(img, gray)
cv2.waitKey(0)