0

what kind of module, syntax, function or do i need to use classes (oop)? i am still a baby python3, opencv4....please help

gui.py

'''

    from guizero import App, PushButton
    def do_nothing()
            print('Button was pressed')

    app=App()
    button=PushButton(app,command=do_nothing)
    app.display()

'''

main.py

'''

    import numpy as np
    import cv2
    cap = cv2.VideoCapture(0)
    cap.set(3,640) # set Width
    cap.set(4,480) # set Height
    while(True):
        ret, frame = cap.read()
        frame = cv2.flip(frame, -1) # Flip camera vertically
        gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

        cv2.imshow('frame', frame)
        cv2.imshow('gray', gray)

        k = cv2.waitKey(30) & 0xff
        if k == 27: # press 'ESC' to quit
            break

'''

right now, i just wanted to have simple ui...by just pressing ''(button1), the main.py will pop-up

1 Answers1

0

You can't just pop main.py. What you can do is put the OpenCV code in a function that you will call from your PushButton instance i.e. replace do_nothing we a function that does something similar. Note that I don't know much about guizero so I can't tell what will happen once you start your infinite loop.

Side notes:

  • There might already be something in guizero to show picture so you don't have to use imshow.
  • OpenCV already provides the highgui module which might be enough for your purpose.
SGaist
  • 906
  • 8
  • 33
  • 109