Skip to content

Instantly share code, notes, and snippets.

@ochilab
Last active March 9, 2020 13:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ochilab/a834e568c0c51999ecf979a0cb43e0f7 to your computer and use it in GitHub Desktop.
Save ochilab/a834e568c0c51999ecf979a0cb43e0f7 to your computer and use it in GitHub Desktop.
Tkinterでのカメラ映像表示
root=tk.Tk()
root.title("RGB Recorder")
root.geometry("800x600")
root.resizable(width=False, height=False)
canvas=tk.Canvas(root, width=640, height=480, bg="white")
canvas.pack()
def update():#update
global img
global camera
ret, frame =camera.read()
#TkInterで表示できる形式に変換する
img=ImageTk.PhotoImage(Image.fromarray(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)))
canvas.create_image(w/2,h/2,image=img)
root.after(1,update) #本関数を再帰的に呼び出す
#Cameraの設定などは省略してます
update()
root.mainloop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment