[英]Why cv2 is throwing bad argument error? How can I run it successfully?
I have declared all variables as global I m using tkinter interface for dipalying image我已将所有变量声明为全局变量,我使用 tkinter 接口进行图像处理
global img, img1,img2,img3
Here are the two function used for displaying这里有两个function用于显示
def hist():
global img2,img3
transform = transforms.Grayscale()
img2 = transform(img2)
img2 = ImageOps.equalize(img2,mask=None)
img2 = img2.resize((180, 180))
img2 = ImageTk.PhotoImage(img2)
canvas9.create_image(96, 96, image=img2)
canvas9.place(x=730,y=60)
After running this function I m getting error In this I m copying img2 in img3 and I am facing problem运行此 function 后出现错误在此我将 img2 复制到 img3 中,我遇到了问题
def rgb():
global img3,img2
img3 = img2.copy()
img3=cv2.cvtColor(img3,cv2.COLOR_BGR2RGB)
img3 = img3.resize((180, 180))
img3 = ImageTk.PhotoImage(img3)
canvas10.create_image(96, 96, image=img3)
canvas10.place(x=370,y=320)
Error错误
This is the error I m getting这是我得到的错误
File "C:\python310\lib\tkinter\__init__.py", line 1921, in __call__
return self.func(*args)
File "C:\Users\ABHISHEK\PycharmProjects\cervical_project\gui.py", line 23, in rgb
img3=cv2.cvtColor(img3,cv2.COLOR_BGR2RGB)
cv2.error: OpenCV(4.5.5) :-1: error: (-5:Bad argument) in function 'cvtColor'
> Overload resolution failed:
> - src is not a numpy array, neither a scalar
> - Expected Ptr<cv::UMat> for argument 'src'
You're mixing OpenCV/numpy and PIL indiscriminately.您正在不加选择地混合 OpenCV/numpy 和 PIL。
img3 = img2.copy()
img3 = cv2.cvtColor(img3, cv2.COLOR_BGR2RGB)
So you're actually using img2
.所以你实际上是在使用
img2
。 What is it?它是什么?
img2 = ImageTk.PhotoImage(img2)
Tk PhotoImages are not compatible with OpenCV. Tk PhotoImages 与 OpenCV 不兼容。
Check the type yourself:自己检查类型:
print(type(img3)) # right before calling cvtColor
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.