Python cv2.TM_CCOEFF Examples

The following are 3 code examples of cv2.TM_CCOEFF(). 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: WatermarkRemover.py    From nowatermark with MIT License 6 votes vote down vote up
def find_watermark_from_gray(self, gray_img, watermark_template_gray_img):
        """
        从原图的灰度图中寻找水印位置
        :param gray_img: 原图的灰度图
        :param watermark_template_gray_img: 水印模板的灰度图
        :return: x1, y1, x2, y2
        """
        # Load the images in gray scale

        method = cv2.TM_CCOEFF
        # Apply template Matching
        res = cv2.matchTemplate(gray_img, watermark_template_gray_img, method)
        min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res)

        # If the method is TM_SQDIFF or TM_SQDIFF_NORMED, take minimum
        if method in [cv2.TM_SQDIFF, cv2.TM_SQDIFF_NORMED]:
            x, y = min_loc
        else:
            x, y = max_loc

        return x, y, x + self.watermark_template_w, y + self.watermark_template_h 
Example #2
Source File: pycv2.py    From vrequest with MIT License 5 votes vote down vote up
def findmatchtemplate(filepathname, befindimage):
    # 从 befindimage 中找到 filepathname,(befindimage 是大图,filepathname 是小图)
    img1 = cv2.imread(filepathname)
    img2 = cv2.imread(befindimage)
    w, h = img1.shape[:2]
    v = cv2.matchTemplate(img2,img1,cv2.TM_CCOEFF)
    a, b, c, top_left = cv2.minMaxLoc(v)
    bot_right = top_left[0]+h, top_left[1]+w
    img3 = cv2.rectangle(img2, top_left, bot_right, (155,155,0), 1)
    cv2.imshow('nier', img3)
    # cv2.waitKey()
    # cv2.destroyAllWindows()
    return top_left[0], top_left[1], w, h 
Example #3
Source File: test_dummy.py    From airtest with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def other():
    scr = cv2.imread(screenFile, 0)
    icon = cv2.imread(iconFile, 0)

    res = cv2.matchTemplate(icon, scr, cv2.TM_CCOEFF)
    minVal, maxVal, minLoc, maxLoc = cv2.minMaxLoc(res)
    topLeft = maxLoc
    print topLeft