当前位置:   article > 正文

Python cv2.minMaxLoc方法代码示例

cv2.minmaxloc

本文整理汇总了Python中cv2.minMaxLoc方法的典型用法代码示例。如果您正苦于以下问题:Python cv2.minMaxLoc方法的具体用法?Python cv2.minMaxLoc怎么用?Python cv2.minMaxLoc使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在模块cv2的用法示例。

在下文中一共展示了cv2.minMaxLoc方法的22个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: match_img

​ 点赞 7 ​

  1. # 需要导入模块: import cv2 [as 别名]
  2. # 或者: from cv2 import minMaxLoc [as 别名]
  3. def match_img(image, template, value):
  4. """
  5. :param image: 图片
  6. :param template: 模板
  7. :param value: 阈值
  8. :return: 水印坐标
  9. 描述:用于获得这幅图片模板对应的位置坐标,用途:校准元素位置信息
  10. """
  11. res = cv2.matchTemplate(image, template, cv2.TM_CCOEFF_NORMED)
  12. threshold = value
  13. min_v, max_v, min_pt, max_pt = cv2.minMaxLoc(res)
  14. if max_v < threshold:
  15. return False
  16. if not max_pt[0] in range(10, 40) or max_pt[1] > 20:
  17. return False
  18. return max_pt

开发者ID:Mingtzge,项目名称:2019-CCF-BDCI-OCR-MCZJ-OCR-IdentificationIDElement,代码行数:18,代码来源:split_img_generate_data.py


 

 

示例2: get_match_confidence

​ 点赞 7 ​

  1. # 需要导入模块: import cv2 [as 别名]
  2. # 或者: from cv2 import minMaxLoc [as 别名]
  3. def get_match_confidence(img1, img2, mask=None):
  4. if img1.shape != img2.shape:
  5. return False
  6. ## first try, using absdiff
  7. # diff = cv2.absdiff(img1, img2)
  8. # h, w, d = diff.shape
  9. # total = h*w*d
  10. # num = (diff<20).sum()
  11. # print 'is_match', total, num
  12. # return num > total*0.90
  13. if mask is not None:
  14. img1 = img1.copy()
  15. img1[mask!=0] = 0
  16. img2 = img2.copy()
  17. img2[mask!=0] = 0
  18. ## using match
  19. match = cv2.matchTemplate(img1, img2, cv2.TM_CCOEFF_NORMED)
  20. _, confidence, _, _ = cv2.minMaxLoc(match)
  21. # print confidence
  22. return confidence

开发者ID:NetEaseGame,项目名称:ATX,代码行数:22,代码来源:scene_detector.py


 

示例3: probability

​ 点赞 6 ​

  1. # 需要导入模块: import cv2 [as 别名]
  2. # 或者: from cv2 import minMaxLoc [as 别名]
  3. def probability(self, im: str) -> float:
  4. """
  5. Return the probability of the existence of given image.
  6. :param im: the name of the image.
  7. :return: the probability (confidence).
  8. """
  9. assert self.screen is not None
  10. try:
  11. template = self.images[im]
  12. except KeyError:
  13. logger.error('Unexpected image name {}'.format(im))
  14. return 0.0
  15. res = cv.matchTemplate(self.screen, template, TM_METHOD)
  16. _, max_val, _, max_loc = cv.minMaxLoc(res)
  17. logger.debug('max_val = {}, max_loc = {}'.format(max_val, max_loc))
  18. return max_val

开发者ID:will7101,项目名称:fgo-bot,代码行数:20,代码来源:tm.py


 

 

示例4: find

​ 点赞 6 ​

  1. # 需要导入模块: import cv2 [as 别名]
  2. # 或者: from cv2 import minMaxLoc [as 别名]
  3. def find(self, im: str, threshold: float = None) -> Tuple[int, int]:
  4. """
  5. Find the template image on screen and return its top-left coords.
  6. Return None if the matching value is less than `threshold`.
  7. :param im: the name of the image
  8. :param threshold: the threshold of matching. If not given, will be set to the default threshold.
  9. :return: the top-left coords of the result. Return (-1, -1) if not found.
  10. """
  11. threshold = threshold or self.threshold
  12. assert self.screen is not None
  13. try:
  14. template = self.images[im]
  15. except KeyError:
  16. logger.error('Unexpected image name {}'.format(im))
  17. return -1, -1
  18. res = cv.matchTemplate(self.screen, template, TM_METHOD)
  19. _, max_val, _, max_loc = cv.minMaxLoc(res)
  20. logger.debug('max_val = {}, max_loc = {}'.format(max_val, max_loc))
  21. return max_loc if max_val >= threshold else (-1, -1)

开发者ID:will7101,项目名称:fgo-bot,代码行数:25,代码来源:tm.py


 

示例5: cal_rgb_confidence

​ 点赞 6 ​

  1. # 需要导入模块: import cv2 [as 别名]
  2. # 或者: from cv2 import minMaxLoc [as 别名]
  3. def cal_rgb_confidence(img_src_rgb, img_sch_rgb):
  4. """同大小彩图计算相似度."""
  5. # BGR三通道心理学权重:
  6. weight = (0.114, 0.587, 0.299)
  7. src_bgr, sch_bgr = cv2.split(img_src_rgb), cv2.split(img_sch_rgb)
  8. # 计算BGR三通道的confidence,存入bgr_confidence:
  9. bgr_confidence = [0, 0, 0]
  10. for i in range(3):
  11. res_temp = cv2.matchTemplate(src_bgr[i], sch_bgr[i], cv2.TM_CCOEFF_NORMED)
  12. min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res_temp)
  13. bgr_confidence[i] = max_val
  14. # 加权可信度
  15. weighted_confidence = bgr_confidence[0] * weight[0] + bgr_confidence[1] * weight[1] + bgr_confidence[2] * weight[2]
  16. return weighted_confidence

开发者ID:AirtestProject,项目名称:Airtest,代码行数:19,代码来源:cal_confidence.py


 

 

示例6: find_template

​ 点赞 6 ​

  1. # 需要导入模块: import cv2 [as 别名]
  2. # 或者: from cv2 import minMaxLoc [as 别名]
  3. def find_template(im_source, im_search, threshold=0.8, rgb=False):
  4. """函数功能:找到最优结果."""
  5. # 第一步:校验图像输入
  6. check_source_larger_than_search(im_source, im_search)
  7. # 第二步:计算模板匹配的结果矩阵res
  8. res = _get_template_result_matrix(im_source, im_search)
  9. # 第三步:依次获取匹配结果
  10. min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res)
  11. h, w = im_search.shape[:2]
  12. # 求取可信度:
  13. confidence = _get_confidence_from_matrix(im_source, im_search, max_loc, max_val, w, h, rgb)
  14. # 求取识别位置: 目标中心 + 目标区域:
  15. middle_point, rectangle = _get_target_rectangle(max_loc, w, h)
  16. best_match = generate_result(middle_point, rectangle, confidence)
  17. LOGGING.debug("threshold=%s, result=%s" % (threshold, best_match))
  18. return best_match if confidence >= threshold else None

开发者ID:AirtestProject,项目名称:Airtest,代码行数:18,代码来源:template.py


 

示例7: match_dmg_templates

​ 点赞 6 ​

  1. # 需要导入模块: import cv2 [as 别名]
  2. # 或者: from cv2 import minMaxLoc [as 别名]
  3. def match_dmg_templates(self, frame):
  4. match_mat, max_val, tl = [None]*10, [0]*10, [(0, 0)]*10
  5. for i in range(0, 10):
  6. match_mat[i] = cv2.matchTemplate(frame, self.num_img[0],
  7. cv2.TM_CCORR_NORMED, mask=self.num_mask[0])
  8. _, max_val[i], _, tl[i] = cv2.minMaxLoc(match_mat[i])
  9. # print(max_val[0])
  10. br = (tl[0][0] + self.num_w, tl[0][1] + self.num_h)
  11. frame = cv2.rectangle(frame, tl[0], br, (255, 255, 255), 2)
  12. # Multi-template result searching
  13. # _, max_val_1, _, tl_1 = cv2.minMaxLoc(np.array(match_mat))
  14. # print(tl_1)
  15. # A number of methods corresponding to the various trackbars available.

开发者ID:jpnaterer,项目名称:smashscan,代码行数:18,代码来源:thresholding.py


 

示例8: main

​ 点赞 6 ​

  1. # 需要导入模块: import cv2 [as 别名]
  2. # 或者: from cv2 import minMaxLoc [as 别名]
  3. def main():
  4. src = cv2.imread('src.jpg', cv2.IMREAD_GRAYSCALE)
  5. tpl = cv2.imread('tpl.jpg', cv2.IMREAD_GRAYSCALE)
  6. result = cv2.matchTemplate(src, tpl, cv2.TM_CCOEFF_NORMED)
  7. result = cv2.normalize(result, dst=None, alpha=0, beta=1,
  8. norm_type=cv2.NORM_MINMAX, dtype=-1)
  9. minVal, maxVal, minLoc, maxLoc = cv2.minMaxLoc(result)
  10. matchLoc = maxLoc
  11. draw1 = cv2.rectangle(
  12. src, matchLoc, (matchLoc[0] + tpl.shape[1], matchLoc[1] + tpl.shape[0]), 0, 2, 8, 0)
  13. draw2 = cv2.rectangle(
  14. result, matchLoc, (matchLoc[0] + tpl.shape[1], matchLoc[1] + tpl.shape[0]), 0, 2, 8, 0)
  15. cv2.imshow('draw1', draw1)
  16. cv2.imshow('draw2', draw2)
  17. cv2.waitKey(0)
  18. print src.shape
  19. print tpl.shape
  20. print result.shape
  21. print matchLoc

开发者ID:cynricfu,项目名称:dual-fisheye-video-stitching,代码行数:21,代码来源:template_matching.py


 

示例9: detect

​ 点赞 6 ​

  1. # 需要导入模块: import cv2 [as 别名]
  2. # 或者: from cv2 import minMaxLoc [as 别名]
  3. def detect(self, z, x):
  4. k = self.gaussianCorrelation(x, z)
  5. # 得到响应图
  6. res = real(fftd(complexMultiplication(self._alphaf, fftd(k)), True))
  7. # pv:响应最大值 pi:相应最大点的索引数组
  8. _, pv, _, pi = cv2.minMaxLoc(res)
  9. # 得到响应最大的点索引的float表示
  10. p = [float(pi[0]), float(pi[1])]
  11. # 使用幅值做差来定位峰值的位置
  12. if pi[0] > 0 and pi[0] < res.shape[1] - 1:
  13. p[0] += self.subPixelPeak(res[pi[1], pi[0] - 1], pv, res[pi[1], pi[0] + 1])
  14. if pi[1] > 0 and pi[1] < res.shape[0] - 1:
  15. p[1] += self.subPixelPeak(res[pi[1] - 1, pi[0]], pv, res[pi[1] + 1, pi[0]])
  16. # 得出偏离采样中心的位移
  17. p[0] -= res.shape[1] / 2.
  18. p[1] -= res.shape[0] / 2.
  19. # 返回偏离采样中心的位移和峰值
  20. return p, pv
  21. # 基于当前帧更新目标位置

开发者ID:ryanfwy,项目名称:KCF-DSST-py,代码行数:26,代码来源:tracker.py


 

示例10: detect_scale

​ 点赞 6 ​

  1. # 需要导入模块: import cv2 [as 别名]
  2. # 或者: from cv2 import minMaxLoc [as 别名]
  3. def detect_scale(self, image):
  4. xsf = self.get_scale_sample(image)
  5. # Compute AZ in the paper
  6. add_temp = cv2.reduce(complexMultiplication(self.sf_num, xsf), 0, cv2.REDUCE_SUM)
  7. # compute the final y
  8. scale_response = cv2.idft(complexDivisionReal(add_temp, (self.sf_den + self.scale_lambda)), None, cv2.DFT_REAL_OUTPUT)
  9. # Get the max point as the final scaling rate
  10. # pv:响应最大值 pi:相应最大点的索引数组
  11. _, pv, _, pi = cv2.minMaxLoc(scale_response)
  12. return pi
  13. # 更新尺度

开发者ID:ryanfwy,项目名称:KCF-DSST-py,代码行数:18,代码来源:tracker.py


 

示例11: imagesearcharea

​ 点赞 6 ​

  1. # 需要导入模块: import cv2 [as 别名]
  2. # 或者: from cv2 import minMaxLoc [as 别名]
  3. def imagesearcharea(image, x1, y1, x2, y2, precision=0.8, im=None):
  4. if im is None:
  5. im = region_grabber(region=(x1, y1, x2, y2))
  6. if is_retina:
  7. im.thumbnail((round(im.size[0] * 0.5), round(im.size[1] * 0.5)))
  8. # im.save('testarea.png') usefull for debugging purposes, this will save the captured region as "testarea.png"
  9. img_rgb = np.array(im)
  10. img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY)
  11. template = cv2.imread(image, 0)
  12. res = cv2.matchTemplate(img_gray, template, cv2.TM_CCOEFF_NORMED)
  13. min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res)
  14. if max_val < precision:
  15. return [-1, -1]
  16. return max_loc

开发者ID:drov0,项目名称:python-imagesearch,代码行数:18,代码来源:imagesearch.py


 

示例12: locate_img

​ 点赞 6 ​

  1. # 需要导入模块: import cv2 [as 别名]
  2. # 或者: from cv2 import minMaxLoc [as 别名]
  3. def locate_img(image, template):
  4. img = image.copy()
  5. res = cv2.matchTemplate(img, template, method)
  6. print res
  7. print res.shape
  8. cv2.imwrite('image/shape.png', res)
  9. min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res)
  10. print cv2.minMaxLoc(res)
  11. if method in [cv2.TM_SQDIFF, cv2.TM_SQDIFF_NORMED]:
  12. top_left = min_loc
  13. else:
  14. top_left = max_loc
  15. h, w = template.shape
  16. bottom_right = (top_left[0] + w, top_left[1]+h)
  17. cv2.rectangle(img, top_left, bottom_right, 255, 2)
  18. cv2.imwrite('image/tt.jpg', img)

开发者ID:NetEase,项目名称:airtest,代码行数:18,代码来源:pixelmatch.py


 

示例13: getKeypoints

​ 点赞 6 ​

  1. # 需要导入模块: import cv2 [as 别名]
  2. # 或者: from cv2 import minMaxLoc [as 别名]
  3. def getKeypoints(probMap, threshold=0.1):
  4. mapSmooth = cv2.GaussianBlur(probMap, (3, 3), 0, 0)
  5. mapMask = np.uint8(mapSmooth>threshold)
  6. keypoints = []
  7. contours = None
  8. try:
  9. #OpenCV4.x
  10. contours, _ = cv2.findContours(mapMask, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
  11. except:
  12. #OpenCV3.x
  13. _, contours, _ = cv2.findContours(mapMask, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
  14. for cnt in contours:
  15. blobMask = np.zeros(mapMask.shape)
  16. blobMask = cv2.fillConvexPoly(blobMask, cnt, 1)
  17. maskedProbMap = mapSmooth * blobMask
  18. _, maxVal, _, maxLoc = cv2.minMaxLoc(maskedProbMap)
  19. keypoints.append(maxLoc + (probMap[maxLoc[1], maxLoc[0]],))
  20. return keypoints

开发者ID:PINTO0309,项目名称:MobileNetV2-PoseEstimation,代码行数:23,代码来源:openvino-usbcamera-cpu-ncs2-async.py


 

示例14: _locate_target

​ 点赞 6 ​

  1. # 需要导入模块: import cv2 [as 别名]
  2. # 或者: from cv2 import minMaxLoc [as 别名]
  3. def _locate_target(self, score):
  4. def subpixel_peak(left, center, right):
  5. divisor = 2 * center - left - right
  6. if abs(divisor) < 1e-3:
  7. return 0
  8. return 0.5 * (right - left) / divisor
  9. _, _, _, max_loc = cv2.minMaxLoc(score)
  10. loc = np.float32(max_loc)
  11. if max_loc[0] in range(1, score.shape[1] - 1):
  12. loc[0] += subpixel_peak(
  13. score[max_loc[1], max_loc[0] - 1],
  14. score[max_loc[1], max_loc[0]],
  15. score[max_loc[1], max_loc[0] + 1])
  16. if max_loc[1] in range(1, score.shape[0] - 1):
  17. loc[1] += subpixel_peak(
  18. score[max_loc[1] - 1, max_loc[0]],
  19. score[max_loc[1], max_loc[0]],
  20. score[max_loc[1] + 1, max_loc[0]])
  21. offset = loc - np.float32(score.shape[1::-1]) / 2
  22. return offset

开发者ID:huanglianghua,项目名称:open-vot,代码行数:25,代码来源:kcf.py


 

示例15: SMAvgLocalMax

​ 点赞 6 ​

  1. # 需要导入模块: import cv2 [as 别名]
  2. # 或者: from cv2 import minMaxLoc [as 别名]
  3. def SMAvgLocalMax(self, src):
  4. # size
  5. stepsize = pySaliencyMapDefs.default_step_local
  6. width = src.shape[1]
  7. height = src.shape[0]
  8. # find local maxima
  9. numlocal = 0
  10. lmaxmean = 0
  11. for y in range(0, height-stepsize, stepsize):
  12. for x in range(0, width-stepsize, stepsize):
  13. localimg = src[y:y+stepsize, x:x+stepsize]
  14. lmin, lmax, dummy1, dummy2 = cv2.minMaxLoc(localimg)
  15. lmaxmean += lmax
  16. numlocal += 1
  17. # averaging over all the local regions
  18. return lmaxmean / numlocal
  19. # normalization specific for the saliency map model

开发者ID:tyarkoni,项目名称:pliers,代码行数:19,代码来源:pySaliencyMap.py


 

示例16: matchAB

​ 点赞 6 ​

  1. # 需要导入模块: import cv2 [as 别名]
  2. # 或者: from cv2 import minMaxLoc [as 别名]
  3. def matchAB(fileA, fileB):
  4. # 读取图像数据
  5. imgA = cv2.imread(fileA)
  6. imgB = cv2.imread(fileB)
  7. # 转换成灰色
  8. grayA = cv2.cvtColor(imgA, cv2.COLOR_BGR2GRAY)
  9. grayB = cv2.cvtColor(imgB, cv2.COLOR_BGR2GRAY)
  10. # 获取图片A的大小
  11. height, width = grayA.shape
  12. # 取局部图像,寻找匹配位置
  13. result_window = np.zeros((height, width), dtype=imgA.dtype)
  14. for start_y in range(0, height-100, 10):
  15. for start_x in range(0, width-100, 10):
  16. window = grayA[start_y:start_y+100, start_x:start_x+100]
  17. match = cv2.matchTemplate(grayB, window, cv2.TM_CCOEFF_NORMED)
  18. _, _, _, max_loc = cv2.minMaxLoc(match)
  19. matched_window = grayB[max_loc[1]:max_loc[1]+100, max_loc[0]:max_loc[0]+100]
  20. result = cv2.absdiff(window, matched_window)
  21. result_window[start_y:start_y+100, start_x:start_x+100] = result
  22. plt.imshow(result_window)
  23. plt.show()

开发者ID:cangyan,项目名称:image-detect,代码行数:27,代码来源:image_detect_02.py


 

示例17: detect

​ 点赞 6 ​

  1. # 需要导入模块: import cv2 [as 别名]
  2. # 或者: from cv2 import minMaxLoc [as 别名]
  3. def detect(self, z, x):
  4. k = self.gaussianCorrelation(x, z)
  5. res = real(fftd(complexMultiplication(self._alphaf, fftd(k)), True))
  6. _, pv, _, pi = cv2.minMaxLoc(res) # pv:float pi:tuple of int
  7. p = [float(pi[0]), float(pi[1])] # cv::Point2f, [x,y] #[float,float]
  8. if(pi[0]>0 and pi[0]<res.shape[1]-1):
  9. p[0] += self.subPixelPeak(res[pi[1],pi[0]-1], pv, res[pi[1],pi[0]+1])
  10. if(pi[1]>0 and pi[1]<res.shape[0]-1):
  11. p[1] += self.subPixelPeak(res[pi[1]-1,pi[0]], pv, res[pi[1]+1,pi[0]])
  12. p[0] -= res.shape[1] / 2.
  13. p[1] -= res.shape[0] / 2.
  14. return p, pv

开发者ID:uoip,项目名称:KCFnb,代码行数:18,代码来源:kcftracker.py


 

示例18: image_search

​ 点赞 5 ​

  1. # 需要导入模块: import cv2 [as 别名]
  2. # 或者: from cv2 import minMaxLoc [as 别名]
  3. def image_search(x_start :int, y_start :int, x_end :int, y_end :int,
  4. img :str, threshold :int, bmp :image =None) -> Optional[Tuple[int, int]]:
  5. """Search the screen for the supplied picture.
  6. Returns a tuple with x,y-coordinates, or None if result is below
  7. the threshold.
  8. Keyword arguments:
  9. image -- Filename or path to file that you search for.
  10. threshold -- The level of fuzziness to use - a perfect match will be
  11. close to 1, but probably never 1. In my testing use a
  12. value between 0.7-0.95 depending on how strict you wish
  13. to be.
  14. bmp -- a bitmap from the get_bitmap() function, use this if you're
  15. performing multiple different OCR-readings in succession
  16. from the same page. This is to avoid to needlessly get the
  17. same bitmap multiple times. If a bitmap is not passed, the
  18. function will get the bitmap itself. (default None)
  19. """
  20. if not bmp: bmp = Inputs.get_bitmap()
  21. # Bitmaps are created with a 8px border
  22. search_area = bmp.crop((x_start + 8, y_start + 8,
  23. x_end + 8, y_end + 8))
  24. search_area = numpy.asarray(search_area)
  25. search_area = cv2.cvtColor(search_area, cv2.COLOR_RGB2GRAY)
  26. template = cv2.imread(img, 0)
  27. res = cv2.matchTemplate(search_area, template, cv2.TM_CCOEFF_NORMED)
  28. _, max_val, _, max_loc = cv2.minMaxLoc(res)
  29. if max_val < threshold:
  30. return None
  31. return max_loc

开发者ID:kujan,项目名称:NGU-scripts,代码行数:34,代码来源:inputs.py


 

示例19: MatchTemplate

​ 点赞 5 ​

  1. # 需要导入模块: import cv2 [as 别名]
  2. # 或者: from cv2 import minMaxLoc [as 别名]
  3. def MatchTemplate(template, target):
  4. """Returns match score for given template"""
  5. res = cv2.matchTemplate(target, template, cv2.TM_CCOEFF_NORMED)
  6. min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res)
  7. return max_val

开发者ID:cfircohen,项目名称:airport,代码行数:7,代码来源:solver.py


 

示例20: match_img

​ 点赞 5 ​

  1. # 需要导入模块: import cv2 [as 别名]
  2. # 或者: from cv2 import minMaxLoc [as 别名]
  3. def match_img(self, image, target, value, rematch=False):
  4. """
  5. :param image: 原始图片
  6. :param target: 匹配模板
  7. :param value: 匹配阈值
  8. :param rematch: false,初赛水印,true复赛水印
  9. :return: 水印外轮廓坐标,原始图片灰度图,水印内轮廓
  10. """
  11. img_rgb = cv2.imread(image)
  12. h, w, c = img_rgb.shape
  13. img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY)
  14. template = cv2.imread(target, 0)
  15. th, tw = template.shape
  16. max_v1 = 0
  17. if not rematch:
  18. template = template[16:56, 20:186]
  19. else:
  20. template = template[18:107, 19:106]
  21. res = cv2.matchTemplate(img_gray, template, cv2.TM_CCOEFF_NORMED)
  22. threshold = value
  23. min_v, max_v, min_pt, max_pt = cv2.minMaxLoc(res)
  24. if max_v < threshold:
  25. return False, False, False
  26. if not rematch:
  27. template1 = cv2.imread(self.roi_rematch_img_path, 0)
  28. template1 = template1[18:107, 19:106]
  29. res1 = cv2.matchTemplate(img_gray, template, cv2.TM_CCOEFF_NORMED)
  30. min_v1, max_v1, min_pt1, max_pt1 = cv2.minMaxLoc(res1)
  31. if max_v < max_v1: # 避免两种水印匹配重叠的情况
  32. return False, False, False
  33. if not rematch:
  34. x = 20
  35. y = 16
  36. else:
  37. x = 19
  38. y = 18
  39. ori_pt = (min(w - tw - 1, max(max_pt[0] - x, 0)), max(0, min(max_pt[1] - y, h - th - 1)))
  40. return ori_pt, img_gray, max_pt

开发者ID:Mingtzge,项目名称:2019-CCF-BDCI-OCR-MCZJ-OCR-IdentificationIDElement,代码行数:40,代码来源:watermask_process.py


 

示例21: compare_a_template

​ 点赞 5 ​

  1. # 需要导入模块: import cv2 [as 别名]
  2. # 或者: from cv2 import minMaxLoc [as 别名]
  3. def compare_a_template(img_gray, template): # 函数返回模板匹配的最大值
  4. """
  5. 将图片与模板对比,比较相似度
  6. :param img_gray: 灰度图片
  7. :param template: 模板图片
  8. :return: 相似度,介于[0,1]
  9. """
  10. #img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) # 转为灰度图
  11. res = cv2.matchTemplate(img_gray, template, cv2.TM_CCOEFF_NORMED) # 模板匹配
  12. _, max_val, _, _ = cv2.minMaxLoc(res)
  13. return max_val # 返回的是归一化的相似度的最大值,值位于0-1之间

开发者ID:Mingtzge,项目名称:2019-CCF-BDCI-OCR-MCZJ-OCR-IdentificationIDElement,代码行数:13,代码来源:twist_part.py


 

示例22: match_template1

​ 点赞 5 ​

  1. # 需要导入模块: import cv2 [as 别名]
  2. # 或者: from cv2 import minMaxLoc [as 别名]
  3. def match_template1(template, img, plot=False, method=cv2.TM_SQDIFF_NORMED):
  4. img = cv2.imread(img, 0).copy()
  5. template = cv2.imread(template, 0)
  6. w, h = template.shape[::-1]
  7. if lib == OPENCV:
  8. res = cv2.matchTemplate(img, template, method)
  9. min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res)
  10. if method in [cv2.TM_SQDIFF, cv2.TM_SQDIFF_NORMED]:
  11. top_left = min_loc
  12. else:
  13. top_left = max_loc
  14. else:
  15. result = match_template(img, template)
  16. ij = np.unravel_index(np.argmax(result), result.shape)
  17. top_left = ij[::-1]
  18. bottom_right = (top_left[0] + w, top_left[1] + h)
  19. if plot:
  20. cv2.rectangle(img, top_left, bottom_right, 255, 5)
  21. plt.subplot(121)
  22. plt.imshow(img)
  23. plt.title('Detected Point'), plt.xticks([]), plt.yticks([])
  24. plt.subplot(122)
  25. plt.imshow(template)
  26. plt.show()
  27. return top_left, bottom_right

开发者ID:tobyqin,项目名称:kog-money,代码行数:31,代码来源:match.py


 

 

注:本文中的cv2.minMaxLoc方法示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/79124
推荐阅读
相关标签
  

闽ICP备14008679号