简体   繁体   English

OpenCV(3.4.2): error: (-215:Assertion failed) with Template Matching Method

[英]OpenCV(3.4.2): error: (-215:Assertion failed) with Template Matching Method

I'm using normalization as a preprocessing method with Template Matching.我使用规范化作为模板匹配的预处理方法。 However, I faced an error when I run the code但是,我在运行代码时遇到了错误

Error: error: OpenCV(3.4.2) /opt/concourse/worker/volumes/live/9523d527-1b9e-48e0-7ed0-a36adde286f0/volume/opencv-suite_1535558719691/work/modules/imgproc/src/templmatch.cpp:1102: error: (-215:Assertion failed) (depth == 0 || depth == 5) && type == _templ.type() && _img.dims() <= 2 in function 'matchTemplate'错误:错误:OpenCV(3.4.2)/opt/concourse/worker/volumes/live/9523d527-1b9e-48e0-7ed0-a36adde286f0/volume/opencv-suite_1535558719691/work/modules/imgproc/src/templ10 : 错误: (-215:Assertion failed) (depth == 0 || depth == 5) && type == _templ.type() && _img.dims() <= 2 in function 'matchTemplate'

This my preprocessing method:这是我的预处理方法:

def Image_Preprocessing (image):
    Gray_image = cv2.cvtColor(image , cv2.COLOR_BGR2GRAY)  # converting the image to grayscale image
    resized_image = cv2.resize(Gray_image, (width, height))  # Resize the image 
    mean, stdDev = cv2.meanStdDev(resized_image)  #Get Mean and Standard-deviation
    Normalized_image = (resized_image-mean)/stdDev  #Normalize the image  
    # Scale the normalized values to integer range
    Normalized_image -= Normalized_image.min() 
    Normalized_image /= Normalized_image.max()
    Normalized_image *= 255 # [0, 255] range

    return  Normalized_image

How I can solve this problem?我该如何解决这个问题?

In any case, you should verify @HansHirse 's answer, if the problem even is your preprocessing, you can try this:在任何情况下,您都应该验证@HansHirse 的答案,如果问题甚至是您的预处理,您可以试试这个:

def Image_Preprocessing (image):
    Gray_image = cv2.cvtColor(image , cv2.COLOR_BGR2GRAY)  # converting the image to grayscale image
    resized_image = cv2.resize(Gray_image, (width, height))  # Resize the image
    Normalized_image = np.array(np.divide(resized_image, np.amax(resized_image)), dtype=np.float64) # Normalizes to float 0 - 1, ensure float
    # Scale the normalized values to integer range
    Normalized_image *= 255 # [0, 255] range
    Normalized_image = np.uint8(Normalized_image)

    return  Normalized_image

This returns a uint8 image, if your template is also uint8, there shouldn't be an issue.这将返回一个 uint8 图像,如果您的模板也是 uint8,则应该没有问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 python OpenCV(3.4.2)错误:(-215:断言失败) - python OpenCV(3.4.2) error: (-215:Assertion failed) 如何在 pycharm 中修复此错误? cv2.error: OpenCV(3.4.2) 错误: (-215:Assertion failed) - How to fix this error in pycharm? cv2.error: OpenCV(3.4.2) error: (-215:Assertion failed) OpenCV 调整大小错误(-215:断言失败) - OpenCV resize error(-215:Assertion Failed) 错误: (-215:Assertion failed) 使用 openCV 时 - error: (-215:Assertion failed) while using openCV 错误:(-215:Assertion failed) npoints > 0 while working with contours using OpenCV - Error: (-215:Assertion failed) npoints > 0 while working with contours using OpenCV 如何修复 Opencv arcLength function 错误:(-215:断言失败) - How to fix Opencv arcLength function error: (-215:Assertion failed) Yolov5 OpenCV 错误:(-215:断言失败)同时使用.onnx - Yolov5 OpenCV error: (-215:Assertion failed) whilst using .onnx Python 和 OpenCV:-215:尝试调用 calibrateCamera 时出现断言失败错误 - Python and OpenCV: -215:Assertion failed error when trying to call calibrateCamera OpenCV错误:(-215:断言失败)!_src.empty()在函数&#39;cvtColor&#39;中 - OpenCV error: (-215:Assertion failed) !_src.empty() in function 'cvtColor' 错误:OpenCV(4.1.0) 错误:(-215:Assertion failed) !ssize.empty() in function &#39;cv::resize&#39; - error: OpenCV(4.1.0) error: (-215:Assertion failed) !ssize.empty() in function 'cv::resize'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM