I am making a funktion that calls itself, but i'm getting error: RecursionError: maximum recursion depth exceeded while calling a Python object, Is there a way around this. More specifically i am getting it for line 35, ok, frame = cap.read() I cant put a while loop because of the .after funktion in my program.
import cv2
from tkinter import *
import PIL
from PIL import Image, ImageTk
root = Tk()
root.bind('<Escape>', lambda e: root.quit())
lmain = Label(root)
lmain.pack()
print("[INFO] Making variables")
ImageSource = 0
window_name = "AutoCam"
width = 600
height = 800
cap = cv2.VideoCapture(ImageSource)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, width)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, height)
print("[INFO] Made variables ")
def ShowFrame(frame):
print("[INFO] making image.")
cv2image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGBA)
img = PIL.Image.fromarray(cv2image)
imgtk = ImageTk.PhotoImage(image=img)
lmain.imgtk = imgtk
lmain.configure(image=imgtk)
print("[INFO] After 10 initializing")
lmain.after(10, CheckSource)
print("[INFO] Showed image")
def CheckSource():
ok, frame = cap.read()
if ok:
print("[INFO] Ok is triggered")
if cv2.waitKey(1) & 0xFF == ord('q'):
cv2.destroyAllWindows()
cv2.waitKey(0)
print("[INFO] Exiting app after command")
ShowFrame(frame)
else:
lmain.after(10, CheckSource())
CheckSource()
root.mainloop()
Any and all help would be very appreciated. Could someone also explain how to avoid this for future use?
[EDIT]
the error message is:
Traceback (most recent call last):
File "C:/Users/Gotta/Documents/AutoCamPy.py", line 52, in <module>
CheckSource()
File "C:/Users/Gotta/Documents/AutoCamPy.py", line 49, in CheckSource
lmain.after(10, CheckSource())
File "C:/Users/Gotta/Documents/AutoCamPy.py", line 49, in CheckSource
lmain.after(10, CheckSource())
File "C:/Users/Gotta/Documents/AutoCamPy.py", line 49, in CheckSource
lmain.after(10, CheckSource())
[Previous line repeated 995 more times]
File "C:/Users/Gotta/Documents/AutoCamPy.py", line 35, in CheckSource
ok, frame = cap.read()
RecursionError: maximum recursion depth exceeded while calling a Python
object
.after(..., CheckSource())- change to.after(..., CheckSource)- Mulan