Python cv2.sqrt() Examples
The following are 7
code examples of cv2.sqrt().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
cv2
, or try the search function
.
Example #1
Source File: util.py From CrowdFlow with GNU General Public License v3.0 | 6 votes |
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
Example #2
Source File: util.py From CrowdFlow with GNU General Public License v3.0 | 6 votes |
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)
Example #3
Source File: util.py From CrowdFlow with GNU General Public License v3.0 | 6 votes |
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
Example #4
Source File: util.py From CrowdFlow with GNU General Public License v3.0 | 6 votes |
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 * 220.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
Example #5
Source File: FingerDetection.py From Finger-Detection-and-Tracking with BSD 2-Clause "Simplified" License | 6 votes |
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
Example #6
Source File: dataset_util.py From LaneSegmentationNetwork with GNU Lesser General Public License v3.0 | 6 votes |
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
Example #7
Source File: util.py From CrowdFlow with GNU General Public License v3.0 | 5 votes |
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)