Guigui
Guigui

Reputation: 11

OpenCV(4.5.5) :-1: error: (-5:Bad argument) in function 'imshow'

I have this error : OpenCV(4.5.5) :-1: error: (-5:Bad argument) in function 'imshow'

Overload resolution failed:

  • mat data type = 18 is not supported
  • Expected Ptr<cv::cuda::GpuMat> for argument 'mat'
  • Expected Ptr<cv::UMat> for argument 'mat'

with this code :

fname = "img.jpeg"
    for i in range (0,10):
        f = open(fname, "wb")
        buf = np.array(ws.recv())
        f.write(buf)
        f.flush()
        f.close()
        cv2.imshow('frame', buf)
        if cv2.waitKey(20) & 0xFF == ord('q'):
            break

    cv2.destroyAllWindows()
    ws.close()
except Exception as e:
    print(e)

If someone can understand this error, it would help me a lot. Thanks.

Upvotes: 0

Views: 5587

Answers (1)

Markus
Markus

Reputation: 6298

cv2.imshow doesn't support binary buffers with image data. The respective image format has to be unpacked and arranged in a proper shape as raw data. To do this don't implement your own import procedure but use cv2.imread and you get the image data in a format that opencv can process:

img = cv2.imread('img.jpg')
cv2.imshow('frame', img)

Upvotes: 1

Related Questions