I'm trying to do a simple template matching with openCV-python, but right in the beginning getting an error. I've run the following code:
import cv2 as cv
import numpy as np
haystackImg = cv.imread('fullImage.png', cv.IMREAD_UNCHANGED)
needleImg = cv.imread('diamond.png', cv.IMREAD_UNCHANGED)
result = cv.matchTemplate(haystackImg,needleImg, cv.TM_CCOEFF_NORMED)
cv.imshow('result', result)
cv.waitKey() ```
...and I got this error:
[ WARN:0@0.186] global D:\a\opencv-python\opencv-python\opencv\modules\imgcodecs\src\loadsave.cpp (239) cv::findDecoder imread_('fullImage.png'): can't open/read file: check file path/integrity
[ WARN:0@0.195] global D:\a\opencv-python\opencv-python\opencv\modules\imgcodecs\src\loadsave.cpp (239) cv::findDecoder imread_('diamond.png'): can't open/read
file: check file path/integrity ython39/python.exe "c:/U
Traceback (most recent call last):
File "[myFilePath]\starting.py", line 8, in <modd file: check file path/ule>
result = cv.matchTemplate(haystackImg,needleImg, cv.TM_CCOEFF_NORMED)
cv2.error: OpenCV(4.5.5) D:\a\opencv-python\opencv-python\opencv\modules\imgproc\src\templmatch.cpp:588: error: (-215:Assertion failed) corr.rows <= img.rows +
templ.rows - 1 && corr.cols <= img.cols + templ.cols - 1 in function 'cv::crossCorr'
The confusing part of it, that I didn't even have a D: drive, and the module is searching for something on that. I reinstalled it, but it didn't help.
The problem was, that my source path contained non ASCII characters such as á and é... Created a new location without any non ASCII characters and white-spaces, and it works fine now.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.