Detector/LogoDetector.py
def _homography(self, image):
		"""
		Compute homography from image to the given video clip
		"""
		# get matching points
		kp1, des1 = sift.detectAndCompute(image, None)
		kp2, des2 = sift.detectAndCompute(self.template, None)
		bf = cv2.BFMatcher()
		matches = bf.knnMatch(des1, des2, k=2)
		good = []
		# prune the matching
		for m,n in matches:
			if m.distance < 0.5 * n.distance:
			    good.append([m])
		# if no good matching, return 
		if len(good) < 4:
			return
		# extract location info from matching point
		kp1_index = [m[0].queryIdx for m in good]
		kp2_index =	[m[0].trainIdx for m in good]
		kp1 = np.array([k.pt for k in np.array(kp1)[kp1_index]])
		kp2 = np.array([k.pt for k in np.array(kp2)[kp2_index]])
		# calculate homography using RANSAC
		H, _ =  cv2.findHomography(kp2, kp1, cv2.RANSAC, 0.1)
		if H is None:
			return
		# get location of the self.template in the image
		height, width = self.template.shape
		top_left = H.dot(np.array([[0, 0, 1]]).reshape(3, 1)).flatten()
		bottom_left = H.dot(np.array([[0, height, 1]]).reshape(3, 1)).flatten()
		bottom_right = H.dot(np.array([[width, height, 1]]).reshape(3, 1)).flatten()
		top_right = H.dot(np.array([[width, 0, 1]]).reshape(3, 1)).flatten()
		# rescale the points
		top_left = top_left[:2] / top_left[-1]
		bottom_left = bottom_left[:2] / bottom_left[-1]
		bottom_right = bottom_right[:2] / bottom_right[-1]
		top_right = top_right[:2] / top_right[-1]
		# int type
		top_left = top_left.astype(int)
		bottom_left = bottom_left.astype(int)
		bottom_right = bottom_right.astype(int) 
		top_right = top_right.astype(int)

		return top_left, bottom_left, bottom_right, top_right

		Compute homography from image to the given video clip
		
Compute homography from image to the given video clip
Compute homography from image to the given video clip
def _homography(self, image):
		kp1, des1 = sift.detectAndCompute(image, None)
		kp2, des2 = sift.detectAndCompute(self.template, None)
		bf = cv2.BFMatcher()
		matches = bf.knnMatch(des1, des2, k=2)
		good = []
		for m,n in matches:
			if m.distance < 0.5 * n.distance:
			    good.append([m])
		if len(good) < 4:
			return
		kp1_index = [m[0].queryIdx for m in good]
		kp2_index =	[m[0].trainIdx for m in good]
		kp1 = np.array([k.pt for k in np.array(kp1)[kp1_index]])
		kp2 = np.array([k.pt for k in np.array(kp2)[kp2_index]])
		H, _ =  cv2.findHomography(kp2, kp1, cv2.RANSAC, 0.1)
		if H is None:
			return
		height, width = self.template.shape
		top_left = H.dot(np.array([[0, 0, 1]]).reshape(3, 1)).flatten()
		bottom_left = H.dot(np.array([[0, height, 1]]).reshape(3, 1)).flatten()
		bottom_right = H.dot(np.array([[width, height, 1]]).reshape(3, 1)).flatten()
		top_right = H.dot(np.array([[width, 0, 1]]).reshape(3, 1)).flatten()
		top_left = top_left[:2] / top_left[-1]
		bottom_left = bottom_left[:2] / bottom_left[-1]
		bottom_right = bottom_right[:2] / bottom_right[-1]
		top_right = top_right[:2] / top_right[-1]
		top_left = top_left.astype(int)
		bottom_left = bottom_left.astype(int)
		bottom_right = bottom_right.astype(int) 
		top_right = top_right.astype(int)
		return top_left, bottom_left, bottom_right, top_right
def _homography ( self , image ) : kp1 , des1 = sift . detectAndCompute ( image , None ) kp2 , des2 = sift . detectAndCompute ( self . template , None ) bf = cv2 . BFMatcher ( ) matches = bf . knnMatch ( des1 , des2 , k = 2 ) good = [ ] for m , n in matches : if m . distance < 0.5 * n . distance : good . append ( [ m ] ) if len ( good ) < 4 : return kp1_index = [ m [ 0 ] . queryIdx for m in good ] kp2_index = [ m [ 0 ] . trainIdx for m in good ] kp1 = np . array ( [ k . pt for k in np . array ( kp1 ) [ kp1_index ] ] ) kp2 = np . array ( [ k . pt for k in np . array ( kp2 ) [ kp2_index ] ] ) H , _ = cv2 . findHomography ( kp2 , kp1 , cv2 . RANSAC , 0.1 ) if H is None : return height , width = self . template . shape top_left = H . dot ( np . array ( [ [ 0 , 0 , 1 ] ] ) . reshape ( 3 , 1 ) ) . flatten ( ) bottom_left = H . dot ( np . array ( [ [ 0 , height , 1 ] ] ) . reshape ( 3 , 1 ) ) . flatten ( ) bottom_right = H . dot ( np . array ( [ [ width , height , 1 ] ] ) . reshape ( 3 , 1 ) ) . flatten ( ) top_right = H . dot ( np . array ( [ [ width , 0 , 1 ] ] ) . reshape ( 3 , 1 ) ) . flatten ( ) top_left = top_left [ : 2 ] / top_left [ - 1 ] bottom_left = bottom_left [ : 2 ] / bottom_left [ - 1 ] bottom_right = bottom_right [ : 2 ] / bottom_right [ - 1 ] top_right = top_right [ : 2 ] / top_right [ - 1 ] top_left = top_left . astype ( int ) bottom_left = bottom_left . astype ( int ) bottom_right = bottom_right . astype ( int ) top_right = top_right . astype ( int ) return top_left , bottom_left , bottom_right , top_right
Compute homography from image to the given video clip
Compute homography from image to the given video clip
"""
		Compute homography from image to the given video clip
		""" # get matching points # prune the matching # if no good matching, return  # extract location info from matching point # calculate homography using RANSAC # get location of the self.template in the image # rescale the points # int type
self
image