image = imutils.url_to_image(url) 自动边缘检测Automatic Canny Edge Detection gray = cv2.cvtColor(logo, cv2.COLOR_BGR2GRAY) edgeMap = imutils.auto_canny(gray) #源码 def auto_canny(image, sigma=0.33): # compute the median of the single channel pixel intensities v = np.median(image) # apply automatic Canny edge detection using the computed median lower = int(max(0, (1.0 - sigma) * v)) upper = int(min(255, (1.0 + sigma) * v)) edged = cv2.Canny(image, lower, upper) # return the edged image return edged
深度阅读(略)
广度阅读
dense
1 2 3 4 5 6 7
class DENSE: def detect(self, img): kps = [] for x in range(0, img.shape[1], self.step): for y in range(0, img.shape[0], self.step): # create a keypoint and add it to the keypoints list kps.append(cv2.KeyPoint(x, y, self.radius))
def corners_to_keypoints(corners): """function to take the corners from cv2.GoodFeaturesToTrack and return cv2.KeyPoints""" if corners is None: keypoints = [] else: keypoints = [cv2.KeyPoint(kp[0][0], kp[0][1], 1) for kp in corners]
for x in range(0, img.shape[1], self.step): for y in range(0, img.shape[0], self.step): # create a keypoint and add it to the keypoints list kps.append(cv2.KeyPoint(x, y, self.radius)) => [cv2.KeyPoint(x,y) for x in range(0, img.shape[1], self.step) for y in range(0, img.shape[0], self.step)]