예제 #1
0
def detect(img):
    canny = thresh(img)

    sobel = cv2.Sobel(canny, cv2.CV_64F, 1, 0, ksize=5)
    row, col = sobel.shape

    sobel = cv2.erode(sobel, np.ones([int(row / 15), 1]), iterations=1)
    sobel = cv2.dilate(sobel, np.ones([int(row / 1.5), 1]), iterations=1)
    sobel = np.array(sobel, dtype=np.uint8)
    _, sobel = cv2.threshold(sobel, 200, 255, cv2.THRESH_BINARY)
    # print(canny.shape)

    lines = cv2.HoughLinesP(sobel, 1, np.pi / 180, 150, None, int(0.5 * row),
                            30)
    # print("Initial lines : " , len(lines))
    # val = 0
    if lines is not None:
        lines = lines.tolist()
        lines.sort(key=lambda x: x[0][0])
        print("Initial Lines : ", len(lines))
        lines = deletelines(lines)
        print("After deletion : ", len(lines))

        for line in lines:
            # print(line)
            cv2.line(img, (line[0][0], line[0][1]), (line[0][2], line[0][3]),
                     (0, 255, 0), 2)

            if line[0][0] == line[0][2]:
                theta = 90
            else:
                theta = slope(line)
            # print(theta)
            if theta > 80:
                cv2.line(img, (line[0][0], line[0][1]),
                         (line[0][2], line[0][3]), (0, 255, 0), 2)
                # val+=1
        # print(val)

        cv2.imshow("Output", img)
        # cv2.imshow("Sobel",sobel)
        # cv2.imshow("Canny",canny)
        cv2.waitKey(0)

        vertical_lines = [x[0][0] for x in lines]
        # print(vertical_lines)
        return vertical_lines
예제 #2
0
def detect(img):  # Detect Vertical Lines
    canny = thresh(img)  # Thresh

    sobel = cv2.Sobel(canny, cv2.CV_64F, 1, 0,
                      ksize=5)  # Apply Sobel filter -- Y
    row, col = sobel.shape

    # Morphological Opn
    sobel = cv2.erode(sobel, np.ones([int(row / 15), 1]), iterations=1)
    sobel = cv2.dilate(sobel, np.ones([int(row / 1.5), 1]), iterations=1)
    sobel = np.array(sobel, dtype=np.uint8)
    _, sobel = cv2.threshold(sobel, 200, 255, cv2.THRESH_BINARY)
    # print(canny.shape)

    # Detect Vertical Lines
    lines = cv2.HoughLinesP(sobel, 1, np.pi / 180, 150, None, int(0.4 * row),
                            30)
    # print("Initial lines : " , len(lines))

    if lines is not None:
        lines = lines.tolist()
        lines.sort(key=lambda x: x[0][0])
        # print("Initial Lines : ",len(lines))
        lines = deletelines(lines)  # Delete Clustered Lines
        # print("After deletion : ",len(lines))

        for line in lines:
            # cv2.line(img,(line[0][0],line[0][1]),(line[0][2],line[0][3]),(0,255,0),2)

            if line[0][0] == line[0][2]:
                theta = 90
            else:
                theta = slope(line)

        # cv2.imshow("Output",img)
        # cv2.imshow("Sobel",sobel)
        # cv2.imshow("Canny",canny)
        # cv2.waitKey(0)

        vertical_lines = [x[0][0] for x in lines]
        return vertical_lines
예제 #3
0
def detect(img):            #Horizontal Lines Detection
    canny = rectangle.thresh(img)       # Thresh image
    sobel = cv2.Sobel(canny,cv2.CV_64F,0,1,ksize=5)     # Sobel Filtering
    row,col = sobel.shape

    # Morphological Operations
    sobel = cv2.erode(sobel,np.ones([1,int(col/10)]),iterations=1)
    sobel = cv2.dilate(sobel,np.ones([1,int(col/2)]),iterations=1)
    sobel = np.array(sobel,dtype=np.uint8)
    _,sobel = cv2.threshold(sobel,200,255,cv2.THRESH_BINARY)

    # Detect Lines
    lines = cv2.HoughLinesP(sobel,1,np.pi/180,150,None,col/2,30)

    val = 0
    if lines is not None:       # Condition Check
        lines = lines.tolist()
        lines.sort(key= lambda x : x[0][1])
        # print(len(lines))
        lines = deletelines(lines)      # Delete clustered lines

        for line in lines:

            if line[0][0] == line[0][2]:
                theta = 90
            else :
                theta = slope(line)

            if theta < 10:      # Condition Check
                # cv2.line(img,(line[0][0],line[0][1]),(line[0][2],line[0][3]),(0,255,0),2)
                val+=1


        # cv2.imshow("Sobel",sobel)
        # cv2.imshow("Canny",canny)
        # cv2.waitKey(0)

        return lines
예제 #4
0
def detect(img):
    canny = thresh(img)
    sobel = cv2.Sobel(canny, cv2.CV_64F, 0, 1, ksize=5)
    row, col = sobel.shape

    sobel = cv2.erode(sobel, np.ones([1, int(col / 10)]), iterations=1)
    sobel = cv2.dilate(sobel, np.ones([1, int(col / 2)]), iterations=1)
    _, sobel = cv2.threshold(sobel, 200, 255, cv2.THRESH_BINARY)
    sobel = np.array(sobel, dtype=np.uint8)
    # print(sobel.shape,sobel.dtype)

    lines = cv2.HoughLinesP(sobel, 1, np.pi / 180, 150, None, col / 2, 30)
    # print("Initial lines : " , len(lines))
    val = 0
    if lines is not None:
        lines = lines.tolist()
        lines.sort(key=lambda x: x[0][1])
        print(len(lines))
        lines = deletelines(lines)

        for line in lines:

            if line[0][0] == line[0][2]:
                theta = 90
            else:
                theta = slope(line)
            # print(theta)
            if theta < 10:
                cv2.line(img, (line[0][0], line[0][1]),
                         (line[0][2], line[0][3]), (0, 255, 0), 2)
                val += 1
        print(val)

        # cv2.imshow("Sobel",sobel)
        # cv2.imshow("Canny",canny)
        # cv2.waitKey(0)

        return lines