本文整理汇总了Python中line.Line.intersection方法的典型用法代码示例。如果您正苦于以下问题:Python Line.intersection方法的具体用法?Python Line.intersection怎么用?Python Line.intersection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类line.Line
的用法示例。
在下文中一共展示了Line.intersection方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_intersect_edge
# 需要导入模块: from line import Line [as 别名]
# 或者: from line.Line import intersection [as 别名]
def test_intersect_edge(self):
l1 = Line(Point([0,0]), Point([10, 0]))
l2 = Line(Point([0, 0]), Point([5, 5]))
p = l1.intersection(l2)
self.assertEqual(p.vec, [0.0, 0.0, 1.0])
示例2: test_intersect_parallel
# 需要导入模块: from line import Line [as 别名]
# 或者: from line.Line import intersection [as 别名]
def test_intersect_parallel(self):
l1 = Line(Point([0,0]), Point([10, 0]))
l2 = Line(Point([0, 5]), Point([5, 5]))
p = l1.intersection(l2)
self.assertEqual(p, False)
示例3: test_problems
# 需要导入模块: from line import Line [as 别名]
# 或者: from line.Line import intersection [as 别名]
def test_problems(self):
l1 = Line(Vector([4.046, 2.836]), 1.21)
l2 = Line(Vector([10.115, 7.09]), 3.025)
self.assertTrue(l1.__eq__(l2))
self.assertEquals(None, l1.intersection(l2))
l1 = Line(Vector([7.204, 3.182]), 8.68)
l2 = Line(Vector([8.172, 4.114]), 9.883)
self.assertEquals((dec('1.17277663546464155833736023125'), dec('0.0726955116633319428771277112348')),
l1.intersection(l2).coordinates)
self.assertFalse(l1.__eq__(l2))
l1 = Line(Vector([1.182, 5.562]), 6.744)
l2 = Line(Vector([1.773, 8.343]), 9.525)
self.assertEquals(None, l1.intersection(l2))
self.assertFalse(l1.__eq__(l2))
示例4: generate_extremas
# 需要导入模块: from line import Line [as 别名]
# 或者: from line.Line import intersection [as 别名]
def generate_extremas(self, polygon, y):
extremas = []
scan_line = Line(Point([self.canvas.xmin, y]), Point([self.canvas.xmax, y]))
for edge in polygon.lines:
if edge.horizontal():
continue
if y == edge.highest():
continue
if y >= edge.lowest() and y < edge.highest():
p = scan_line.intersection(edge)
if p == False:
continue # lines are parallel
extremas.append(p)
return extremas
示例5: detect_lanes
# 需要导入模块: from line import Line [as 别名]
# 或者: from line.Line import intersection [as 别名]
def detect_lanes(cv_image, left_search_strips, right_search_strips):
'''
Detects lanes in the specified image based on the specified search strips. The first
argument is a OpenCV image. The second and third arguments are the left and right
lane search strip sets respectively. The function returns a 4-tuple. The first item
in the tuple is a Boolean that is True if the lanes were found and False otherwise.
If the found flag is False, the rest of the tuple items are undefined. The second
and third items in the return tuple are Line objects representing the image line of
the left and right lanes respectively. The last item in the return tuple is a
column vector of NumPy matrix type of length 2 that represents the location of the
vanishing point.
'''
# turn canny detector knobs
low_threshold = 100
ratio = 3
# apply the canny edge detector
canny_image = cv2.Canny(cv_image, low_threshold, low_threshold*ratio)
# find the intersections between the search strips and the edges from the canny
# detector
left_lane_points = find_lane_points(canny_image, left_search_strips, 'left')
right_lane_points = find_lane_points(canny_image, right_search_strips, 'right')
# fit line models to the intersections found
left_lane_line = ransac_line2d(left_lane_points)
right_lane_line = ransac_line2d(right_lane_points)
# if either of the lane lines cannot be found, return failure
if left_lane_line == None or right_lane_line == None:
return False, left_lane_line, right_lane_line, None
# find the vanishing point
vanishing_point = Line.intersection(left_lane_line, right_lane_line)
return True, left_lane_line, right_lane_line, vanishing_point
示例6: hw4_lane_pose_estimation
# 需要导入模块: from line import Line [as 别名]
# 或者: from line.Line import intersection [as 别名]
def hw4_lane_pose_estimation():
'''
TODO DOCUMENTATION
'''
image_paths = ['LDWS_test/LDWS_test_data {0:03}.bmp'.format(x) for x in range(1, 609)]
intrinsic_matrix, distortion_coefficients = intrinsic_calibration.hw4_calibration(False)
left_search_strips, right_search_strips = lane_detection.define_hw4_search_strips()
cv2.namedWindow('display')
for image_path in image_paths:
cv_image = cv2.imread(image_path)
lanes_found, left_lane_line, right_lane_line, vanishing_point = \
lane_detection.detect_lanes(
cv_image,
left_search_strips,
right_search_strips,
)
display_image = cv_image
if lanes_found:
vanishing_point_pixels = tuple2inttuple(colvec2tuple(vanishing_point))
cv2.circle(display_image, vanishing_point_pixels, 10, (255, 255, 255))
bottom_image_line = Line(np.matrix([[0],[480]]), np.matrix([[1],[0]]))
bottom_left = Line.intersection(left_lane_line, bottom_image_line)
bottom_right = Line.intersection(right_lane_line, bottom_image_line)
bottom_left_pixels = tuple2inttuple(colvec2tuple(bottom_left))
bottom_right_pixels = tuple2inttuple(colvec2tuple(bottom_right))
cv2.circle(display_image, bottom_left_pixels, 10, (0, 0, 255))
cv2.circle(display_image, bottom_right_pixels, 10, (255, 0, 0))
almost_bottom_image_line = Line(np.matrix([[0],[480-150]]), np.matrix([[1],[0]]))
almost_bottom_left = Line.intersection(left_lane_line, almost_bottom_image_line)
almost_bottom_right = Line.intersection(right_lane_line, almost_bottom_image_line)
almost_bottom_left_pixels = tuple2inttuple(colvec2tuple(almost_bottom_left))
almost_bottom_right_pixels = tuple2inttuple(colvec2tuple(almost_bottom_right))
cv2.circle(display_image, almost_bottom_left_pixels, 10, (0, 0, 255))
cv2.circle(display_image, almost_bottom_right_pixels, 10, (255, 0, 0))
cv2.line(display_image, vanishing_point_pixels, bottom_left_pixels, (255, 0, 255), 1, cv2.CV_AA)
cv2.line(display_image, vanishing_point_pixels, bottom_right_pixels, (255, 0, 255), 1, cv2.CV_AA)
object_points = np.array([
[-1.6, 0, 0],
[1.6, 0, 0],
[-1.6, 4.0, 0],
[1.6, 4.0, 0],
])
image_points = np.array([
bottom_left.T.A[0],
bottom_right.T.A[0],
almost_bottom_left.T.A[0],
almost_bottom_right.T.A[0],
])
solve_pnp_results = cv2.solvePnP(
object_points,
image_points,
intrinsic_matrix,
distortion_coefficients,
)
pnp_success, rotation_omega, translate = solve_pnp_results
horizontal_drift = -translate[0][0]
print(horizontal_drift)
cv2.line(display_image, (320-80, 10), (320+80, 10), (0, 0, 0), 1, cv2.CV_AA)
cv2.line(display_image, (320-80, 10), (320-80, 50), (0, 0, 0), 1, cv2.CV_AA)
cv2.line(display_image, (320+80, 10), (320+80, 50), (0, 0, 0), 1, cv2.CV_AA)
cv2.line(display_image, (320-80, 50), (320+80, 50), (0, 0, 0), 1, cv2.CV_AA)
cv2.line(display_image, (320+int(40*horizontal_drift/0.4), 30), (320+int(40*horizontal_drift/0.4), 50), (0, 0, 0), 1, cv2.CV_AA)
cv2.imshow('display', display_image)
cv2.waitKey(1)
示例7: test_intersection
# 需要导入模块: from line import Line [as 别名]
# 或者: from line.Line import intersection [as 别名]
def test_intersection(self):
l1 = Line(Vector([1, 2]), 3)
l2 = Line(Vector([1, -1]), 2)
self.assertEquals(((dec(7)/dec(3)), (dec(1)/dec(3))), l1.intersection(l2).coordinates)
self.assertEquals(((dec(7)/dec(3)), (dec(1)/dec(3))), l2.intersection(l1).coordinates)