• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python transform.hough_line_peaks函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中skimage.transform.hough_line_peaks函数的典型用法代码示例。如果您正苦于以下问题:Python hough_line_peaks函数的具体用法?Python hough_line_peaks怎么用?Python hough_line_peaks使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: test_hough_line_peaks_dist

def test_hough_line_peaks_dist():
    img = np.zeros((100, 100), dtype=np.bool_)
    img[:, 30] = True
    img[:, 40] = True
    hspace, angles, dists = tf.hough_line(img)
    assert len(tf.hough_line_peaks(hspace, angles, dists, min_distance=5)[0]) == 2
    assert len(tf.hough_line_peaks(hspace, angles, dists, min_distance=15)[0]) == 1
开发者ID:ChrisBeaumont,项目名称:scikit-image,代码行数:7,代码来源:test_hough_transform.py


示例2: test_hough_line_peaks_dist

def test_hough_line_peaks_dist():
    img = np.zeros((100, 100), dtype=np.bool_)
    img[:, 30] = True
    img[:, 40] = True
    hspace, angles, dists = tf.hough_line(img)
    with expected_warnings(['`background`']):
        assert len(tf.hough_line_peaks(hspace, angles, dists,
                                       min_distance=5)[0]) == 2
        assert len(tf.hough_line_peaks(hspace, angles, dists,
                                       min_distance=15)[0]) == 1
开发者ID:MartinSavc,项目名称:scikit-image,代码行数:10,代码来源:test_hough_transform.py


示例3: calculate

 def calculate(self, image: np.ndarray, disk_size: int=9,
               mean_threshold: int=100, min_object_size: int=750) -> float:
     # Find edges that have a strong vertical direction
     vertical_edges = sobel_v(image)
     # Separate out the areas where there is a large amount of vertically-oriented stuff
     segmentation = self._segment_edge_areas(vertical_edges, disk_size, mean_threshold, min_object_size)
     # Draw a line that follows the center of the segments at each point, which should be roughly vertical
     # We should expect this to give us four approximately-vertical lines, possibly with many gaps in
     # each line
     skeletons = skeletonize(segmentation)
     # Use the Hough transform to get the closest lines that approximate those four lines
     hough = transform.hough_line(skeletons, np.arange(-constants.FIFTEEN_DEGREES_IN_RADIANS,
                                                       constants.FIFTEEN_DEGREES_IN_RADIANS,
                                                       0.0001))
     # Create a list of the angles (in radians) of all of the lines the Hough transform produced, with 0.0
     # being completely vertical
     # These angles correspond to the angles of the four sides of the channels, which we need to
     # correct for
     angles = [angle for _, angle, dist in zip(*transform.hough_line_peaks(*hough))]
     if not angles:
         raise ValueError("Image rotation could not be calculated. Check the images to see if they're weird.")
     else:
         # Get the average angle and convert it to degrees
         offset = sum(angles) / len(angles) * 180.0 / math.pi
         if offset > constants.ACCEPTABLE_SKEW_THRESHOLD:
             log.warn("Image is heavily skewed. Check that the images are valid.")
         return offset
开发者ID:jimrybarski,项目名称:fylm_critic,代码行数:27,代码来源:rotate.py


示例4: test_hough_line_peaks_zero_input

def test_hough_line_peaks_zero_input():
    # Test to make sure empty input doesn't cause a failure
    img = np.zeros((100, 100), dtype='uint8')
    theta = np.linspace(0, np.pi, 100)
    hspace, angles, dists = transform.hough_line(img, theta)
    h, a, d = transform.hough_line_peaks(hspace, angles, dists)
    assert_equal(a, np.array([]))
开发者ID:Cadair,项目名称:scikit-image,代码行数:7,代码来源:test_hough_transform.py


示例5: calculate_rotation

def calculate_rotation(image):
    # sometimes we snag corners, by cropping the left and right 10% of the image we focus only on the
    # vertical bars formed by the structure
    height, width = image.shape
    crop = int(width * 0.1)
    cropped_image = image[:, crop: width - crop]
    # Find edges that have a strong vertical direction
    vertical_edges = sobel_v(cropped_image)
    # Separate out the areas where there is a large amount of vertically-oriented stuff
    segmentation = segment_edge_areas(vertical_edges)
    # Draw a line that follows the center of the segments at each point, which should be roughly vertical
    # We should expect this to give us four approximately-vertical lines, possibly with many gaps in
    # each line
    skeletons = skeletonize(segmentation)
    # Use the Hough transform to get the closest lines that approximate those four lines
    hough = transform.hough_line(skeletons, np.arange(-constants.FIFTEEN_DEGREES_IN_RADIANS,
                                                      constants.FIFTEEN_DEGREES_IN_RADIANS,
                                                      0.0001))
    # Create a list of the angles (in radians) of all of the lines the Hough transform produced, with 0.0
    # being completely vertical
    # These angles correspond to the angles of the four sides of the channels, which we need to
    # correct for
    angles = [angle for _, angle, dist in zip(*transform.hough_line_peaks(*hough))]
    if not angles:
        raise ValueError("Image rotation could not be calculated. Check the images to see if they're weird.")
    else:
        # Get the average angle and convert it to degrees
        offset = sum(angles) / len(angles) * 180.0 / math.pi
        if offset > constants.ACCEPTABLE_SKEW_THRESHOLD:
            log.warn("Image is heavily skewed. Check that the images are valid.")
        return offset
开发者ID:jimrybarski,项目名称:fylm_critic,代码行数:31,代码来源:tiff_to_hdf5.py


示例6: removeChessboard

def removeChessboard(img):

    # Get the major lines in the image
    edges, dilatedEdges, (h, theta, d) = findLines(img)

    # Create image with ones to fill inn lines
    lines = np.ones(img.shape[:2])

    # Add lines to image as zeroes
    for _, angle, dist in zip(*hough_line_peaks(h, theta, d)):
        y0 = (dist - 0 * np.cos(angle)) / np.sin(angle)
        y1 = (dist - img.shape[1] * np.cos(angle)) / np.sin(angle)
        x, y = line(int(y1), 0, int(y0), img.shape[1] - 1)
        x = np.clip(x, 0, img.shape[0] - 1)
        y = np.clip(y, 0, img.shape[1] - 1)
        lines[x, y] = 0

    # Remove border edges from image with all edges
    w = 4
    edges = np.pad(edges[w:img.shape[0] - w, w:img.shape[1] - w], w, mode='constant')

    # Erode the lines bigger, such that they cover the original lines
    lines = erosion(lines, square(13))

    # Remove major lines and close shape paths
    removedChessboard = closing(edges * lines, square(8))

    return removedChessboard
开发者ID:niklasmh,项目名称:ntnu,代码行数:28,代码来源:task5a.py


示例7: test_hough_line_peaks_num

def test_hough_line_peaks_num():
    img = np.zeros((100, 100), dtype=np.bool_)
    img[:, 30] = True
    img[:, 40] = True
    hspace, angles, dists = transform.hough_line(img)
    assert len(transform.hough_line_peaks(hspace, angles, dists,
                                          min_distance=0, min_angle=0,
                                          num_peaks=1)[0]) == 1
开发者ID:Cadair,项目名称:scikit-image,代码行数:8,代码来源:test_hough_transform.py


示例8: align_with_boarder

def align_with_boarder(image, sigma=1):

    edges = ft.canny(image, sigma=sigma)
    # edges = abs(fil.sobel_v(image))

    h, theta, d = tf.hough_line(edges)

    a, rot_angle, c = tf.hough_line_peaks(h, theta, d, min_distance=0)
    image = rotate(image, np.rad2deg(rot_angle[0]))

    return image
开发者ID:MK8J,项目名称:PV_analysis,代码行数:11,代码来源:util.py


示例9: test_ideal_tfr

 def test_ideal_tfr(self):
     """Test if the ideal TFR can be found using the instantaneous frequency
     laws."""
     _, iflaw1 = fmlin(128, 0.0, 0.2)
     _, iflaw2 = fmlin(128, 0.3, 0.5)
     iflaws = np.c_[iflaw1, iflaw2].T
     tfr, _, _ = pproc.ideal_tfr(iflaws)
     tfr[tfr == 1] = 255
     tfr = tfr.astype(np.uint8)
     hspace, angles, dists = hough_line(tfr)
     for x in hough_line_peaks(hspace, angles, dists):
         self.assertEqual(len(x), 2)
开发者ID:fmarrabal,项目名称:pytftb,代码行数:12,代码来源:test_postprocessing.py


示例10: test_hough_line_peaks

def test_hough_line_peaks():
    img = np.zeros((100, 150), dtype=int)
    rr, cc = line(60, 130, 80, 10)
    img[rr, cc] = 1

    out, angles, d = tf.hough_line(img)

    out, theta, dist = tf.hough_line_peaks(out, angles, d)

    assert_equal(len(dist), 1)
    assert_almost_equal(dist[0], 80.723, 1)
    assert_almost_equal(theta[0], 1.41, 1)
开发者ID:noahstier,项目名称:scikit-image,代码行数:12,代码来源:test_hough_transform.py


示例11: houghSides

def houghSides(bottle, edges, threshold, left):
    h, theta, d = hough_line(edges)
    accum = zip(*hough_line_peaks(h, theta, d))
    sortedAccum = sorted(accum, key=getKey, reverse=True)
    sortedAccumR = [sa for sa in sortedAccum if sa[2] > 200]
    sortedAccumL = [sa for sa in sortedAccum if sa[2] <= 200]

    if left:
        hpeak, angle, dist = sortedAccumL[0]
    else:
        hpeak, angle, dist in sortedAccumR[0]

    return (1, dist, angle)
开发者ID:rbjork,项目名称:RxShareFlask,代码行数:13,代码来源:rxshareserverskimage.py


示例12: test_hough_line_peaks_ordered

def test_hough_line_peaks_ordered():
    # Regression test per PR #1421
    testim = np.zeros((256, 64), dtype=np.bool)

    testim[50:100, 20] = True
    testim[85:200, 25] = True
    testim[15:35, 50] = True
    testim[1:-1, 58] = True

    hough_space, angles, dists = tf.hough_line(testim)

    hspace, _, _ = tf.hough_line_peaks(hough_space, angles, dists)
    assert hspace[0] > hspace[1]
开发者ID:noahstier,项目名称:scikit-image,代码行数:13,代码来源:test_hough_transform.py


示例13: check_door

def check_door(image, Pw_corners, Pi_corners, door_edges,
               required_matching_ratio=0.7, verbose=0):
    """Check if door is closed."""
    results = {}

    image_sobel, image_edges = detect_edges(image)

    # Detect lines with Hough transform
    hough_accumulator, angles, dists = hough_line(image_edges)
    hspace, angles, dists = hough_line_peaks(
        hough_accumulator, angles, dists, threshold=150.0)

    # Estimate camera transformation by minimizing the distance between
    # calibration points
    params = optimize_transform(camera_params, Pw_corners, Pi_corners)
    if verbose >= 1:
        print("Parameters: %s" % np.round(params, 3))
    cam2world = transform_from(matrix_from_euler_xyz(params[:3]), params[3:6])
    kappa = params[-1]

    W2I = partial(world2image, cam2world=cam2world, kappa=kappa,
                  **camera_params)

    # Get edge pixels in vicinity of lines
    Pi_line_points = check_edge_is_on_line(image_edges, angles, dists)

    if len(Pi_line_points) == 0:
        if verbose >= 1:
            print("No lines detected, assume that door is closed")
        door_closed = True
    else:
        # Check how good the edges of the door projected to the image match
        # detected edge pixels that correspond to lines
        matchings = [check_line_is_edge(edge, Pi_line_points, cam2world, kappa,
                                        camera_params) for edge in door_edges]
        results["door_edges_in_image"] = [m[0] for m in matchings]
        ratios = np.array([m[1] for m in matchings])

        if verbose >= 1:
            print(("Matching ratios: " + ", ".join(["%.2f"] * len(ratios)))
                % tuple(100 * ratios))

        door_closed = np.any(ratios > required_matching_ratio)

    results["cam2world"] = cam2world
    results["Pi_line_points"] = Pi_line_points
    results["image_sobel"] = image_sobel
    results["image_edges"] = image_edges
    results["lines"] = (angles, dists)

    return door_closed, W2I, results
开发者ID:AlexanderFabisch,项目名称:picamera-project,代码行数:51,代码来源:image_processing.py


示例14: test_hough_line_peaks_angle

def test_hough_line_peaks_angle():
    img = np.zeros((100, 100), dtype=np.bool_)
    img[:, 0] = True
    img[0, :] = True

    hspace, angles, dists = tf.hough_line(img)
    assert len(tf.hough_line_peaks(hspace, angles, dists, min_angle=45)[0]) == 2
    assert len(tf.hough_line_peaks(hspace, angles, dists, min_angle=90)[0]) == 1

    theta = np.linspace(0, np.pi, 100)
    hspace, angles, dists = tf.hough_line(img, theta)
    assert len(tf.hough_line_peaks(hspace, angles, dists, min_angle=45)[0]) == 2
    assert len(tf.hough_line_peaks(hspace, angles, dists, min_angle=90)[0]) == 1

    theta = np.linspace(np.pi / 3, 4. / 3 * np.pi, 100)
    hspace, angles, dists = tf.hough_line(img, theta)
    assert len(tf.hough_line_peaks(hspace, angles, dists, min_angle=45)[0]) == 2
    assert len(tf.hough_line_peaks(hspace, angles, dists, min_angle=90)[0]) == 1
开发者ID:ChrisBeaumont,项目名称:scikit-image,代码行数:18,代码来源:test_hough_transform.py


示例15: test_example

def test_example():
        
    # Construct toydata
    image = np.zeros((100, 100))
    idx = np.arange(25, 75)
    image[idx[::-1], idx] = 255
    image[idx, idx] = 255
    
    # Classic straight-line Hough transform  
    h, theta, d = hough_line(image)

    # plot
    plt.figure(figsize=(8, 4))

    plt.subplot(131)
    plt.imshow(image, cmap=plt.cm.gray)
    plt.title('Input image')

    plt.subplot(132)
    plt.imshow(np.log(1 + h),
               extent=[np.rad2deg(theta[-1]), np.rad2deg(theta[0]),
                       d[-1], d[0]],
               cmap=plt.cm.gray, aspect=1/1.5)
    plt.title('Hough transform')
    plt.xlabel('Angles (degrees)')
    plt.ylabel('Distance (pixels)')

    plt.subplot(133)
    plt.imshow(image, cmap=plt.cm.gray)
    rows, cols = image.shape
    for _, angle, dist in zip(*hough_line_peaks(h, theta, d)):
        y0 = (dist - 0 * np.cos(angle)) / np.sin(angle)
        y1 = (dist - cols * np.cos(angle)) / np.sin(angle)
        plt.plot((0, cols), (y0, y1), '-r')
    plt.axis((0, cols, rows, 0))
    plt.title('Detected lines')
开发者ID:sapresearch,项目名称:Tomo,代码行数:36,代码来源:PMHoughT.py


示例16: hough_line

    h, theta, d = hough_line(image)

    fig, ax = plt.subplots(1, 3, figsize=(6, 3.5))

    # Original image
    ax[0].imshow(image, cmap=plt.cm.gray)
    ax[0].axis('off')

    # Display Hough transform
    ax[1].imshow(np.log(1 + h),
                 extent=[np.rad2deg(theta[-1]), np.rad2deg(theta[0]),
                         d[-1], d[0]],
                 cmap=plt.cm.gray, aspect=1 / 1.5)
    ax[1].axis('off')

    # Original image with lines detected
    ax[2].imshow(image, cmap=plt.cm.gray)
    rows, cols = image.shape
    for _, angle, dist in zip(*hough_line_peaks(h, theta, d, min_angle=5,
                                                min_distance=5)):
        y0 = (dist - 0 * np.cos(angle)) / np.sin(angle)
        y1 = (dist - cols * np.cos(angle)) / np.sin(angle)
        ax[2].plot((0, cols), (y0, y1), '-r')
    ax[2].axis((0, cols, rows, 0))
    ax[2].axis('off')

    # Save a nice figure
    fig.tight_layout()
    fig.subplots_adjust(wspace=0, left=0, right=1, top=1, bottom=0)
    fig.savefig('./hough_lines.png', dpi=300)
开发者ID:JDWarner,项目名称:skimage-media,代码行数:30,代码来源:hough_lines.py


示例17: lines

def lines(base, test):
    """
    Reads two images of yoga poses and compares them.
    """
    image1 = imread(base, flatten=True)
    image2 = imread(test, flatten=True)

    # Angles
    a1 = []
    a2 = []

    group1_a1 = []
    group2_a1 = []
    group3_a1 = []
    # Generate figure and 2 axes from matplotlib
    fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(8, 4))

    # # Plot 1 -> Base Case (original)
    # print "Plot 1"
    h, theta, d = hough_line(image1)
    ax1.imshow(image1, cmap=plt.cm.get_cmap('gray'))
    rows, cols = image1.shape

    for _, angle, dist in zip(*hough_line_peaks(h, theta, d)):
        y0 = (dist - 0 * np.cos(angle)) / np.sin(angle)
        y1 = (dist - cols * np.cos(angle)) / np.sin(angle)
        degree = degrees(angle)
        a1.append(degree)
        if degree < -45 or degree > 45:
            if degree < -85 or degree > 85:
                pos_horizontal = []
                neg_horizontal = []
                if degree > 0:
                    pos_horizontal.append(90 - degree)
                elif degree <= 0:
                    neg_horizontal.append(-(degree + 90))
                ax1.plot((0, cols), (y0, y1), '-r')
        elif degree > -45 and degree < 0:
            if degree > -40 and degree < -25:
                group2_a1.append(degree)
                ax1.plot((0, cols), (y0, y1), '-r')
        elif degree > 0 and degree < 45:
            if degree > 15 and degree < 40:
                group3_a1.append(degree)
                ax1.plot((0, cols), (y0, y1), '-r')

    ax1.axis((0, cols, rows, 0))
    ax1.set_title('Detected lines')
    ax1.set_axis_off()
    if len(pos_horizontal) == 0:
        avg_horizontal = reduce(lambda x, y: x + y, neg_horizontal) / float(len(neg_horizontal))
    elif len(neg_horizontal) == 0:
        avg_horizontal = reduce(lambda x, y: x + y, pos_horizontal) / float(len(pos_horizontal))
    else:
        avg_neg = reduce(lambda x, y: x + y, neg_horizontal) / float(len(neg_horizontal))
        avg_pos = reduce(lambda x, y: x + y, pos_horizontal) / float(len(pos_horizontal))
        avg_horizontal = (avg_pos + avg_neg)/2

    print "BASE HORIZONTAL: " + str(avg_horizontal)
    # print group2_a1
    # print group3_a1

    # Plot 2 -> Test Case (submission)
    # print "\nPlot 2"
    h1, theta1, d1 = hough_line(image2)
    ax2.imshow(image2, cmap=plt.cm.gray)
    rows, cols = image2.shape

    group1_a2 = []
    group2_a2 = []
    group3_a2 = []
    for _, angle, dist in zip(*hough_line_peaks(h1, theta1, d1)):
        y0 = (dist - 0 * np.cos(angle)) / np.sin(angle)
        y1 = (dist - cols * np.cos(angle)) / np.sin(angle)
        degree = degrees(angle)
        a2.append(degree)
        if degree < -45 or degree > 45:
            if degree < -85 or degree > 85:
                pos_horizontal_user = []
                neg_horizontal_user = []
                if degree > 0:
                    pos_horizontal_user.append(90 - degree)
                elif degree <= 0:
                    neg_horizontal_user.append(-(degree + 90))
                ax2.plot((0, cols), (y0, y1), '-r')
        elif degree > -45 and degree < 0:
            if degree > -40 and degree < -25:
                group2_a2.append(degree)
                ax2.plot((0, cols), (y0, y1), '-r')
        elif degree > 0 and degree < 45:
            if degree > 15 and degree < 40:
                group3_a2.append(degree)
                ax2.plot((0, cols), (y0, y1), '-r')
        a2.append(degrees(angle))
        # ax2.plot((0, cols), (y0, y1), '-r')

    if len(pos_horizontal_user) == 0:
        avg_horizontal_user = reduce(lambda x, y: x + y, neg_horizontal_user) / float(len(neg_horizontal_user))
    elif len(neg_horizontal_user) == 0:
        avg_horizontal_user = reduce(lambda x, y: x + y, pos_horizontal_user) / float(len(pos_horizontal_user))
#.........这里部分代码省略.........
开发者ID:th13,项目名称:libyoga,代码行数:101,代码来源:hough.py


示例18: extract_corner_hough

def extract_corner_hough(patch):
    """ Extract four corner points using Hough transform

    """
    # Find the lines that makes the boundary box using Hough Transform
    h, theta, d = hough_line(patch)

    # Divide the hough space for searching different horizontal and vertical lines
    hcroph = h[:, 0:30]
    rows, cols = patch.shape

    # Search all vertical lines in the hough parameter space
    # It is located in the middle, when theta is near zero
    vlf = []
    for _, angle, dist in zip(*hough_line_peaks(h, theta, d, min_angle=9)):
        x0 = (dist - 0 * np.sin(angle)) / np.cos(angle)
        x1 = (dist - rows * np.sin(angle)) / np.cos(angle)
        vlf += [((x0, 0), (x1, rows))]

    # Likewise previous operation, but with horizontal lines
    # Located at the left, when theta is near minus 90 degree
    hlf = []
    for _, angle, dist in zip(*hough_line_peaks(hcroph, theta, d, min_angle=9)):
        y0 = (dist - 0 * np.cos(angle)) / np.sin(angle)
        y1 = (dist - cols * np.cos(angle)) / np.sin(angle)
        hlf += [((0, y0), (cols, y1))]

    if DEBUG:
        plt.subplot(142)
        plt.title('hough line')
        plt.imshow(patch, cmap='gray')
        for i in xrange(len(vlf)):
            plt.plot((vlf[i][0][0], vlf[i][1][0]), (vlf[i][0][1], vlf[i][1][1]), 'r-')
        for i in xrange(len(hlf)):
            plt.plot((hlf[i][0][0], hlf[i][1][0]), (hlf[i][0][1], hlf[i][1][1]), 'r-')
        plt.axis([0, cols, rows, 0])

    # Search the rightmost and leftmost vertical lines
    vl = []
    vl += [search_closest_line(vlf, [(0, 0), (0, rows)])]
    vl += [search_closest_line(vlf, [(cols, 0), (cols, rows)])]

    # Search the topmost and bottommost horizontal lines
    hl = []
    hl += [search_closest_line(hlf, [(0, 0), (cols, 0)])]
    hl += [search_closest_line(hlf, [(0, rows), (cols, rows)])]

    if len(hl) < 2 or len(vl) < 2:
        print 'Not enough lines found'
        return []

    points = [vl[0], vl[-1], hl[0], hl[-1]]
    # Check for error
    for i in xrange(4):
        for j in xrange(i + 1, 4):
            if points[i] == points[j]:
                print 'Error Line'
                return []

    # Calculate the intersection between pair of vertical and horizontal lines
    # The line is defined by using two points.
    p1 = calc_intersection(vl[0][0][0], vl[0][0][1], vl[0][1][0], vl[0][1][1], hl[0][0][0], hl[0][0][1], hl[0][1][0],
                           hl[0][1][1])
    p2 = calc_intersection(vl[0][0][0], vl[0][0][1], vl[0][1][0], vl[0][1][1], hl[1][0][0], hl[1][0][1], hl[1][1][0],
                           hl[1][1][1])
    p3 = calc_intersection(vl[1][0][0], vl[1][0][1], vl[1][1][0], vl[1][1][1], hl[0][0][0], hl[0][0][1], hl[0][1][0],
                           hl[0][1][1])
    p4 = calc_intersection(vl[1][0][0], vl[1][0][1], vl[1][1][0], vl[1][1][1], hl[1][0][0], hl[1][0][1], hl[1][1][0],
                           hl[1][1][1])

    # Find the nearest point for each corner
    dim = patch.shape
    corners = [(0, 0), (0, dim[0]), (dim[1], dim[0]), (dim[1], 0)]
    points = [p1, p2, p3, p4]
    dest_points = [[] for x in range(4)]
    for i in xrange(4):
        dest_points[i] = search_closest_points(corners[i], points)

    epsilon = 1e-10
    for i in xrange(4):
        for j in xrange(i + 1, 4):
            if calc_distance(dest_points[i], dest_points[j]) < epsilon:
                print 'Error point'
                return []

    return dest_points
开发者ID:mitbal,项目名称:pemilu,代码行数:86,代码来源:extract.py


示例19: lines

def lines(base, test):
    image1 = imread(base, flatten=True)
    image2 = imread(test, flatten=True)

    # Angles
    a1 = []
    a2 = []

    group1_a1 = []
    group2_a1 = []
    group3_a1 = []

    # # Plot 1 -> Base Case (original)
    # print "Plot 1"
    h, theta, d = hough_line(image1)
    rows, cols = image1.shape

    for _, angle, dist in zip(*hough_line_peaks(h, theta, d)):
        y0 = (dist - 0 * np.cos(angle)) / np.sin(angle)
        y1 = (dist - cols * np.cos(angle)) / np.sin(angle)
        degree = degrees(angle)
        a1.append(degree)
        if degree < -45 or degree > 45:
            if degree < -85 or degree > 85:
                pos_horizontal = []
                neg_horizontal = []
                if degree > 0:
                    pos_horizontal.append(90 - degree)
                elif degree <= 0:
                    neg_horizontal.append(-(degree + 90))
        elif degree > -45 and degree < 0:
            if degree > -40 and degree < -25:
                group2_a1.append(degree)
        elif degree > 0 and degree < 45:
            if degree > 15 and degree < 40:
                group3_a1.append(degree)

    if len(pos_horizontal) == 0:
        avg_horizontal = reduce(lambda x, y: x + y, neg_horizontal) / float(len(neg_horizontal))
    elif len(neg_horizontal) == 0:
        avg_horizontal = reduce(lambda x, y: x + y, pos_horizontal) / float(len(pos_horizontal))
    else:
        avg_neg = reduce(lambda x, y: x + y, neg_horizontal) / float(len(neg_horizontal))
        avg_pos = reduce(lambda x, y: x + y, pos_horizontal) / float(len(pos_horizontal))
        avg_horizontal = (avg_pos + avg_neg)/2

    print "BASE HORIZONTAL: " + str(avg_horizontal)

    h1, theta1, d1 = hough_line(image2)
    rows, cols = image2.shape

    group1_a2 = []
    group2_a2 = []
    group3_a2 = []
    for _, angle, dist in zip(*hough_line_peaks(h1, theta1, d1)):
        y0 = (dist - 0 * np.cos(angle)) / np.sin(angle)
        y1 = (dist - cols * np.cos(angle)) / np.sin(angle)
        degree = degrees(angle)
        a2.append(degree)
        if degree < -45 or degree > 45:
            if degree < -85 or degree > 85:
                pos_horizontal_user = []
                neg_horizontal_user = []
                if degree > 0:
                    pos_horizontal_user.append(90 - degree)
                elif degree <= 0:
                    neg_horizontal_user.append(-(degree + 90))
        elif degree > -45 and degree < 0:
            if degree > -40 and degree < -25:
                group2_a2.append(degree)
        elif degree > 0 and degree < 45:
            if degree > 15 and degree < 40:
                group3_a2.append(degree)
        a2.append(degrees(angle))

    if len(pos_horizontal_user) == 0:
        avg_horizontal_user = reduce(lambda x, y: x + y, neg_horizontal_user) / float(len(neg_horizontal_user))
    elif len(neg_horizontal_user) == 0:
        avg_horizontal_user = reduce(lambda x, y: x + y, pos_horizontal_user) / float(len(pos_horizontal_user))
    else:
        avg_neg = reduce(lambda x, y: x + y, neg_horizontal_user) / float(len(neg_horizontal_user))
        avg_pos = reduce(lambda x, y: x + y, pos_horizontal_user) / float(len(pos_horizontal_user))
        avg_horizontal_user = (avg_pos + avg_neg)/2

    avg_down = -1
    avg_up =-1

    base_down = reduce(lambda x, y: x + y, group2_a1) / float(len(group2_a1))
    if len(group2_a2) > 0:
        avg_down = reduce(lambda x, y: x + y, group2_a2) / float(len(group2_a2))
    base_up = reduce(lambda x, y: x + y, group3_a1) / float(len(group3_a1))
    if len(group3_a2) > 0:
        avg_up = reduce(lambda x, y: x + y, group3_a2) / float(len(group3_a2))

    print "USER HORIZONTAL: " + str(avg_horizontal_user)

    print "BASE DOWN: " + str(base_down)
    print "USER DOWN: " + str(avg_down)

    print "BASE UP: " + str(base_up)
#.........这里部分代码省略.........
开发者ID:th13,项目名称:libyoga,代码行数:101,代码来源:hough.py


示例20: logical_and

between_fields = logical_and(field_area, logical_not(field_mask))

# Find the roads and separate the fields
# Separate out into smaller blocks
print('Separating Fields in image')
for stride in [100, 200, 400]:  # pixels
    num_row_strides = int_(between_fields.shape[0]/stride)
    num_col_strides = int_(between_fields.shape[1]/stride)
    r_stride = int_(between_fields.shape[0]/num_row_strides)
    c_stride = int_(between_fields.shape[1]/num_col_strides)

    for r in range(num_row_strides+1):
        for c in range(num_col_strides+1):
            h, theta, d = hough_line(between_fields[r*r_stride:(r+1)*r_stride, c*c_stride:(c+1)*c_stride])
            threshold = 0  #0.0005*max(h)
            h, theta, d = hough_line_peaks(h, theta, d, min_distance=20, threshold=threshold)
            for n in range(len(theta)):
                if abs(theta[n]) < 0.1 or abs(theta[n]) > ((pi/2) - 0.1):
                    draw_hough_line(field_mask[r*r_stride:(r+1)*r_stride, c*c_stride:(c+1)*c_stride], d[n], theta[n])


# do a few small openings
field_mask = binary_opening(field_mask, rectangle(1, 5))
field_mask = binary_opening(field_mask, rectangle(5, 1))
imsave(fname_template.format('segmented_fields', 'png'), field_mask)

# Label fields
field_mask = label(field_mask, 4, 0) + 1
remove_small_objects(field_mask, 100, 1, True)
field_props = regionprops(field_mask)
开发者ID:danlopez00,项目名称:crop_predict,代码行数:30,代码来源:find_mask.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python transform.iradon函数代码示例发布时间:2022-05-27
下一篇:
Python transform.hough_line函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap