我们从Python开源项目中,提取了以下9个代码示例,用于说明如何使用cv2.goodFeaturesToTrack()。
def execute_GoodFeaturesToTrack(proxy,obj): ''' https://opencv-python-tutroals.readthedocs.org/en/latest/py_tutorials/py_feature2d/py_shi_tomasi/py_shi_tomasi.html ''' try: img=obj.sourceObject.Proxy.img.copy() except: img=cv2.imread(__dir__+'/icons/freek.png') gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) corners = cv2.goodFeaturesToTrack(gray,obj.maxCorners,obj.qualityLevel,obj.minDistance) corners = np.int0(corners) for i in corners: x,y = i.ravel() cv2.circle(img,(x,y),3,255,-1) obj.Proxy.img = img
def center_from_good_features(matrix): x, y = (0, 0) weight = 0 corners = cv2.goodFeaturesToTrack(matrix, FEATURE_DETECT_MAX_CORNERS, FEATURE_DETECT_QUALITY_LEVEL, FEATURE_DETECT_MIN_DISTANCE) for point in corners: weight += 1 x += point[0][0] y += point[0][1] return { 'x': x / weight, 'y': y / weight, 'count': weight }
def _find_in_image(self, image, n_max): """ Calculate keypoints from a image Using cv2.goodFeaturesToTrack to find good points @param: image: np.ndarray @return: a list Cowards use this. The brave use '_key_points' which starts from scratch """ rows, cols = image.shape kp = cv2.goodFeaturesToTrack(image, n_max, 0.01, 10, 3) # assert kp.shape = (<number of keypoints>, 1, 2) if kp is None: return [] return [list(i) for i in kp.reshape(-1, 2)[:, ::-1].astype(np.int)]
def get_features_good(self, frame_gray): """ Jianbo Shi and Carlo Tomasi wrote a paper in 1994 called "Good features to track", so now it's called that in OpenCV. """ strong_corners = cv2.goodFeaturesToTrack( frame_gray, mask=None, **self.feature_params ) return strong_corners
def shi_tomasi(gray): # image???? # maxCorners??????? # qualityLevel????????????????????? # minDistance?????????? corners = cv2.goodFeaturesToTrack(gray,25,0.01,10) cv2.computeCorrespondEpilines() # ?????? [[ 311., 250.]] ???????? corners = np.int0(corners) return corners
def detect(self, image): gray = np.float32(cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)) corners = cv2.goodFeaturesToTrack(gray, Configuration.gftt_max_corners, Configuration.gftt_quality_level, Configuration.gftt_min_distance) return [x[0] for x in corners]
def extract(img): return np.ravel(cv2.goodFeaturesToTrack(cv2.cvtColor(img, cv2.COLOR_BGR2GRAY), 8, 0.08, 3))
def detectAllVertices(self, testImg): # Detecting vertices on the newly constructed board self.gray = cv2.cvtColor(testImg, cv2.COLOR_BGR2GRAY) tempVertices = cv2.goodFeaturesToTrack(self.gray, int(self.FINAL_VERTICES_COUNT), 0.01, 10) tempVertices = np.int0(tempVertices) newVertices = [] for i in tempVertices: x, y = i.ravel() newVertices.append((x, y)) # Matrix to store coordinates of vertices on the board self.ALL_VERTICES = [[(0, 0) for x in range(self.FACTOR + 2)] for x in range(self.FACTOR + 2)] # Filling the matrix self.ALL_VERTICES[0][0] = (self.CORNERS[1]) for i in range(0, self.FACTOR): for j in range(0, self.FACTOR): predicted_x = self.ALL_VERTICES[i][j][0] + int( (self.OUTER_VERTICES[2][self.FACTOR - i][0] - self.OUTER_VERTICES[0][i][0]) / 8) predicted_y = self.ALL_VERTICES[i][j][1] + int( (self.OUTER_VERTICES[3][self.FACTOR - i][1] - self.OUTER_VERTICES[1][i][1]) / 8) minn_dist = self.INT_MAX for point in newVertices: this_dist = Geometry.getPointsDistance(point, (predicted_x, self.ALL_VERTICES[i][j][1])) if this_dist < minn_dist: self.ALL_VERTICES[i][j + 1] = point minn_dist = this_dist minn_dist = self.INT_MAX for point in newVertices: this_dist = Geometry.getPointsDistance(point, (self.ALL_VERTICES[i][j][0], predicted_y)) if this_dist < minn_dist: self.ALL_VERTICES[i + 1][j] = point; minn_dist = this_dist self.ALL_VERTICES[self.FACTOR][self.FACTOR] = (self.CORNERS[3])