當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。