【问题标题】:error: C:\projects\opencv-python\opencv\modules\imgproc\src\imgwarp.cpp:3483: error: (-215) ssize.width > 0 && ssize.height > 0 in function cv::resize错误:C:\projects\opencv-python\opencv\modules\imgproc\src\imgwarp.cpp:3483:错误:(-215) ssize.width > 0 && ssize.height > 0 in function cv::resize
【发布时间】:2018-05-15 12:32:51
【问题描述】:

我有一个错误,如下面的代码中的问题所述,用于调整 cv2 的大小功能。我在这里提到过 error: (-215) ssize.width > 0 && ssize.height > 0 in function resize

但我认为图像已正确加载。所以我会很感激一些帮助。

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)

【问题讨论】:

  • 出现错误前print(roi.shape) 会打印什么?
  • 它给出 (128,0)
  • 所以你的图片尺寸为0,你不能调整它的大小。确保leng 至少为 1。
  • 哦,实际上,我使用 cv2.imread() 读取的原始图像的大小为 (546, 768)。
  • 但您正在调整 roi 的大小,而不是您的原始图像

标签: python opencv image-resizing


【解决方案1】:

我想你正在做某种检测,你得到的结果是rects。当rect 越界时,我也遇到了您遇到的问题。

就我而言,我找到了 rect startX, startY, endX, endY 的 4 个协调员,然后检查他们是否超出了边界。

if (startX<0 or startY<0 or endX > W or endY > H): break

希望它能解决你的问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-07
    • 2020-10-13
    • 2020-09-03
    相关资源
    最近更新 更多