使用OpenCV读取图像并使用Tkinter显示

7 python opencv tkinter python-2.7

我在Ubuntu 14.04 LTS上有一个非常简单的程序来使用OpenCV读取和显示图像:

import cv2 #import OpenCV

img = cv2.imread('picture.jpg') #read a picture using OpenCV
cv2.imshow('image',img) # Display the picture
cv2.waitKey(0) # wait for closing
cv2.destroyAllWindows() # Ok, destroy the window
Run Code Online (Sandbox Code Playgroud)

我的问题:

如何在OpenCV中继续阅读图片但使用Tkinter显示?

我问这个是因为我想为我的程序创建一个接口,但OpenCV无法做到这一点所以我需要Tkinter.但是,我必须使用OpenCV在后台进行所有图像处理.只显示结果必须使用Tkinter完成.

编辑:

从上面的答案,我改变了行:

im = Image.open('slice001.hrs').convert2byte()
Run Code Online (Sandbox Code Playgroud)

至:

im=cv2.imread() # (I imported cv2) 
Run Code Online (Sandbox Code Playgroud)

但是我收到了一个错误.

我会很感激任何提示.

Ha *_*ang 11

你可能想看一下这个.这对我有用:

import numpy as np
import cv2
import Tkinter 
import Image, ImageTk

# Load an color image
img = cv2.imread('img.png')

#Rearrang the color channel
b,g,r = cv2.split(img)
img = cv2.merge((r,g,b))

# A root window for displaying objects
root = Tkinter.Tk()  

# Convert the Image object into a TkPhoto object
im = Image.fromarray(img)
imgtk = ImageTk.PhotoImage(image=im) 

# Put it in the display window
Tkinter.Label(root, image=imgtk).pack() 

root.mainloop() # Start the GUI
Run Code Online (Sandbox Code Playgroud)