Integrate OpenCV webcam into a Kivy user interface

kivy camera
kivy opencv camera android
kivy face detection
kivy image
kivy tutorial
kivy core camera
kivy texture
kivy camera ios

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 =
    # transform image

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

I found this example: — but it doesn’t explain how to acquire the webcam image to process it with OpenCV.

I found an older example: — 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.

What else can I try?

Found this example here:!topic/kivy-users/N18DmblNWb0

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 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 import Texture

import cv2

class CamApp(App):

    def build(self):
        layout = BoxLayout()
        #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 =
        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__':

kivy and opencv work together demo · GitHub, I believe the camera is not being accessed. In buildozer.spec I gave the App permission to access the camera. Clone via HTTPS Clone with Git or checkout with SVN using the repository’s web address.

Note: I have no clue how OpenCV works, but I found, so this means there is an easy way how to work with it.

As you see in camera example, this is the default way and when you look in for camera you can see opencv in providers so perhaps it works with OpenCV out of the box. Check log if you can see OpenCV detected as a provider. You should see CameraOpenCV written somewhere if it's detected and it should show itself when capturing image.

If you however want to work with OpenCV directly(i.e. and similar stuff), then you need to write your own handler for the provider or append more options to the camera_opencv file.

OpenCV with Kivy, I've got a project that I've built in python that uses OpenCV pretty -6-working-​with-camera-in-kivy/ This example doesn't show how to use cv2  Teams. Q&A for Work. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information.

You may have a look at Also have a look at all the other posts from Adrian on his site. Many practical examples.

Camera Example, This example demonstrates a simple use of the camera. It shows a window with a buttoned labelled 'play' to turn the camera on and off. Note that not finding a  3 Integrate OpenCV webcam into a Kivy user interface Jun 10 '16 2 No visible text() when using matplotlib.pyplot Sep 5 '16 0 Decorators in class methods: compatibility with 'getattr' Sep 12 '16, Camera ====== Core class for acquiring the camera and converting its input into a :class:``. .. versionchanged:: 1.10.0 The pygst  Recently I've started learning about Kivy, a Python Natural User Interface (NUI) toolkit. kivy: change the color of a label. uix. w: int, the width of the text in lines, including padding. bind (height = resize_label_text) Note that the event here is named height . Popup` with a list of options from which the user can select.

Integrate OpenCv with Kivy : kivy, Thanks ! cvtColor, basically I am porting an existing OpenCv project but want a more robust UI. Continue this thread Rearrange items in a list with on_touch_move in Kivy. Face Detection using Python and OpenCV with webcam OpenCV is a Library which is used to carry out image processing using programming languages like python. This project utilizes OpenCV Library to make a Real-Time Face Detection using your webcam as a primary camera.

Accessing Android camera through Kivy, This example demonstrates a simple use of the camera. Integrate OpenCV webcam into a Kivy user interface, It converts the opencv captures to kivy textures​,  Camera Example¶. This example demonstrates a simple use of the camera. It shows a window with a buttoned labelled ‘play’ to turn the camera on and off.

  • Bill, while interesting, the link has nothing to do with kivy, and doesn't address the question. Some could have downvoted you for this (I didn't).