![](/img/trans.png)
[英]I am using python and opencv to take an image; however, the image quality is not displaying the correct size image
[英]Search image inside of image and take the coodinates using python
我需要在一張圖片中搜索另一張圖片並獲取坐標。 我試着吼叫。 但如果找不到圖像,它不會停止。它顯示錯誤的坐標。 我知道,它正在顯示最大值。 所以我什至嘗試添加“如果線程......但這不是好的解決方案。有沒有其他方法比這更准確?或像素匹配方法?
代碼:
import cv2
method = cv2.TM_SQDIFF_NORMED
# Read the images from the file
small_image = cv2.imread('c3.jpg')
large_image = cv2.imread('screenPls.png')
result = cv2.matchTemplate(small_image, large_image, method)
# We want the minimum squared difference
mn, lk, mnLoc, _ = cv2.minMaxLoc(result)
# Draw the rectangle:
# Extract the coordinates of our best match
MPx, MPy = mnLoc
# Step 2: Get the size of the template.This is the same size as the match.
trows, tcols = small_image.shape[: 2]
# Step 3: Draw the rectangle on large_image
cv2.rectangle(large_image, (MPx, MPy), (MPx + tcols, MPy + trows), (0, 0, 255), 2)
# Display the original image with the rectangle around the match.
cv2.imshow('output', large_image)
# The image is only displayed
cv2.waitKey(0)
您只是喜歡使用帶有“if”的 squareError 閾值。 即使當你使用一個正好在大圖像內的小圖像時,錯誤也不會為 0。所以這樣做吧。
lats取閾值為0.01
if mn < 0.01:
MPx, MPy = mnLoc
# Step 2: Get the size of the template.This is the same size as the match.
trows, tcols = small_image.shape[: 2]
# Step 3: Draw the rectangle on large_image
cv2.rectangle(large_image, (MPx, MPy), (MPx + tcols, MPy + trows), (0, 0, 255), 2)
# Display the original image with the rectangle around the match.
cv2.imshow('output', large_image)
# The image is only displayed
cv2.waitKey(0)
那可行
然而,搜索內部圖像的最佳方式是“機器學習”
這在計算上是昂貴的,但它會最准確地識別對象。 但也有局限性。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.