Issue
I started to learn OpenCV today and faced a small problem:
cv2.error: OpenCV(4.6.0) :-1: error: (-5:Bad argument) in function 'imshow'
You can use this issue just to warm up before going to solve more complicated questions:)
Thank you!
The code:
import cv2 as cv
img = R'Photos and videos\Photos and videos\Dogs photo.jpg'
cv.imread = img
cv.imshow("Dog", img)
cv.waitKey(0)
The Error:
Traceback (most recent call last):
File "C:\Program Files\Python310\lib\runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Program Files\Python310\lib\runpy.py", line 86, in _run_code
exec(code, run_globals)
File "C:\Users\Admin\PycharmProjects\pythonProject1\read.py", line 7, in <module>
cv.imshow("Dog", img)
cv2.error: OpenCV(4.6.0) :-1: error: (-5:Bad argument) in function 'imshow'
> Overload resolution failed:
> - mat is not a numpy array, neither a scalar
> - Expected Ptr<cv::cuda::GpuMat> for argument 'mat'
> - Expected Ptr<cv::UMat> for argument 'mat'
Solution
cv.imread()
is a function which takes in a "path" as an argument, so you need to pass the path to your image to it and it will then return the CV2 Image object, which you can pass that imshow()
to display.
import cv2 as cv
path = R'Photos and videos\Photos and videos\Dogs photo.jpg'
img = cv.imread(path)
cv.imshow("Dog", img)
cv.waitKey(0)
Answered By - Vorkos
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.