I'm having problems with using OpenCV, Python, Tkinter and PiCamera in a program.
A Tkinter window is used to display and set the values to be used in OpenCV:
I am trying to continuously read and process the video feed from PiCamera currently I am using:
while True: for frame in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True): root.update_idletasks()
But after some reading on internet I found that using update()
is not advisable, so I tried my luck to understand threading but I failed. There are a lot of examples with VideoCapture()
which is used with USB cameras but not a lot with PiCamera. Is there any other way than threading?
You can use root.after(...)
. Below is a sample code:
# define a variable used to stop the image capture
do_image_capture = True
def capture_image():
if do_image_capture:
camera.capture(rawCapture, format='bgr', use_video_port=True)
# do whatever you want on the captured data
...
root.after(100, capture_image) # adjust the first argument to suit your case
capture_image()
Below sample code is using thread:
import threading
stop_image_capture = False
def capture_image():
for frame in camera.capture_continuous(rawCapture, format='bgr', use_video_port=True)
# do whatever you want on the capture image
....
if stop_image_capture:
break
t = threading.Thread(target=capture_image)
t.setDaemon(True)
t.start()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.