I want to convert class webcam into kv file and Using popup

18 views
Skip to first unread message

뿌야

unread,
May 12, 2020, 8:39:29 AM5/12/20
to Kivy users support
I would like to use Streetpopup for the Streetpop class defined in the py file.

If i click Street Button I want Webcam to come out.


kv file

Button:
            text: "Street"
            size_hint: .5, .0
            font_size: 50
            on_press: Factory.StreetPop().open()

<StreetPop@Popup>:


py file

class StreetPop(Popup):
    def build(self):
        layout = BoxLayout()
        layout.add_widget(self.img1)
        self.capture = cv2.VideoCapture(0)
        cv2.namedWindow("CV2 Image")
        Clock.schedule_interval(self.update, 1.0/33.0)
        return layout

    def update(self, dt):
        ret, frame = self.capture.read()
        cv2.imshow("CV2 Image", frame)
        buf1 = cv2.flip(frame, 0)
        buf = buf1.tostring()
        texture1 = Texture.create(size=(frame.shape[1], frame.shape[0]), colorfmt='bgr')
        self.img1.texture = texture1

        cv2.destroyAllWindows()

Elliot Garbus

unread,
May 12, 2020, 11:10:47 AM5/12/20
to kivy-...@googlegroups.com

The build method only belongs to App().  Move the layout code to kv.

 

<StreetPop>:  # remove the dynamic class creation because you are defining it in python.

 

Move the code you want to run at StreetPop object creation to __init__()   

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/cdfc3db8-4417-416e-b789-09b0accaac3a%40googlegroups.com.

 

Reply all
Reply to author
Forward
0 new messages