Advertisement
Guest User

Untitled

a guest
Aug 24th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. __author__ = 'bunkus'
  2. from kivy.app import App
  3. from kivy.uix.widget import Widget
  4. from kivy.uix.boxlayout import BoxLayout
  5. from kivy.uix.image import Image
  6. from kivy.clock import Clock
  7. from kivy.graphics.texture import Texture
  8.  
  9. import cv2
  10.  
  11. class CamApp(App):
  12.  
  13. def build(self):
  14. self.img1=Image()
  15. layout = BoxLayout()
  16. layout.add_widget(self.img1)
  17. #opencv2 stuffs
  18. self.capture = cv2.VideoCapture(0)
  19. cv2.namedWindow("CV2 Image")
  20. Clock.schedule_interval(self.update, 1.0/33.0)
  21. return layout
  22.  
  23. def update(self, dt):
  24. # display image from cam in opencv window
  25. ret, frame = self.capture.read()
  26. cv2.imshow("CV2 Image", frame)
  27. # convert it to texture
  28. buf1 = cv2.flip(frame, 0)
  29. buf = buf1.tostring()
  30. texture1 = Texture.create(size=(frame.shape[1], frame.shape[0]), colorfmt='bgr')
  31. texture1.blit_buffer(buf, colorfmt='bgr', bufferfmt='ubyte')
  32. # display image from the texture
  33. self.img1.texture = texture1
  34.  
  35. if __name__ == '__main__':
  36. CamApp().run()
  37. cv2.destroyAllWindows()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement