Pass data from SDK to Numpy

Ask software engineering and SDK questions for developers working on Mac OS X, Windows or Linux.
  • Author
  • Message
Offline

michaelukw

  • Posts: 9
  • Joined: Tue Aug 11, 2020 12:01 pm
  • Real Name: Michael Banck

Pass data from SDK to Numpy

PostTue Aug 11, 2020 12:21 pm

Hello Blackmagic Forum,

we recently bought a video grabber card (DeckLink Mini Recorder), which is required for our project to pass video data to an a.i.
For ms windows the whole thing is working fine, it is pretty easy to get the data by openCV via video capturing.
The problem is, we are forced to use Linux (Ubuntu) by our dependencies. I could not make openCV getting data from the grabber card and I read in this forum, this function is not available for Linux. (correct me if I am wrong)
So I just started playing around with the SDK (11.6). So far I can get some data with the "Capture" sample code. I am receiving the 4:2:2 YCrPr color format and was able to map it to an RGB format by doing the calculation by myself.
But I still need this data in Python. What do you think is the best way to get this data into a numpy array, and what is the best way to convert it to RGB (Maybe there is a more simple way which is already implemented)?

Everything should be as fast as possible, since the a.i. is supposed to do the evaluation in real time.
We are using tensorflow/keras so there is no way to get rid of Python.

I would be very grateful for any suggestions
BR Michael
Offline

Brendan Dower

Blackmagic Design

  • Posts: 60
  • Joined: Thu Oct 10, 2019 5:56 am
  • Real Name: Brendan Dower

Re: Pass data from SDK to Numpy

PostTue Aug 11, 2020 10:41 pm

Hi Michael,

Our SDK also includes an IDeckLinkConversion Interface which can be used to convert the frame inside the capture application.

  • High-level instructions detailing how to do this can be found in section 2.4.15 of the SDK manual.
  • The detailed description of the IDeckLinkConversion interface can be found in section 2.5.44.
  • The CaptureStills sample from the SDK demonstrates how to use this interface.
Do you need to import individual frames into numPy for analysis, or are you trying to import the video stream itself?

If you only need the individual still frames, I would recommend running CaptureStills to save the frames to disck as an image file and then opening these PNG files into your python script and converting these to a numPy array using numPy's 'asarray' method. You could use pillow to import the image.

Code: Select all
from PIL import Image
from numpy import asarray

image = Image.open("frame1.png")
data = asarray(image)

Brendan Dower
Blackmagic Design Developer Support
Offline

michaelukw

  • Posts: 9
  • Joined: Tue Aug 11, 2020 12:01 pm
  • Real Name: Michael Banck

Re: Pass data from SDK to Numpy

PostThu Aug 13, 2020 10:23 am

Hi Brendan,

thank you for your very fast response. It will take me a while to read the linked sections, but it sounds good so far.

About the numPy, I need each single frame (probably resized, but it doesn't matter), because the A.I. is supposed to evaluate the images. As I mentioned, the use case is real time, so I can't store the Image on a disc. A HDD and also SSD would slow down the whole process, so the RAM is the only way here and I would like to store it only once, without any additional allocation or iteration.

BR Michael

Return to Software Developers

Who is online

Users browsing this forum: No registered users and 13 guests