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

将OpenCV网络摄像头集成到Kivy用户界面中,第1张

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

在以下位置找到此示例:https : //groups.google.com/forum/#!topic/kivy-
users/N18DmblNWb0

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

__author__ = 'bunkus'from kivy.app import Appfrom kivy.uix.widget import Widgetfrom kivy.uix.boxlayout import BoxLayoutfrom kivy.uix.image import Imagefrom kivy.clock import Clockfrom kivy.graphics.texture import Textureimport cv2class 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 = texture1if __name__ == '__main__':    CamApp().run()    cv2.destroyAllWindows()


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5664138.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存