0

I was trying to build a small application in python, that has a Tkinter GUI and a seperate video feed from Simple Cv. I've written a bigger code, but for testing I've written a small snippet here. What this basically does is, creates an instance of the Tkinter window and creates an instance of the camera and displays the feed.

But on execution the feed freezes but the Tkinter windows works well.. Any suggestions?? I've tried adding a while loop, but my PC freezes.

from Tkinter import*
import ttk
from SimpleCV import*
root = Tk()
cam1 = Camera()
vid  = cam1.getImage()
vid.show()

#W = Canvas(root, width = 500, height = 500).pack()
root.geometry('1000x1000')
root.mainloop()
  • `Camera.getImage()` isn't any sort of "feed", it just grabs a single frame from the camera. To get live video, you'd need to call it repeatedly (using Tkinter's `after()` mechanism; a loop would just lock up your GUI). Surely there are some existing examples of this... – jasonharper May 01 '17 at 13:30
  • Could you please give me some more insight of Tkinter's after() in this scenario? –  May 01 '17 at 14:41
  • You'd have a function that grabs a frame, and updates a Tkinter widget to show that image. In the function, you'd do `widget.after(100, nameOfThisFunction)` to reschedule the function for 100ms later (`widget` being a reference to any Tkinter widget or window). That would try to update at 10 frames per second, I don't know if that's a practical speed or not. – jasonharper May 01 '17 at 14:52
  • Wait this is like a recursive function rite? –  May 01 '17 at 15:02
  • Not exactly, an actual recursive function would lock up the GUI just like a loop - until it killed your program due to stack overflow. `after` is asking Tkinter to call a specific function at a later time: the function doesn't actually call itself. – jasonharper May 01 '17 at 15:08
  • What widget should i use? Canvas? and what attributes do i give it? –  May 01 '17 at 15:10
  • A Label is the simplest widget that can display an image, although I have no idea if SimpleCV's images are directly compatible (I've never used it myself). Surely there is some example code out there that does just this. – jasonharper May 01 '17 at 15:18

0 Answers0