【发布时间】:2015-01-29 15:05:56
【问题描述】:
我正在编写一个用于测试 opencv 函数的小 gui - 以轻松更改参数值(用于阈值、斑点检测等)。我开始使用 tkinter 编写 gui,并使用 Image.fromarray 函数得到奇怪的结果——我的图像变成了蓝色;当我用 cv2.imshow 显示时,没有这样的色调,所以它必须是 fromarry 的人工制品,我 blv。我按预期检查了模式及其 RGB。图像对在斑点检测之前和之后(绘制小圆圈)。左对是 opencv,右对在我的 tkinter gui 中。
tk_img=Image.fromarray(newImg)
tk_photo=ImageTk.PhotoImage(tk_img)
mod=tk_img.mode
print('mode:'+str(mod))
label1 = Tkinter.Label(self, image=tk_photo)
label1.image = tk_photo
label1.grid(row = Imrow, column = Im2col, columnspan = Im2col, sticky=Tkinter.NW)
self.update()
cv2.imshow('orig', currentImg)
cv2.waitKey(0)
cv2.imshow('current', newImg)
cv2.waitKey(0)
cv2.destroyAllWindows()
【问题讨论】:
-
所以我做了一个笨拙的解决方法,将图像保存到临时文件并读取:r=cv2.imwrite('temp.jpg',img) tk_img = Image.open('temp.jpg' )tk_photo=ImageTk.PhotoImage(tk_img)
-
我会看看枕头是否有同样的效果,或者这是否已在补丁中修复。 (Pillow 也可以在 3.x 上运行。)
标签: python opencv tkinter python-imaging-library