Пример #1
0
 def compute_distance_image(self, input_map):
     #Create necessary matrices
     dist_matrix=cv.CreateMat(input_map.height, input_map.width, cv.CV_32FC1)
     dist_img_gray=cv.CreateMat(input_map.height, input_map.width, cv.CV_8UC1)
     #Get the Euclidean distance from every free point in the map to the closest obstacle
     cv.DistTransform(input_map, dist_matrix)
     #To make the pikes of the distance function we use the square of the resulted value
     square_mat=cv.CreateMat(input_map.height, input_map.width, cv.CV_32FC1)
     cv.Pow(dist_matrix,square_mat, 3)
     #We normalize the values of all pixels to print the image.
     matrix = dist_matrix
     max_val = np.max(matrix)
     m=255/max_val
     for r in range(0, matrix.height):
         for c in range(0, matrix.width):
             dist_img_gray[r,c]=np.int(m*matrix[r,c])
     return(dist_img_gray, dist_matrix)
Пример #2
0
def on_trackbar(edge_thresh):

    cv.Threshold(gray, edge, float(edge_thresh), float(edge_thresh),
                 cv.CV_THRESH_BINARY)
    #Distance transform
    cv.DistTransform(edge, dist, cv.CV_DIST_L2, cv.CV_DIST_MASK_5)

    cv.ConvertScale(dist, dist, 5000.0, 0)
    cv.Pow(dist, dist, 0.5)

    cv.ConvertScale(dist, dist32s, 1.0, 0.5)
    cv.AndS(dist32s, cv.ScalarAll(255), dist32s, None)
    cv.ConvertScale(dist32s, dist8u1, 1, 0)
    cv.ConvertScale(dist32s, dist32s, -1, 0)
    cv.AddS(dist32s, cv.ScalarAll(255), dist32s, None)
    cv.ConvertScale(dist32s, dist8u2, 1, 0)
    cv.Merge(dist8u1, dist8u2, dist8u2, None, dist8u)
    cv.ShowImage(wndname, dist8u)