當前位置: 首頁>>代碼示例>>Python>>正文


Python cv2.fitLine方法代碼示例

本文整理匯總了Python中cv2.fitLine方法的典型用法代碼示例。如果您正苦於以下問題:Python cv2.fitLine方法的具體用法?Python cv2.fitLine怎麽用?Python cv2.fitLine使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在cv2的用法示例。


在下文中一共展示了cv2.fitLine方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: update

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import fitLine [as 別名]
def update(_=None):
    noise = cv2.getTrackbarPos('noise', 'fit line')
    n = cv2.getTrackbarPos('point n', 'fit line')
    r = cv2.getTrackbarPos('outlier %', 'fit line') / 100.0
    outn = int(n*r)

    p0, p1 = (90, 80), (w-90, h-80)
    img = np.zeros((h, w, 3), np.uint8)
    cv2.line(img, toint(p0), toint(p1), (0, 255, 0))

    if n > 0:
        line_points = sample_line(p0, p1, n-outn, noise)
        outliers = np.random.rand(outn, 2) * (w, h)
        points = np.vstack([line_points, outliers])
        for p in line_points:
            cv2.circle(img, toint(p), 2, (255, 255, 255), -1)
        for p in outliers:
            cv2.circle(img, toint(p), 2, (64, 64, 255), -1)
        func = getattr(cv2, cur_func_name)
        vx, vy, cx, cy = cv2.fitLine(np.float32(points), func, 0, 0.01, 0.01)
        cv2.line(img, (int(cx-vx*w), int(cy-vy*w)), (int(cx+vx*w), int(cy+vy*w)), (0, 0, 255))

    draw_str(img, (20, 20), cur_func_name)
    cv2.imshow('fit line', img) 
開發者ID:makelove,項目名稱:OpenCV-Python-Tutorial,代碼行數:26,代碼來源:fitline.py

示例2: filterCornersLine

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import fitLine [as 別名]
def filterCornersLine(corners, rows, cols):
    [vx, vy, x, y] = cv2.fitLine(corners, cv.CV_DIST_HUBER, 0, 0.1, 0.1)
    lefty = int((-x * vy / vx) + y)
    righty = int(((cols - x) * vy / vx) + y)

    cornerdata = []
    tt = 0
    for i in corners:
        xl, yl = i.ravel()
        # check distance to fitted line, only draw corners within certain range
        distance = dist(0, lefty, cols - 1, righty, xl, yl)
        if distance > 40:  ## threshold important -> make accessible
            cornerdata.append(tt)

        tt += 1

    corners_final = np.delete(corners, [cornerdata], axis=0)  # delete corners to form new array

    return corners_final 
開發者ID:hanneshoettinger,項目名稱:opencv-steel-darts,代碼行數:21,代碼來源:DartsRecognition.py

示例3: update

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import fitLine [as 別名]
def update(_=None):
    noise = cv2.getTrackbarPos('noise', 'fit line')
    n = cv2.getTrackbarPos('point n', 'fit line')
    r = cv2.getTrackbarPos('outlier %', 'fit line') / 100.0
    outn = int(n*r)

    p0, p1 = (90, 80), (w-90, h-80)
    img = np.zeros((h, w, 3), np.uint8)
    cv2.line(img, toint(p0), toint(p1), (0, 255, 0))

    if n > 0:
        line_points = sample_line(p0, p1, n-outn, noise)
        outliers = np.random.rand(outn, 2) * (w, h)
        points = np.vstack([line_points, outliers])
        for p in line_points:
            cv2.circle(img, toint(p), 2, (255, 255, 255), -1)
        for p in outliers:
            cv2.circle(img, toint(p), 2, (64, 64, 255), -1)
        func = getattr(cv2.cv, cur_func_name)
        vx, vy, cx, cy = cv2.fitLine(np.float32(points), func, 0, 0.01, 0.01)
        cv2.line(img, (int(cx-vx*w), int(cy-vy*w)), (int(cx+vx*w), int(cy+vy*w)), (0, 0, 255))

    draw_str(img, (20, 20), cur_func_name)
    cv2.imshow('fit line', img) 
開發者ID:fatcloud,項目名稱:PyCV-time,代碼行數:26,代碼來源:fitline.py

示例4: fitLine_ransac

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import fitLine [as 別名]
def fitLine_ransac(pts,zero_add = 0 ):
    if len(pts)>=2:
        [vx, vy, x, y] = cv2.fitLine(pts, cv2.DIST_HUBER, 0, 0.01, 0.01)
        lefty = int((-x * vy / vx) + y)
        righty = int(((136- x) * vy / vx) + y)
        return lefty+30+zero_add,righty+30+zero_add
    return 0,0



#精定位算法 
開發者ID:fanghon,項目名稱:lpr,代碼行數:13,代碼來源:finemapping.py

示例5: ransac_linefit_opencv

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import fitLine [as 別名]
def ransac_linefit_opencv(points):
        """
        Use opencv fitline function to fit the line
        :param points:
        :return: line [vx, vy, x, y] vx, vy represent the direction x, y represent the origin position
        """
        line = cv2.fitLine(points=points, distType=cv2.DIST_WELSCH, param=0, reps=0.01, aeps=0.01)
        return line 
開發者ID:MaybeShewill-CV,項目名稱:DVCNN_Lane_Detection,代碼行數:10,代碼來源:ransac_fitline.py

示例6: getOrientation

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import fitLine [as 別名]
def getOrientation(frame, config):

    th_val = 1

    ret, binary_img = cv2.threshold(frame, th_val, 255, cv2.THRESH_BINARY)
    contours, hierarchy = cv2.findContours(binary_img, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)[-2:]


    # Sort contours by area
    contours.sort(key=lambda ar: cv2.contourArea(ar))

    largest_contour = contours[-1]

    [vx, vy, x, y] = cv2.fitLine(largest_contour, cv2.DIST_L2, 0, 0.01, 0.01)
    line_angle = math.atan2(vy, vx)
    line_angle_degrees = math.degrees(line_angle)

    angle = line_angle_degrees + 90

    x, y, w, h = cv2.boundingRect(largest_contour)

    img_cropped = frame[y:y+h, x:x+w]

    rotated_img, actual_angle = rotateFishImage(img_cropped, angle, config)

    return rotated_img, actual_angle 
開發者ID:ver228,項目名稱:tierpsy-tracker,代碼行數:28,代碼來源:zebrafishAnalysis.py


注:本文中的cv2.fitLine方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。