Exemplo n.º 1
0
    def HoughDetect(self, img):
        #        img = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)

        img = cv2.medianBlur(img, 5)
        img = auto.AutoCanny(img)
        #        img = cv2.Canny(img,self.canny_lower,self.canny_upper)

        img = cv2.resize(img, (300, 300))

        img_line = np.zeros((300, 300))

        img_contour, contours, hierarchy = cv2.findContours(
            img, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
        img_contour = cv2.drawContours(img_contour, contours, -1,
                                       (255, 255, 255), 1)
        cv2.imshow("contour", img_contour)
        lines = cv2.HoughLines(img, 1, np.pi / 1440, 180)

        if lines is not None:

            for line in lines:
                rho, theta = line[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(img_line, (x1, y1), (x2, y2), (255, 255, 255), 2)

        result = img_contour - img_line

        #        result = cv2.morphologyEx(result, cv2.MORPH_ERODE, self.kernel, iterations=2)
        #result = cv2.morphologyEx(result, cv2.MORPH_OPEN, self.linek, iterations=1)

        return result
Exemplo n.º 2
0
    def HoughDetect(self, img):
        h, w = img.shape[:2]

        img = cv2.medianBlur(img, 5)

        img = auto.AutoCanny(img)

        img_line = np.zeros((h, w))

        img_contour, contours, hierarchy = cv2.findContours(
            img, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
        img_contour = cv2.drawContours(img_contour, contours, -1,
                                       (255, 255, 255), 3)

        lines = cv2.HoughLines(img, 1, np.pi / 1440, 180)

        if lines is not None:

            for line in lines:
                rho, theta = line[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(img_line, (x1, y1), (x2, y2), (255, 255, 255), 5)

        result = img_contour - img_line
        result = result[90:340, 175:425]

        #result = cv2.morphologyEx(result, cv2.MORPH_ERODE, self.kernel, iterations=2)
        #result = cv2.morphologyEx(result, cv2.MORPH_OPEN, self.linek, iterations=1)

        return result
Exemplo n.º 3
0
cam = cv2.VideoCapture(0)

while (cam.isOpened()):
    I1 = []
    I2 = []
    I3 = []

    ret, img = cam.read()

    img = Dist.Undistort(img)

    img = img[90:340, 175:425]

    h, w = img.shape[:2]

    img_h = auto.AutoCanny(img)
    #img_h = Hough.HoughDetect(img)
    #img_h = cv2.morphologyEx(img_h, cv2.MORPH_CLOSE, kernel, iterations=1)
    cv2.imshow("canny", img_h)
    npic_1 = np.zeros((h, w), dtype=np.float32)
    npic_2 = np.zeros((h, w), dtype=np.float32)
    npic_3 = np.zeros((h, w), dtype=np.float32)

    points = newlib.GooBoundary(img_h)

    key = cv2.waitKey(10)

    len_x, len_y, npic_1 = newlib.MakeLength(img_h, points)

    grad_x = (np.gradient(len_x))
    grad_y = (np.gradient(len_y))
Exemplo n.º 4
0
    if (key == 27):
        break

    #Get webcam screen
    ret, img = cam.read()

    #Calibrating webcam
    dst = Dist.Undistort(img)

    h, w = dst.shape[:2]

    #Grayscale image
    gray = cv2.cvtColor(dst, cv2.COLOR_BGR2GRAY)

    #Canny image
    dst = auto.AutoCanny(gray)

    #Crop image
    dst = dst[15:415, 100:500]

    #Dilate to enhance image
    dst = cv2.morphologyEx(dst, cv2.MORPH_DILATE, kernel, iterations=1)

    #Construct blank image
    pic1 = dst.copy()
    pic1[:] = 0
    pic2 = dst.copy()
    pic2[:] = 0

    #Get border points
    points = dp(dst)