템플릿 매칭으로 미키 검사 (python)
5599 단어 Python
의 목적
openCV 템플릿 일치를 사용하여 미키마우스를 감지합니다.
차리다
환경과 환경
오픈 cv 라이브러리를 준비합니다.
원본 이미지 테스트.png
템플릿 이미지 (원본 이미지에서 잘라내기) test1.png
코드
sample.py#coding:utf-8
import cv2
import numpy as np
#画像をグレースケールで読み込む
fname_img1='test1.png'
fname_img2='test2.png'
img = cv2.imread(fname_img1, 0)
temp = cv2.imread(fname_img2, 0)
#マッチングテンプレートを実行
match_result = cv2.matchTemplate(img, temp, cv2.TM_CCOEFF_NORMED)
#類似度の設定(0~1)
threshold = 0.9
#検出結果から検出領域の位置を取得
loc=np.where(match_result >= threshold)
#検出領域を四角で囲んで保存
w, h = temp.shape[::-1]
for top_left in zip(*loc[::-1]):
bottom_right = (top_left[0] + w, top_left[1] + h)
#保存
result = cv2.imread(fname_img1)
#height = img.shape[0]
#width = img.shape[1]
#result = cv2.resize(img , (int(width*1.0), int(height*1.0)))
cv2.rectangle(result,top_left, bottom_right, (255, 0, 0), 10)
cv2.imwrite("result.png", result)
테스트
아래와 같이 검사할 수 있다면 OK result입니다.png
CodingError 대책 libpng warning: Image width is zero in IHDR
libpng warning: Image height is zero in IHDR
libpng error: Invalid IHDR data
imwrite에 지정된 원본 이미지의 크기는 0입니다.
올바른 크기의 이미지 지정 및 해결
참고 자료
템플릿 일치
Python 템플릿 일치, OpenCV 샘플 코드 및 설명
OpenCV를 사용하여 이미지 크기 변경
Reference
이 문제에 관하여(템플릿 매칭으로 미키 검사 (python)), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/seigot/items/7052d0cf0c964c2c3e97
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
환경과 환경
오픈 cv 라이브러리를 준비합니다.
원본 이미지 테스트.png

템플릿 이미지 (원본 이미지에서 잘라내기) test1.png

코드
sample.py#coding:utf-8
import cv2
import numpy as np
#画像をグレースケールで読み込む
fname_img1='test1.png'
fname_img2='test2.png'
img = cv2.imread(fname_img1, 0)
temp = cv2.imread(fname_img2, 0)
#マッチングテンプレートを実行
match_result = cv2.matchTemplate(img, temp, cv2.TM_CCOEFF_NORMED)
#類似度の設定(0~1)
threshold = 0.9
#検出結果から検出領域の位置を取得
loc=np.where(match_result >= threshold)
#検出領域を四角で囲んで保存
w, h = temp.shape[::-1]
for top_left in zip(*loc[::-1]):
bottom_right = (top_left[0] + w, top_left[1] + h)
#保存
result = cv2.imread(fname_img1)
#height = img.shape[0]
#width = img.shape[1]
#result = cv2.resize(img , (int(width*1.0), int(height*1.0)))
cv2.rectangle(result,top_left, bottom_right, (255, 0, 0), 10)
cv2.imwrite("result.png", result)
테스트
아래와 같이 검사할 수 있다면 OK result입니다.png
CodingError 대책 libpng warning: Image width is zero in IHDR
libpng warning: Image height is zero in IHDR
libpng error: Invalid IHDR data
imwrite에 지정된 원본 이미지의 크기는 0입니다.
올바른 크기의 이미지 지정 및 해결
참고 자료
템플릿 일치
Python 템플릿 일치, OpenCV 샘플 코드 및 설명
OpenCV를 사용하여 이미지 크기 변경
Reference
이 문제에 관하여(템플릿 매칭으로 미키 검사 (python)), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/seigot/items/7052d0cf0c964c2c3e97
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
#coding:utf-8
import cv2
import numpy as np
#画像をグレースケールで読み込む
fname_img1='test1.png'
fname_img2='test2.png'
img = cv2.imread(fname_img1, 0)
temp = cv2.imread(fname_img2, 0)
#マッチングテンプレートを実行
match_result = cv2.matchTemplate(img, temp, cv2.TM_CCOEFF_NORMED)
#類似度の設定(0~1)
threshold = 0.9
#検出結果から検出領域の位置を取得
loc=np.where(match_result >= threshold)
#検出領域を四角で囲んで保存
w, h = temp.shape[::-1]
for top_left in zip(*loc[::-1]):
bottom_right = (top_left[0] + w, top_left[1] + h)
#保存
result = cv2.imread(fname_img1)
#height = img.shape[0]
#width = img.shape[1]
#result = cv2.resize(img , (int(width*1.0), int(height*1.0)))
cv2.rectangle(result,top_left, bottom_right, (255, 0, 0), 10)
cv2.imwrite("result.png", result)
아래와 같이 검사할 수 있다면 OK result입니다.png

CodingError 대책 libpng warning: Image width is zero in IHDR
libpng warning: Image height is zero in IHDR
libpng error: Invalid IHDR data
imwrite에 지정된 원본 이미지의 크기는 0입니다.
올바른 크기의 이미지 지정 및 해결
참고 자료
템플릿 일치
Python 템플릿 일치, OpenCV 샘플 코드 및 설명
OpenCV를 사용하여 이미지 크기 변경
Reference
이 문제에 관하여(템플릿 매칭으로 미키 검사 (python)), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/seigot/items/7052d0cf0c964c2c3e97
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
libpng warning: Image width is zero in IHDR
libpng warning: Image height is zero in IHDR
libpng error: Invalid IHDR data
템플릿 일치
Python 템플릿 일치, OpenCV 샘플 코드 및 설명
OpenCV를 사용하여 이미지 크기 변경
Reference
이 문제에 관하여(템플릿 매칭으로 미키 검사 (python)), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/seigot/items/7052d0cf0c964c2c3e97텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)