当前位置: 首页>>代码示例>>Python>>正文


Python cv2.HoughLinesP方法代码示例

本文整理汇总了Python中cv2.HoughLinesP方法的典型用法代码示例。如果您正苦于以下问题:Python cv2.HoughLinesP方法的具体用法?Python cv2.HoughLinesP怎么用?Python cv2.HoughLinesP使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cv2的用法示例。


在下文中一共展示了cv2.HoughLinesP方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: sim_noise

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import HoughLinesP [as 别名]
def sim_noise(self, depthFile, rgbFile):
		img=depthFile
		imgcol=rgbFile

		edges = cv2.Canny(img,100,200,apertureSize = 3)
		edgescol = cv2.Canny(imgcol,100,200,apertureSize = 3)
		edges += edgescol

		mask=img.copy()
		mask.fill(0)
		minLineLength = 10
		maxLineGap = 10
		lines = cv2.HoughLinesP(edges,1,np.pi/180,20,100,10)
		if lines is not None:
			for line in lines:
				for x1,y1,x2,y2 in line:
					cv2.line(mask,(x1,y1),(x2,y2),255,1)

			for i in range(480):
				for j in range(640):
					if mask[i][j]>0:
						cv2.circle(img,(j,i),2, (0,0,0), -1)
						if random.random()>0.8:
							cv2.circle(img,(j,i), random.randint(2,6), (0,0,0), -1)
		return img 
开发者ID:xie9187,项目名称:Monocular-Obstacle-Avoidance,代码行数:27,代码来源:RealWorld.py

示例2: FindInternalBox

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import HoughLinesP [as 别名]
def FindInternalBox(bw):
  """Finds where the puzzle card is located.

  Detects all vertical and horizontal lines, and returns the largest
  contour that bounds them"""

  # Invert colors. HoughLines searches white lines on black background
  target = 255 - bw.copy()
  DebugShow(target)

  lines = cv2.HoughLinesP(target, 1, np.pi / 180, 100, 100, 10)
  if lines is None:
    logging.debug("HoughLinesP failed")
    return None

  logging.debug("Found {} lines using HoughLinesP".format(len(lines)))

  lines_image = np.zeros_like(target)
  for line in lines:
    for x1, y1, x2, y2 in line:
      if abs(x1 - x2) < 20:
        # vertical line
        x = min(x1, x2)
        cv2.line(lines_image, (x, y1), (x, y2), 255, 0)
      if abs(y1 - y2) < 20:
        y = min(y1, y2)
        cv2.line(lines_image, (x1, y), (x2, y), 255, 0)

  kernel = np.ones((5, 5), np.uint8)
  lines_image = cv2.dilate(lines_image, kernel, iterations=2)
  DebugShow(lines_image)

  return FindExternalContour(lines_image) 
开发者ID:cfircohen,项目名称:airport,代码行数:35,代码来源:solver.py

示例3: lines

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import HoughLinesP [as 别名]
def lines(self):
        lines = cv2.HoughLinesP(self.image, 1, np.pi / 2, 6, None, 50, 10)
        for line in lines[0]:
            pt1 = (line[0], line[1])
            pt2 = (line[2], line[3])
            cv2.line(self.image, pt1, pt2, (0, 0, 255), 2) 
开发者ID:makelove,项目名称:OpenCV-Python-Tutorial,代码行数:8,代码来源:检测线条和形状-几何形状.py

示例4: line_detect_possible_demo

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import HoughLinesP [as 别名]
def line_detect_possible_demo(image):
    global img
    # 提取图片中黄色区域(hsv空间)
    lower_blue = np.array([26, 43, 46])
    upper_blue = np.array([34, 255, 255])
    frame = image
    # cv2.imshow('Capture', frame)
    # change to hsv model
    hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
    # get mask
    mask = cv2.inRange(hsv, lower_blue, upper_blue)
    # detect red
    res = cv2.bitwise_and(frame, frame, mask=mask)
    ret, binary = cv2.threshold(res, 200, 255, cv2.THRESH_BINARY)
    kernel = np.ones((5, 5), np.uint8)
    # 图像进行膨胀处理
    dilation = cv2.dilate(binary, kernel)
    # 图像腐蚀处理
    erosion = cv2.erode(dilation, kernel)
    erosion = cv2.cvtColor(erosion, cv2.COLOR_BGR2GRAY)
    edges = cv2.Canny(erosion, 100, 150, apertureSize=3)
    #edges = cv2.Canny(binary, 50, 150, apertureSize=3)  # apertureSize是sobel算子大小,只能为1,3,5,7
    # cv2.imshow('1',edges)
    # cv2.waitKey(0)
    lines = cv2.HoughLinesP(edges, 1, np.pi / 180, 100, minLineLength=0,maxLineGap=10)  #函数将通过步长为1的半径和步长为π/180的角来搜索所有可能的直线
    list= []
    for i in range(len(lines)):
        x1 = lines[i][0][0]
        y1 = lines[i][0][1]
        x2 = lines[i][0][2]
        y2 = lines[i][0][3]
        list.append((x1,y1,x2,y2))
        cv2.line(image,(x1,y1),(x2,y2),(0,0,255),2)
    return list 
开发者ID:lyk19940625,项目名称:WorkControl,代码行数:36,代码来源:transboundary.py

示例5: crop_point_hough

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import HoughLinesP [as 别名]
def crop_point_hough(crop_points):
    
    height = len(crop_points)
    width = len(crop_points[0])
    
    #crop_line_data = cv2.HoughLinesP(crop_points, 1, math.pi/180, 2, 10, 10)
    crop_line_data = cv2.HoughLines(crop_points, HOUGH_RHO, HOUGH_ANGLE, HOUGH_THRESH)
    
    crop_lines = np.zeros((height, width, 3), dtype=np.uint8)
    
    if crop_line_data != None:
        crop_line_data = crop_line_data[0]
        #print(crop_line_data)
        
        if len(crop_line_data[0]) == 2:
            for [rho, theta] in crop_line_data:
                #print(rho, theta)
                if (theta <= ANGLE_THRESH) or (theta >= math.pi-ANGLE_THRESH):
                    a = math.cos(theta)
                    b = math.sin(theta)
                    x0 = a*rho
                    y0 = b*rho
                    point1 = (int(round(x0+1000*(-b))), int(round(y0+1000*(a))))
                    point2 = (int(round(x0-1000*(-b))), int(round(y0-1000*(a))))
                    cv2.line(crop_lines, point1, point2, (0, 0, 255), 2)
                
        elif len(crop_line_data[0]) == 4:
            for [x0, y0, x1, y1] in crop_line_data:
                cv2.line(crop_lines, (x0, y0), (x1, y1), (0, 0, 255), 2)
    else:
        print("No lines found")
    
    return crop_lines 
开发者ID:petern3,项目名称:crop_row_detection,代码行数:35,代码来源:line_detect_1.py

示例6: process_img

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import HoughLinesP [as 别名]
def process_img(image):
    original_image = image
    # convert to gray
    processed_img = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    # edge detection
    processed_img =  cv2.Canny(processed_img, threshold1 = 200, threshold2=300)
    
    processed_img = cv2.GaussianBlur(processed_img,(5,5),0)
    
    vertices = np.array([[10,500],[10,300],[300,200],[500,200],[800,300],[800,500],
                         ], np.int32)

    processed_img = roi(processed_img, [vertices])

    # more info: http://docs.opencv.org/3.0-beta/doc/py_tutorials/py_imgproc/py_houghlines/py_houghlines.html
    #                                     rho   theta   thresh  min length, max gap:        
    lines = cv2.HoughLinesP(processed_img, 1, np.pi/180, 180,      20,       15)
    try:
        l1, l2 = draw_lanes(original_image,lines)
        cv2.line(original_image, (l1[0], l1[1]), (l1[2], l1[3]), [0,255,0], 30)
        cv2.line(original_image, (l2[0], l2[1]), (l2[2], l2[3]), [0,255,0], 30)
    except Exception as e:
        print(str(e))
        pass
    try:
        for coords in lines:
            coords = coords[0]
            try:
                cv2.line(processed_img, (coords[0], coords[1]), (coords[2], coords[3]), [255,0,0], 3)
                
                
            except Exception as e:
                print(str(e))
    except Exception as e:
        pass

    return processed_img,original_image 
开发者ID:Sentdex,项目名称:pygta5,代码行数:39,代码来源:part-6-lane-finder.py

示例7: process_img

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import HoughLinesP [as 别名]
def process_img(image):
    original_image = image
    # convert to gray
    processed_img = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    # edge detection
    processed_img =  cv2.Canny(processed_img, threshold1 = 200, threshold2=300)
    
    processed_img = cv2.GaussianBlur(processed_img,(5,5),0)
    
    vertices = np.array([[10,500],[10,300],[300,200],[500,200],[800,300],[800,500],
                         ], np.int32)

    processed_img = roi(processed_img, [vertices])

    # more info: http://docs.opencv.org/3.0-beta/doc/py_tutorials/py_imgproc/py_houghlines/py_houghlines.html
    #                                     rho   theta   thresh  min length, max gap:        
    lines = cv2.HoughLinesP(processed_img, 1, np.pi/180, 180,      20,       15)
    m1 = 0
    m2 = 0
    try:
        l1, l2, m1,m2 = draw_lanes(original_image,lines)
        cv2.line(original_image, (l1[0], l1[1]), (l1[2], l1[3]), [0,255,0], 30)
        cv2.line(original_image, (l2[0], l2[1]), (l2[2], l2[3]), [0,255,0], 30)
    except Exception as e:
        print(str(e))
        pass
    try:
        for coords in lines:
            coords = coords[0]
            try:
                cv2.line(processed_img, (coords[0], coords[1]), (coords[2], coords[3]), [255,0,0], 3)
                
                
            except Exception as e:
                print(str(e))
    except Exception as e:
        pass

    return processed_img,original_image, m1, m2 
开发者ID:Sentdex,项目名称:pygta5,代码行数:41,代码来源:main.py

示例8: process_img

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import HoughLinesP [as 别名]
def process_img(original_image):
    processed_img = cv2.cvtColor(original_image, cv2.COLOR_BGR2GRAY)
    processed_img = cv2.Canny(processed_img, threshold1=200, threshold2=300)
    processed_img = cv2.GaussianBlur(processed_img, (3,3), 0 )
    vertices = np.array([[10,500],[10,300], [300,200], [500,200], [800,300], [800,500]], np.int32)
    processed_img = roi(processed_img, [vertices])

    #                       edges
    lines = cv2.HoughLinesP(processed_img, 1, np.pi/180, 180, 20, 15)
    draw_lines(processed_img,lines)
    return processed_img 
开发者ID:Sentdex,项目名称:pygta5,代码行数:13,代码来源:part-5-line-finding.py

示例9: process_img

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import HoughLinesP [as 别名]
def process_img(image):
    original_image = image
    # edge detection
    processed_img =  cv2.Canny(image, threshold1 = 200, threshold2=300)
    
    processed_img = cv2.GaussianBlur(processed_img,(5,5),0)
    
    vertices = np.array([[10,500],[10,300],[300,200],[500,200],[800,300],[800,500],
                         ], np.int32)

    processed_img = roi(processed_img, [vertices])

    # more info: http://docs.opencv.org/3.0-beta/doc/py_tutorials/py_imgproc/py_houghlines/py_houghlines.html
    #                                     rho   theta   thresh  min length, max gap:        
    lines = cv2.HoughLinesP(processed_img, 1, np.pi/180, 180,      20,       15)
    m1 = 0
    m2 = 0
    try:
        l1, l2, m1,m2 = draw_lanes(original_image,lines)
        cv2.line(original_image, (l1[0], l1[1]), (l1[2], l1[3]), [0,255,0], 30)
        cv2.line(original_image, (l2[0], l2[1]), (l2[2], l2[3]), [0,255,0], 30)
    except Exception as e:
        print(str(e))
        pass
    try:
        for coords in lines:
            coords = coords[0]
            try:
                cv2.line(processed_img, (coords[0], coords[1]), (coords[2], coords[3]), [255,0,0], 3)
                
                
            except Exception as e:
                print(str(e))
    except Exception as e:
        pass

    return processed_img,original_image, m1, m2 
开发者ID:Sentdex,项目名称:pygta5,代码行数:39,代码来源:part-7-self-driving-example.py

示例10: remove_line

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import HoughLinesP [as 别名]
def remove_line(img):
    gray = img.copy()
    edges = cv2.Canny(gray,50,150,apertureSize = 3)
    minLineLength = 5
    maxLineGap = 3
    lines = cv2.HoughLinesP(edges,1,np.pi/180,15,minLineLength,maxLineGap)
    mask = np.ones(img.shape[:2], dtype="uint8") * 255
    if lines is not None:
        for line in lines:
            for x1,y1,x2,y2 in line:
                cv2.line(mask,(x1,y1),(x2,y2),(0,0,0),2)
    return cv2.bitwise_and(img, img, mask=mask) 
开发者ID:hoanglehaithanh,项目名称:Traffic-Sign-Detection,代码行数:14,代码来源:main.py

示例11: get_avg_angle

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import HoughLinesP [as 别名]
def get_avg_angle(a, draw=False):
    lines = cv.HoughLinesP(a,  1, np.pi/180, 1, minLineLength=a.shape[1]*.30, maxLineGap=50)
    angles = []
    if lines is not None:
        for line in lines[0]:
            if draw:
                
                cv.line(a, tuple(line[0:2]), tuple(line[2:]), 1, thickness=2)
            angle = np.arctan2(line[3]-line[1], line[2]-line[0])
            angles.append(angle)
        return np.mean(angles)*degree_scaler
    else:
        return 0 
开发者ID:zmr,项目名称:namsel,代码行数:15,代码来源:hough_rotate.py

示例12: draw_hough_outline

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import HoughLinesP [as 别名]
def draw_hough_outline(self, arr):
        
        arr = invert_bw(arr)
#         import Image
#         Image.fromarray(arr*255).show()
#        h = cv.HoughLinesP(arr, 2, np.pi/4, 5, minLineLength=arr.shape[0]*.10)
        h = cv.HoughLinesP(arr, 2, np.pi/4, 1, minLineLength=arr.shape[0]*.15, maxLineGap=5) #This
#         h = cv.HoughLinesP(arr, 2, np.pi/4, 1, minLineLength=arr.shape[0]*.15, maxLineGap=1)
#        h = cv.HoughLinesP(arr, 2, np.pi/4, 1, minLineLength=arr.shape[0]*.15)
        PI_O4 = np.pi/4
#        if h and h.any():
#        if self._page_type == 'pecha':
#            color = 1
#            thickness = 10
#        else: # Attempt to erase horizontal lines if page_type == book. 
#            # Why? Horizontal lines can break LineCluster if they are broken
#            # e.g. couldn't be filtered out prior to line_breaker.py
#            color = 0
#            thickness = 10
        if h is not None:
            for line in h[0]:
                new = (line[2]-line[0], line[3] - line[1])
                val = (new[0]/np.sqrt(np.dot(new, new)))
                theta = np.arccos(val)
                if theta >= PI_O4: # Vertical line
#                    print line[1] - line[3]
#                     cv.line(arr, (line[0], 0), (line[0], arr.shape[0]), 1, thickness=10)
                    if line[0] < .5*arr.shape[1]:
                        arr[:,:line[0]+12] = 0
                    else:
                        arr[:,line[0]-12:] = 0
                else: # horizontal line
                    if line[2] - line[0] >= .15 * arr.shape[1]:
#                         cv.line(arr, (0, line[1]), (arr.shape[1], line[1]), 1, thickness=50)
                        if line[1] < .5 *arr.shape[0]:
                            arr[:line[1]+17, :] = 0
                        else:
                            arr[line[1]-5:,:] = 0
        

        return ((arr*-1)+1).astype(np.uint8) 
开发者ID:zmr,项目名称:namsel,代码行数:43,代码来源:page_elements2.py

示例13: get_lane_lines

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import HoughLinesP [as 别名]
def get_lane_lines(inframe):
    frame = inframe.copy()
    ret_frame = np.zeros(frame.shape, np.uint8)

    # We converted it into RGB when we normalized it
    gray = cv2.cvtColor(frame, cv2.COLOR_RGB2GRAY)

    gray = get_median_blur(gray)
    canny = get_canny(gray)

    # Hough lines
    # threshold = number of 'votes' before hough algorithm considers it a line
    lines = cv2.HoughLinesP(canny, 1, np.pi/180, threshold=25, minLineLength=40, maxLineGap=100)

    try:
        r = lines.shape[0]
    except AttributeError:
        r = 0

    for i in range(0):
        for x1, y1, x2, y2 in lines[i]:
            # Degrees as its easier for me to conceptualize
            angle = math.atan2(y1-y2, x1-x2)*180/np.pi

            # If it looks like a left or right lane
            # Draw it onto the new image
            if 100 < angle < 170 or -170 < angle < -100:
                cv2.line(ret_frame, (x1, y1), (x2, y2), (255, 255, 255), 10)

    return ret_frame 
开发者ID:kendricktan,项目名称:suiron,代码行数:32,代码来源:SuironCV.py

示例14: hough_lines

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import HoughLinesP [as 别名]
def hough_lines(image):
    """
    Creates hough line
    Note that: `image` should be the output of a Canny transform.
    :param image: |Image| camera frame
    :return: hough lines (not the image with lines)
    """
    return cv2.HoughLinesP(image, 2, np.pi / 180, 50, maxLineGap=50) 
开发者ID:movidius,项目名称:ncappzoo,代码行数:10,代码来源:lane_detector.py

示例15: houghLines

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import HoughLinesP [as 别名]
def houghLines(self, edges, image, debug=True):
        """
        Detects Hough lines
        """

        # Detect hough lines
        lines = cv2.HoughLinesP(edges, rho=1, theta=1 * np.pi / 180, threshold=40, minLineLength=100, maxLineGap=50)
        N = lines.shape[0]

        # Draw lines on image
        New = []
        for i in range(N):
            x1 = lines[i][0][0]
            y1 = lines[i][0][1]
            x2 = lines[i][0][2]
            y2 = lines[i][0][3]

            New.append([x1,y1,x2,y2])

        lines = [Line(x1=New[i][0],y1= New[i][1], x2= New[i][2], y2=New[i][3]) for i in range(len(New))]

        # Categorise the lines into horizontal or vertical
        horizontal, vertical = self.categoriseLines(lines)
        # Filter out close lines based to achieve 9

        # STANDARD THRESHOLD SHOULD BE 20
        ver = filterClose(vertical, horizontal=False, threshold=20)
        hor = filterClose(horizontal, horizontal=True, threshold=20)
        #print(len(ver))
        #print(len(hor))
        # DEBUG TO SHOW LINES
        if debug:
            debugImg = image.copy()
            self.drawLines(debugImg, ver)
            self.drawLines(debugImg, hor)
            #cv2.imshow("2 Hough Lines Found", debugImg)
            cv2.imwrite("2HoughLinesFound.jpeg", debugImg)


        return hor, ver 
开发者ID:nebbles,项目名称:DE3-ROB1-CHESS,代码行数:42,代码来源:mainDetect.py


注:本文中的cv2.HoughLinesP方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。