[英]error: (-215) ssize.width > 0 && ssize.height > 0 in function resize
[英]error: C:\projects\opencv-python\opencv\modules\imgproc\src\imgwarp.cpp:3483: error: (-215) ssize.width > 0 && ssize.height > 0 in function cv::resize
我在以下代码中的问题中提到了cv2的调整大小功能的错误。 我在这里提到了错误:(-215)函数调整大小时ssize.width> 0 && ssize.height> 0
但是我认为图像已正确加载。 因此,我将感谢您的帮助。
for rect in rects:
# Draw the rectangles
cv2.rectangle(im, (rect[0], rect[1]), (rect[0] + rect[2], rect[1] + rect[3]), (0, 255, 0), 3)
# Make the rectangular region around the digit
leng = int(rect[3] * 1.6)
pt1 = int(rect[1] + rect[3] // 2 - leng // 2)
pt2 = int(rect[0] + rect[2] // 2 - leng // 2)
roi = im_th[pt1:pt1+leng, pt2:pt2+leng]
print(roi.shape)
# Resize the image
roi = cv2.resize(roi, None, fx=28, fy=28, interpolation=cv2.INTER_LINEAR)
roi = cv2.dilate(roi, (3, 3))
# Calculate the HOG features
roi_hog_fd = hog(roi, orientations=9, pixels_per_cell=(14, 14), cells_per_block=(1, 1), visualise=False)
roi_hog_fd = pp.transform(np.array([roi_hog_fd], 'float64'))
nbr = clf.predict(roi_hog_fd)
cv2.putText(im, str(int(nbr[0])), (rect[0], rect[1]),cv2.FONT_HERSHEY_DUPLEX, 2, (0, 255, 255), 3)
我想您正在进行某种检测,并且得到的结果是rects
。 当一个rect
超出边界时,我也遇到了您遇到的问题。
以我为例,我找到了rect startX, startY, endX, endY
的4个协调器,然后检查它们是否在边界之外。
if (startX<0 or startY<0 or endX > W or endY > H): break
希望它能解决您的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.