<i id='xhj8h'><tr id='xhj8h'><dt id='xhj8h'><q id='xhj8h'><span id='xhj8h'><b id='xhj8h'><form id='xhj8h'><ins id='xhj8h'></ins><ul id='xhj8h'></ul><sub id='xhj8h'></sub></form><legend id='xhj8h'></legend><bdo id='xhj8h'><pre id='xhj8h'><center id='xhj8h'></center></pre></bdo></b><th id='xhj8h'></th></span></q></dt></tr></i><div id='xhj8h'><tfoot id='xhj8h'></tfoot><dl id='xhj8h'><fieldset id='xhj8h'></fieldset></dl></div>
<legend id='xhj8h'><style id='xhj8h'><dir id='xhj8h'><q id='xhj8h'></q></dir></style></legend>
    • <bdo id='xhj8h'></bdo><ul id='xhj8h'></ul>

    <small id='xhj8h'></small><noframes id='xhj8h'>

    1. <tfoot id='xhj8h'></tfoot>

    2. 将 OpenCV 网络摄像头集成到 Kivy 用户界面中

      时间:2023-10-09

        <small id='QTFaG'></small><noframes id='QTFaG'>

          • <bdo id='QTFaG'></bdo><ul id='QTFaG'></ul>

              <tbody id='QTFaG'></tbody>

            • <legend id='QTFaG'><style id='QTFaG'><dir id='QTFaG'><q id='QTFaG'></q></dir></style></legend>
                <i id='QTFaG'><tr id='QTFaG'><dt id='QTFaG'><q id='QTFaG'><span id='QTFaG'><b id='QTFaG'><form id='QTFaG'><ins id='QTFaG'></ins><ul id='QTFaG'></ul><sub id='QTFaG'></sub></form><legend id='QTFaG'></legend><bdo id='QTFaG'><pre id='QTFaG'><center id='QTFaG'></center></pre></bdo></b><th id='QTFaG'></th></span></q></dt></tr></i><div id='QTFaG'><tfoot id='QTFaG'></tfoot><dl id='QTFaG'><fieldset id='QTFaG'></fieldset></dl></div>
                <tfoot id='QTFaG'></tfoot>

                本文介绍了将 OpenCV 网络摄像头集成到 Kivy 用户界面中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我当前的程序是 Python 并使用 OpenCV.我依靠网络摄像头捕获,并且正在处理每个捕获的帧:

                My current program is in Python and uses OpenCV. I rely on webcam captures and I am processing every captured frame:

                import cv2
                
                # use the webcam
                cap = cv2.VideoCapture(0)
                while True:
                    # read a frame from the webcam
                    ret, img = cap.read()
                    # transform image
                

                我想制作一个带有按钮的 Kivy 界面(或其他图形用户界面),同时通过网络摄像头捕获现有功能.

                I would like to make a Kivy interface (or another graphical user interface) with buttons, keeping already existing functionality with webcam captures.

                我找到了这个例子:https://kivy.org/docs/examples/gen__camera__main__py.html— 但它没有解释如何获取网络摄像头图像以使用 OpenCV 对其进行处理.

                I found this example: https://kivy.org/docs/examples/gen__camera__main__py.html — but it doesn’t explain how to acquire the webcam image to process it with OpenCV.

                我找到了一个较旧的示例:http://thezestyblogfarmer.blogspot.it/2013/10/kivy-python-script-for-capturing.html— 它使用屏幕截图"功能将屏幕截图保存到磁盘.然后我可以读取保存的文件并进行处理,但这似乎是不必要的步骤.

                I found an older example: http://thezestyblogfarmer.blogspot.it/2013/10/kivy-python-script-for-capturing.html — it saves screenshots to disk using the ‘screenshot’ function. Then I can read the saved files and process them, but this seems to be an unnecessary step.

                我还能尝试什么?

                推荐答案

                在这里找到这个例子:https://groups.google.com/forum/#!topic/kivy-users/N18DmblNWb0

                它将 opencv 捕获转换为 kivy 纹理,因此您可以在将其显示到您的 kivy 界面之前进行各种 cv 转换.

                It converts the opencv captures to kivy textures, so you can do every kind of cv transformations before displaying it to your kivy interface.

                __author__ = 'bunkus'
                from kivy.app import App
                from kivy.uix.widget import Widget
                from kivy.uix.boxlayout import BoxLayout
                from kivy.uix.image import Image
                from kivy.clock import Clock
                from kivy.graphics.texture import Texture
                
                import cv2
                
                class CamApp(App):
                
                    def build(self):
                        self.img1=Image()
                        layout = BoxLayout()
                        layout.add_widget(self.img1)
                        #opencv2 stuffs
                        self.capture = cv2.VideoCapture(0)
                        cv2.namedWindow("CV2 Image")
                        Clock.schedule_interval(self.update, 1.0/33.0)
                        return layout
                
                    def update(self, dt):
                        # display image from cam in opencv window
                        ret, frame = self.capture.read()
                        cv2.imshow("CV2 Image", frame)
                        # convert it to texture
                        buf1 = cv2.flip(frame, 0)
                        buf = buf1.tostring()
                        texture1 = Texture.create(size=(frame.shape[1], frame.shape[0]), colorfmt='bgr') 
                        #if working on RASPBERRY PI, use colorfmt='rgba' here instead, but stick with "bgr" in blit_buffer. 
                        texture1.blit_buffer(buf, colorfmt='bgr', bufferfmt='ubyte')
                        # display image from the texture
                        self.img1.texture = texture1
                
                if __name__ == '__main__':
                    CamApp().run()
                    cv2.destroyAllWindows()
                

                这篇关于将 OpenCV 网络摄像头集成到 Kivy 用户界面中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:Kivy 'NoneType' 对象没有属性 'ids' 下一篇:在 Kivy 中从内存中加载图像

                相关文章

                最新文章

                • <bdo id='3qXs8'></bdo><ul id='3qXs8'></ul>

                  1. <i id='3qXs8'><tr id='3qXs8'><dt id='3qXs8'><q id='3qXs8'><span id='3qXs8'><b id='3qXs8'><form id='3qXs8'><ins id='3qXs8'></ins><ul id='3qXs8'></ul><sub id='3qXs8'></sub></form><legend id='3qXs8'></legend><bdo id='3qXs8'><pre id='3qXs8'><center id='3qXs8'></center></pre></bdo></b><th id='3qXs8'></th></span></q></dt></tr></i><div id='3qXs8'><tfoot id='3qXs8'></tfoot><dl id='3qXs8'><fieldset id='3qXs8'></fieldset></dl></div>

                    <tfoot id='3qXs8'></tfoot><legend id='3qXs8'><style id='3qXs8'><dir id='3qXs8'><q id='3qXs8'></q></dir></style></legend>

                    <small id='3qXs8'></small><noframes id='3qXs8'>