Python / Kivy camera widget error with opencv

I am trying to create an application that opens the camera of the device, but I am getting this error:

    [CRITICAL          ] [Camera      ] Unable to find any valuable Camera provider at all!
videocapture - ImportError: No module named VideoCapture
  File "C:\Users\Gaston\Downloads\Kivy-1.9.0-py2.7-win32-x86\kivy27\kivy\core\__init__.py", line 57, in core_select_lib
    fromlist=[modulename], level=0)
  File "C:\Users\Gaston\Downloads\Kivy-1.9.0-py2.7-win32-x86\kivy27\kivy\core\camera\camera_videocapture.py", line 15, in <module>
    from VideoCapture import Device

opencv - ImportError: No module named cv
  File "C:\Users\Gaston\Downloads\Kivy-1.9.0-py2.7-win32-x86\kivy27\kivy\core\__init__.py", line 57, in core_select_lib
    fromlist=[modulename], level=0)
  File "C:\Users\Gaston\Downloads\Kivy-1.9.0-py2.7-win32-x86\kivy27\kivy\core\camera\camera_opencv.py", line 20, in <module>
    import cv

      

Tried installing opencv but still didn't work. And my code is just sample code in the kivy docs: http://kivy.org/docs/examples/gen__camera__main__py.html

+3


source to share


1 answer


I wish I had enough reputation to comment, but I believe you should check if you have a library that can support Camera. I believe you are importing cv instead of cv2. Make sure that if the problem persists, check if your folder contains the required libraries. I got this code from the internet. It works on my computer, can help you: -



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.boxlayout import BoxLayout
from kivy.uix.gridlayout import GridLayout
from kivy.uix.widget import Widget
from kivy.uix.button import Button

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(1)
        self.my_camera = KivyCamera(capture=self.capture, fps=10,resolution=(1280,960))

        return self.my_camera

    def on_stop(self):
        #without this, app will not exit even if the window is closed
        self.capture.release()


if __name__ == '__main__':
    CamApp().run()

      

0


source







All Articles