Last active
September 12, 2023 21:11
-
-
Save cbenhagen/39a336e01e072617fa6f to your computer and use it in GitHub Desktop.
Example of using input from a Blackmagic Decklink or Ultrastudio card in kivy with the use of OpenCV and GStreamer.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from kivy.app 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 kivy.graphics.texture import Texture | |
import cv2 | |
import numpy as np | |
class CamApp(App): | |
def build(self): | |
self.img1 = Image() | |
layout = BoxLayout() | |
layout.add_widget(self.img1) | |
self.capture = cv2.VideoCapture('decklinksrc mode=7 connection=0 ! videoconvert ! appsink') | |
Clock.schedule_interval(self.update, 1.0/33.0) | |
return layout | |
def update(self, dt): | |
ret, frame = self.capture.read() | |
if frame: | |
buf1 = cv2.flip(frame, 0) | |
buf = buf1.tostring() | |
texture1 = Texture.create(size=(frame.shape[1], frame.shape[0]), colorfmt='bgr') | |
texture1.blit_buffer(buf, colorfmt='bgr', bufferfmt='ubyte') | |
self.img1.texture = texture1 | |
else: | |
print("No frame read.") | |
if __name__ == '__main__': | |
CamApp().run() |
I guess frame was None because there was an issue with your decklink settings (line 18). The code now checks for a valid frame and prints an error if there was none.
m not able to import cv2 please help it works with other codes but not with kivy
Hello, I would like to ask a question, can I use this code with blackmagic design intensity pro 4k and what should change the code to make it work? Thank you
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hello , when i'm trying run your script , i'm getting error AttributeError: 'NoneType' object has no attribute 'tostring' .