当前位置: 首页>>代码示例>>Python>>正文


Python cv2.sqrt方法代码示例

本文整理汇总了Python中cv2.sqrt方法的典型用法代码示例。如果您正苦于以下问题:Python cv2.sqrt方法的具体用法?Python cv2.sqrt怎么用?Python cv2.sqrt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cv2的用法示例。


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

示例1: compute_error

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import sqrt [as 别名]
def compute_error(flow, gt_flow, invalid_mask):

    mag_flow = cv2.sqrt(gt_flow[:, :, 0] * gt_flow[:, :, 0] + gt_flow[:, :, 1] * gt_flow[:, :, 1])


    ret, mask_to_large = cv2.threshold(src=mag_flow, thresh=900, maxval=1,                                   type=cv2.THRESH_BINARY_INV)

    total_inp_mask = invalid_mask[:, :, 0] + invalid_mask[:, :, 1] + invalid_mask[:, :, 2]
    ret, fg_mask = cv2.threshold(src=invalid_mask[:, :, 1], thresh=0.5, maxval=1,
                                        type=cv2.THRESH_BINARY)
    ret, total_mask = cv2.threshold(src=total_inp_mask, thresh=0.5, maxval=1,
                                        type=cv2.THRESH_BINARY)
    #mask_to_large = np.ones(fg_mask.shape)
    bg_mask = total_mask - fg_mask
    ee_base = computeEE(flow, gt_flow)
    result = dict()
    result["FG"] = computer_errors(ee_base, fg_mask * mask_to_large)
    result["BG"] = computer_errors(ee_base, bg_mask * mask_to_large)
    result["Total"] = computer_errors(ee_base, total_mask * mask_to_large)
    return result 
开发者ID:tsenst,项目名称:CrowdFlow,代码行数:22,代码来源:util.py

示例2: differenz_trajectory_list

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import sqrt [as 别名]
def differenz_trajectory_list(gt_trajectories, estimate_trajectories):
    """
     .@brief   gt_trajectories and estimate trajectories have to be aligned
    """
    differenz_trajectory_list = list()
    assert len(gt_trajectories) == len(estimate_trajectories)
    for n in range(len(gt_trajectories)):
        if len(gt_trajectories[n]) != (len(estimate_trajectories[n])) / 2:
            print( "ID", n, len(gt_trajectories[n]), (len(estimate_trajectories[n])) / 2)
        for i in range(len(gt_trajectories[n])):

            diff_x = gt_trajectories[n][i][0] - estimate_trajectories[n][2*i]
            diff_y = gt_trajectories[n][i][1] - estimate_trajectories[n][2*i+1]
            differenz_trajectory_list.append(math.sqrt( diff_x * diff_x + diff_y * diff_y))

    return np.array(differenz_trajectory_list) 
开发者ID:tsenst,项目名称:CrowdFlow,代码行数:18,代码来源:util.py

示例3: flow2RGB

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import sqrt [as 别名]
def flow2RGB(flow, max_flow_mag = 5):
    """ Color-coded visualization of optical flow fields

        # Arguments
            flow: array of shape [:,:,2] containing optical flow
            max_flow_mag: maximal expected flow magnitude used to normalize. If max_flow_mag < 0 the maximal
            magnitude of the optical flow field will be used
    """
    hsv_mat = np.ones(shape=(flow.shape[0], flow.shape[1], 3), dtype=np.float32) * 255
    ee = cv2.sqrt(flow[:, :, 0] * flow[:, :, 0] + flow[:, :, 1] * flow[:, :, 1])
    angle = np.arccos(flow[:, :, 0]/ ee)
    angle[flow[:, :, 0] == 0] = 0
    angle[flow[:, :, 1] == 0] = 6.2831853 - angle[flow[:, :, 1] == 0]
    angle = angle * 180 / 3.141
    hsv_mat[:,:,0] = angle
    if max_flow_mag < 0:
        max_flow_mag = ee.max()
    hsv_mat[:,:,1] = ee * 255.0 / max_flow_mag
    ret, hsv_mat[:,:,1] = cv2.threshold(src=hsv_mat[:,:,1], maxval=255, thresh=255, type=cv2.THRESH_TRUNC )
    rgb_mat = cv2.cvtColor(hsv_mat.astype(np.uint8), cv2.COLOR_HSV2BGR)
    return rgb_mat 
开发者ID:tsenst,项目名称:CrowdFlow,代码行数:23,代码来源:util.py

示例4: farthest_point

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import sqrt [as 别名]
def farthest_point(defects, contour, centroid):
    if defects is not None and centroid is not None:
        s = defects[:, 0][:, 0]
        cx, cy = centroid

        x = np.array(contour[s][:, 0][:, 0], dtype=np.float)
        y = np.array(contour[s][:, 0][:, 1], dtype=np.float)

        xp = cv2.pow(cv2.subtract(x, cx), 2)
        yp = cv2.pow(cv2.subtract(y, cy), 2)
        dist = cv2.sqrt(cv2.add(xp, yp))

        dist_max_i = np.argmax(dist)

        if dist_max_i < len(s):
            farthest_defect = s[dist_max_i]
            farthest_point = tuple(contour[farthest_defect][0])
            return farthest_point
        else:
            return None 
开发者ID:amarlearning,项目名称:Finger-Detection-and-Tracking,代码行数:22,代码来源:FingerDetection.py

示例5: convert_to_nearest_label

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import sqrt [as 别名]
def convert_to_nearest_label(label_path, image_size, apply_ignore=True):
    """
    Convert RGB label image to onehot label image
    :param label_path: File path of RGB label image
    :param image_size: Size to resize result image
    :param apply_ignore: Apply ignore
    :return:
    """
    label = np.array(Image.open(label_path).resize((image_size[0], image_size[1]), Image.ANTIALIAS))[:, :, :3]
    label = label.astype(np.float32)
    stacked_label = list()
    for index, mask in enumerate(label_mask):
        length = np.sum(cv2.pow(label - mask, 2), axis=2, keepdims=False)
        length = cv2.sqrt(length)
        stacked_label.append(length)

    stacked_label = np.array(stacked_label)
    stacked_label = np.transpose(stacked_label, [1, 2, 0])
    converted_to_classes = np.argmin(stacked_label, axis=2).astype(np.uint8)
    if apply_ignore:
        ignore_mask = (converted_to_classes == (len(label_mask) - 1)).astype(np.uint8)
        ignore_mask *= (256 - len(label_mask))
        converted_to_classes += ignore_mask

    return converted_to_classes 
开发者ID:POSTECH-IMLAB,项目名称:LaneSegmentationNetwork,代码行数:27,代码来源:dataset_util.py

示例6: computeEE

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import sqrt [as 别名]
def computeEE(src0, src1):
    diff_flow = src0 - src1
    res = (diff_flow[:, :, 0] * diff_flow[:, :, 0]) + (diff_flow[:, :, 1] * diff_flow[:, :, 1])
    return cv2.sqrt(res) 
开发者ID:tsenst,项目名称:CrowdFlow,代码行数:6,代码来源:util.py


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