0

I am new to python and I am stuck with this problem. I want to create a window that would have an entry box for threshold, which would then be used to make a binary image from camera. The binary image would then be live streamed in another(or even better: the same) window. I've written this code so far:

from picamera.array import PiRGBArray
from picamera import PiCamera
import time
import cv2
import imutils
from Tkinter import*


def go():

    thr=int(x.get())


window=Tk()
window.title("Test")
window.geometry('800x480')

Label (window, text="Input threshold:").grid(row=0,column=0,sticky=W)
x=Entry(window, width=10, bg="white")
x.grid(row=1,column=0,sticky=W)

Button(window,text="Go!",width=6,command=go).grid(row=0,column=1,sticky=W)



camera=PiCamera()
rawCapture=PiRGBArray(camera)
camera.resolution=(640,480)
camera.framerate=32
rawCapture=PiRGBArray(camera,size=(640,480))

time.sleep(0.1)

for frame in camera.capture_continuous(rawCapture,format="bgr",use_video_port=True):



    image=frame.array

    qray=cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
    cv2.imshow("Blackwhite",qray)
    thresh=cv2.threshold(qray,thr,255,cv2.THRESH_BINARY)[1]
    cv2.imshow("thresh",thresh)




    key=cv2.waitKey(1) & 0xFF
    rawCapture.truncate(0)

    if key == ord("q"):

        break



window.mainloop()

The problem is that in this code there are two loops which cannot run simultaneously. How would I combine them?

Thank you for your help

  • look at some simple examples of multithreading, launch your camera stream into another thread, then you can set the threshold variable from you gui (main) thread – Chad G Apr 11 '18 at 16:49

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.