简体   繁体   English

OpenCV 调整大小错误(-215:断言失败)

[英]OpenCV resize error(-215:Assertion Failed)

This is my code for building a linear classifier for images and cv2.resize() is throwing error while converting the image from original size to (32,32)这是我为图像构建线性分类器的代码,并且 cv2.resize() 在将图像从原始大小转换为 (32,32) 时抛出错误

import numpy as np
import cv2

labels = ["dog","cat","panda"]
np.random.seed(1)

W = np.random.randn(3,3072)
b = np.random.randn(3)

orig = cv2.imread("panda_00001.png")
image = cv2.resize(orig,(32,32)).flatten()

scores = W.dot(image) + b

for (label,score) in zip(labels,scores):
    print("[INFO] {}:{:.2f}".format(label,score))

cv2.putText(orig,"Label:{}".format(labels[np.argmax(scores)]),(10,30),cv2.FONT_HERSHEY_SIMPLEX,0.9,(0,255,0),2)

cv2.imshow("Image",orig)
cv2.waitkey(0)

Getting this error on execution执行时出现此错误

Traceback (most recent call last):
  File "linearclassifier.py", line 11, in <module>
    image = cv2.resize(orig,(32,32)).flatten()
cv2.error: OpenCV(4.3.0) C:\projects\opencv-python\opencv\modules\imgproc\src\resize.cpp:3929: error: (-215:Assertion failed) !ssize.empty() in function 'cv::resize'

Your picture path seems to be wrong or invalid.您的图片路径似乎错误或无效。

It's always good practice to integrate a null check to the read picture in your script:将 null 检查集成到脚本中的读取图片始终是一种好习惯:

eg:例如:

import cv2
... 
img = cv2.imread("myImage.jpg")

if (img.size == 0):
   # error handling or throw exception here!

# do stuff with image here 

暂无
暂无

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

相关问题 python OpenCV(3.4.2)错误:(-215:断言失败) - python OpenCV(3.4.2) error: (-215:Assertion failed) 错误: (-215:Assertion failed) 使用 openCV 时 - error: (-215:Assertion failed) while using openCV 错误: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' cv2.resize() - 错误 - OpenCV(4.2.0) - 错误:(-215:Assertion failed) - 循环图像 - cv2.resize() - error - OpenCV(4.2.0) - error: (-215:Assertion failed) - loop over images error (-215:Assertion failed).ssize.empty() in function opencv 中的“resize”在 Macos 上没有问题,但 ZAEA23489CE3AA9B6400ZEBB28E0CDA4 出现错误 - error (-215:Assertion failed) !ssize.empty() in function 'resize' in opencv had no problem on Macos but error occur with Windows OpenCV(4.1.2) 错误: (-215:Assertion failed).ssize:empty() in function 'cv::resize' - OpenCV(4.1.2) error: (-215:Assertion failed) !ssize.empty() in function 'cv::resize' 此错误的问题: (-215:Assertion failed).ssize:empty() in function 'cv::resize' OpenCV - Problem with this error: (-215:Assertion failed) !ssize.empty() in function 'cv::resize' OpenCV 在函数 &#39;cv::resize&#39; 中检索 opencv 错误(-215:Assertion failed)!ssize.empty() - Retrieving opencv error (-215:Assertion failed) !ssize.empty() in function 'cv::resize' OpenCV2 错误:(-215:Assertion failed) 'cv::resize' while training the model - OpenCV2 error: (-215:Assertion failed) 'cv::resize' while training the model 错误:OpenCV(4.2.0)C:\projects\opencv-python\opencv\modules\imgproc\src\resize.cpp:4045:错误:(-215:断言失败) - error: OpenCV(4.2.0) C:\projects\opencv-python\opencv\modules\imgproc\src\resize.cpp:4045: error: (-215:Assertion failed)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM