title: Kivy error Camera Webcam gives error VideoCapture:Resolution not found
body: <p>I have a Kivy App and I am trying to take a video from my webcam camera to put it in my application on my computer. I got this code online which was :-</p>
  
  <pre><code>from kivy.app import App
  from kivy.lang import Builder
  
  kv = '''
  BoxLayout:
      orientation: 'vertical'
      Camera:
          id: camera
          resolution: (640, 480)
          play: False
      ToggleButton:
          text: 'Play'
          on_press: camera.play = not camera.play
          size_hint_y: None
          height: '48dp'
  '''
  
  
  class TestCamera(App):
      def build(self):
          return Builder.load_string(kv)
  
  TestCamera().run() 
  </code></pre>
  
  <p>I am getting an error stating that VideoCapture:Resolution Not Found in kivy/core/camera/camera_videocaputure. I tied to figure out many different ways yet I could not resolve the query. It would be great if anyone could help me out with it. Thanks ! </p>
  
  <p>The error Traceback is : </p>
  
  <pre><code>Traceback (most recent call last):
   File "C:\Users\User\Desktop\personal work\BinaryHeap.py", line 23, in     &lt;module&gt;
       TestCamera().run()
  
  
     File "C:\Users\User\Desktop\personal work\Anaconda3\envs\py27\lib\site-packages\kivy\app.py", line 802, in run
       root = self.build()
     File "C:\Users\User\Desktop\personal work\BinaryHeap.py", line 21, in build
       return Builder.load_string(kv)
     File "C:\Users\User\Desktop\personal work\Anaconda3\envs\py27\lib\site-packages\kivy\lang.py", line 1921, in load_string
       self._apply_rule(widget, parser.root, parser.root)
     File "C:\Users\User\Desktop\personal work\Anaconda3\envs\py27\lib\site-packages\kivy\lang.py", line 2130, in _apply_rule
       e), cause=tb)
   BuilderException: Parser: File "&lt;inline&gt;", line 6:
   ...
         4:    Camera:
         5:        id: camera
   &gt;&gt;    6:        resolution: (640, 480)
         7:        play: False
         8:    ToggleButton:
   ...
   Exception: VideoCapture: Resolution not supported
     File "C:\Users\User\Desktop\personal work\Anaconda3\envs\py27\lib\site-packages\kivy\lang.py", line 2123, in _apply_rule
       setattr(widget_set, key, value)
     File "kivy\weakproxy.pyx", line 22, in kivy.weakproxy.WeakProxy.__setattr__ (kivy\weakproxy.c:1235)
     File "kivy\properties.pyx", line 408, in kivy.properties.Property.__set__ (kivy\properties.c:5114)
     File "kivy\properties.pyx", line 733, in kivy.properties.ListProperty.set (kivy\properties.c:11127)
     File "kivy\properties.pyx", line 446, in kivy.properties.Property.set (kivy\properties.c:5876)
     File "kivy\properties.pyx", line 501, in kivy.properties.Property.dispatch (kivy\properties.c:6557)
     File "kivy\_event.pyx", line 1224, in kivy._event.EventObservers.dispatch (kivy\_event.c:13497)
     File "kivy\_event.pyx", line 1130, in kivy._event.EventObservers._dispatch (kivy\_event.c:12696)
     File "C:\Users\User\Desktop\personal work\Anaconda3\envs\py27\lib\site-packages\kivy\uix\camera.py", line 103, in _on_index
       resolution=self.resolution, stopped=True)
     File "C:\Users\User\Desktop\personal work\Anaconda3\envs\py27\lib\site-packages\kivy\core\camera\camera_videocapture.py", line 26, in __init__
       super(CameraVideoCapture, self).__init__(**kwargs)
     File "C:\Users\User\Desktop\personal work\Anaconda3\envs\py27\lib\site-packages\kivy\core\camera\__init__.py", line 70, in __init__
       self.init_camera()
     File "C:\Users\User\Desktop\personal work\Anaconda3\envs\py27\lib\site-packages\kivy\core\camera\camera_videocapture.py", line 36, in init_camera
       raise Exception('VideoCapture: Resolution not supported')
  </code></pre>
  
  <p>[-1,-1] also does not work just provides me with a blank screen. If someone tries it please temme if it worked for them ? Is there any other way I can get the camera working ? </p>
  
  <pre><code>from kivy.app import App
  from kivy.uix.image import Image
  from kivy.clock import Clock
  from kivy.graphics.texture import Texture
  import cv2
  from kivy.uix.camera import Camera 
  
  class KivyCamera(Image):
      def __init__(self, capture, fps, **kwargs):
          super(KivyCamera, self).__init__(**kwargs)
          self.capture = capture
          Clock.schedule_interval(self.update, 1.0 / fps)
  
      def update(self, dt):
          ret, frame = self.capture.read()
          if ret:
              # convert it to texture
              buf1 = cv2.flip(frame, 0)
              buf = buf1.tostring()
              image_texture = Texture.create(size=(frame.shape[1], frame.shape[0]), colorfmt='bgr')
              image_texture.blit_buffer(buf, colorfmt='bgr', bufferfmt='ubyte')
              # display image from the texture
              self.texture = image_texture
  
  
  class CamApp(App):
      def build(self):
          self.capture = cv2.VideoCapture(0)
          self.my_camera = KivyCamera(capture=self.capture, fps=30)
          return self.my_camera
  
      def on_stop(self):
          #without this, app will not exit even if the window is closed
          self.capture.release()
  
  
  CamApp().run()
  </code></pre>
  
  <p>The above code works for me but I don't know how to change it to a kivy file. So I would appreciate any help. Thanks. I took a picture and my camera resolution was 1920 x 1080. I just thought it might help. </p>