本文整理汇总了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)
示例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
示例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)
示例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
#精定位算法
示例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
示例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