OpenCV Tutorial Source Code

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

jmeldrum

  • Posts: 1
  • Joined: Wed May 08, 2019 11:39 pm
  • Real Name: Joe Meldrum

OpenCV Tutorial Source Code

PostWed May 08, 2019 11:42 pm

I appreciate the video tutorial for live video processing with OpenCV that was posted recently on the Support page. Is the full source code available for the tutorial?
Offline

GlennNZ

  • Posts: 2
  • Joined: Sat Sep 28, 2019 11:37 pm
  • Real Name: Glenn Hawken

Re: OpenCV Tutorial Source Code

PostSun Sep 29, 2019 11:09 pm

+1
Me to!
Thanks
Offline

tautin

  • Posts: 108
  • Joined: Thu Oct 18, 2018 3:11 pm
  • Real Name: Tim Autin

Re: OpenCV Tutorial Source Code

PostTue Mar 17, 2020 10:59 am

For what it's worth, +1 ;)
Offline

Cameron Nichols

Blackmagic Design

  • Posts: 442
  • Joined: Mon Sep 04, 2017 4:05 am

Re: OpenCV Tutorial Source Code

PostWed Mar 18, 2020 10:19 pm

Hi Tim,

The Live Video Processing with OpenCV tutorial source is available on the Blackmagic Developer site:

https://www.blackmagicdesign.com/develo ... d-playback

Under heading: Presentations and Sample Code

Regards
Cameron
Offline

tautin

  • Posts: 108
  • Joined: Thu Oct 18, 2018 3:11 pm
  • Real Name: Tim Autin

Re: OpenCV Tutorial Source Code

PostFri Mar 20, 2020 3:26 pm

Hi Cameron,

Thank you so much :)!
I ran the program and would like to know if there's something we can do to improve the latency when simply looping through, or this the best we can get with Decklink cards (I'm evaluating AR directly with Decklink vs with ATEM + green background / keying)?

Thanks again!

EDIT: you might want to know that the code requires some minor updates to run with a DeckLink 8K Pro.
Offline

giorgi3092

  • Posts: 6
  • Joined: Fri Jul 10, 2020 1:45 pm
  • Real Name: Giorgi Aptsiauri

Re: OpenCV Tutorial Source Code

PostFri Jul 10, 2020 1:56 pm

tautin wrote:Hi Cameron,

Thank you so much :)!
I ran the program and would like to know if there's something we can do to improve the latency when simply looping through, or this the best we can get with Decklink cards (I'm evaluating AR directly with Decklink vs with ATEM + green background / keying)?

Thanks again!

EDIT: you might want to know that the code requires some minor updates to run with a DeckLink 8K Pro.


Hey, can you elaborate on what changes are required to run the OpenCV example with DeckLink 8K Pro?
I am having trouble running it. The output is:
Code: Select all
StartDeckLinkCapture
Capture failed: Could not enable video input


I examined the code quickly and have set the mode to bmdModeHD1080i50 as the camera connected is set to 1080i50 as SDI video output.
I get the same error when I run the program.

I also ran the sample programs which auto-detect the camera mode and they also choose this mode (bmdModeHD1080i50) automatically.

But, again, I can't get it to work with the given OpenCV example.

Can you help on this?
Offline

tautin

  • Posts: 108
  • Joined: Thu Oct 18, 2018 3:11 pm
  • Real Name: Tim Autin

Re: OpenCV Tutorial Source Code

PostThu Jul 16, 2020 3:45 pm

Hey, can you elaborate on what changes are required to run the OpenCV example with DeckLink 8K Pro?
I am having trouble running it. The output is:


Hello,

I don't remember what I changed exactly, but I attached the working project (tested on Ubuntu 16.04 LTS with a DeckLink 8K Pro).

Step I followed:
- plug your camera in the 1st input (the one next to the ref input)
- plug your screen in the 3rd input
- open BlackMagic Desktop Video Setup and:
-> set DeckLink 8K Pro (1) connector to SDI 1 In or Out
-> set DeckLink 8K Pro (2) connector to SDI 3 In or Out
- update the BuildLinux.sh script to put your OpenCV & DeckLink SDK paths
- update the LiveVideoWithOpenCV.cpp at line 552 to set your camera's video mode (4K, Full HD, etc)
- cd into the project folder
- run ./BuildLinux.sh
- run ./build/LiveVideoWithOpenCV

By default you should get a video with a green rectangle around your face when you smile.

Have fun ;)
Attachments
Blackmagic Live Video Processing with OpenCV.zip
(22.33 KiB) Downloaded 306 times
Offline

giorgi3092

  • Posts: 6
  • Joined: Fri Jul 10, 2020 1:45 pm
  • Real Name: Giorgi Aptsiauri

Re: OpenCV Tutorial Source Code

PostMon Jul 20, 2020 8:19 am

tautin wrote:
Hey, can you elaborate on what changes are required to run the OpenCV example with DeckLink 8K Pro?
I am having trouble running it. The output is:


Hello,

I don't remember what I changed exactly, but I attached the working project (tested on Ubuntu 16.04 LTS with a DeckLink 8K Pro).

Step I followed:
- plug your camera in the 1st input (the one next to the ref input)
- plug your screen in the 3rd input
- open BlackMagic Desktop Video Setup and:
-> set DeckLink 8K Pro (1) connector to SDI 1 In or Out
-> set DeckLink 8K Pro (2) connector to SDI 3 In or Out
- update the BuildLinux.sh script to put your OpenCV & DeckLink SDK paths
- update the LiveVideoWithOpenCV.cpp at line 552 to set your camera's video mode (4K, Full HD, etc)
- cd into the project folder
- run ./BuildLinux.sh
- run ./build/LiveVideoWithOpenCV

By default you should get a video with a green rectangle around your face when you smile.

Have fun ;)


Thank you so much! I am developing on Windows but your modifications immensely helped me to gain insight into the flow of the program and what functions really do.

I have modified the DeviceManager class according to yours and it works now!
The problem was that the program only kept enabling the device which arrived last, which was DeckLink subdevice 4 which was not correctly configured in Video Setup software. Your code kept those device pointers in an array and enabled me to enable each device separately and choose the device properly.

Also, credits to Cameron Nichols who gave me valuable insight through email exchange.
Thanks!
Offline

HEILMAO

  • Posts: 2
  • Joined: Mon Nov 30, 2020 4:37 pm
  • Real Name: Oliver Heilmann

Re: OpenCV Tutorial Source Code

PostWed Dec 02, 2020 3:26 pm

Hi all,

I have been trying to get the Decklink Quad 2 capture card to stream video footage. The issue I am having sounds very similar to the one above. When I run the OpenCV sample code you have mentioned above, I get the same error:
Code: Select all
StartDeckLinkCapture
Capture failed: Could not enable video output

I have then modified the program with the mentioned steps (I am using Windows 10 so I did the Windows equivalent for building the code):
- plug your camera in the 1st input (the one next to the ref input)
- plug your screen in the 3rd input
- open BlackMagic Desktop Video Setup and:
-> set DeckLink 8K Pro (1) connector to SDI 1 In or Out
-> set DeckLink 8K Pro (2) connector to SDI 3 In or Out
- update the BuildLinux.sh script to put your OpenCV & DeckLink SDK paths
- update the LiveVideoWithOpenCV.cpp at line 552 to set your camera's video mode (4K, Full HD, etc)
- cd into the project folder
- run ./BuildLinux.sh
- run ./build/LiveVideoWithOpenCV

After I make these changes and use the provided code in the zip file attached above, I get the following error when building:
Code: Select all
C:\Users\...\DeviceManager.h(80,35): error C3861: 'CreateDeckLinkDiscoveryInstance': identifier not found [C:\Users\...\build\LiveVideoWithOpenCV.vcxproj]

The location pointed to is the following line of code:
Code: Select all
m_decklinkDiscovery = CreateDeckLinkDiscoveryInstance();

I am not sure what I should be doing here. giorgi3092 are you able to elaborate on what you did at this stage? If you require any additional information I am happy to provide. Thank you for your help!
Offline

Cameron Nichols

Blackmagic Design

  • Posts: 442
  • Joined: Mon Sep 04, 2017 4:05 am

Re: OpenCV Tutorial Source Code

PostFri Dec 04, 2020 4:21 am

Hi Oliver,

If I can point you to a segment of code in the Live Video with OpenCV sample, in DeviceManager.h, the DeckLinkNotificationManager constructor:
Code: Select all
   // This is a COM interface so should only be created with CreateInstance(), and managed with AddRef() and Release()
   DeckLinkNotificationManager()
      : m_refCount(1)
   {
#ifndef _WIN32
      m_decklinkDiscovery = CreateDeckLinkDiscoveryInstance();
#else
      IDeckLinkDiscovery* discovery = nullptr;

      CoCreateInstance(CLSID_CDeckLinkDiscovery, NULL, CLSCTX_ALL, IID_IDeckLinkDiscovery, (void**)&discovery);
      m_decklinkDiscovery = discovery;
#endif
      if (!m_decklinkDiscovery)
         throw std::runtime_error("CreateDeckLinkDiscoveryInstance failed: check driver is installed");
   }

So the Win32 path should not call CreateDeckLinkDiscoveryInstance, but CoCreateInstance.

Regards
Cameron
Offline

HEILMAO

  • Posts: 2
  • Joined: Mon Nov 30, 2020 4:37 pm
  • Real Name: Oliver Heilmann

Re: OpenCV Tutorial Source Code

PostMon Dec 07, 2020 1:23 pm

Hi Cameron,

Thanks for your response. I have made your suggested changes and am now greeted with the following:

Code: Select all
C:\Users\...\build\Release>LiveVideoWithOpenCV.exe
Capture failed: CreateDeckLinkDiscoveryInstance failed: check driver is installed


I believe that I have the correct drivers installed based on the fact that my Decklink Quad 2 is discovered correctly on the Desktop Video Setup and Blackmagic Media Express which I installed alongside the Decklink SDK 11.7.

Thanks again.
Last edited by HEILMAO on Tue Dec 15, 2020 3:39 pm, edited 1 time in total.
Offline

Cameron Nichols

Blackmagic Design

  • Posts: 442
  • Joined: Mon Sep 04, 2017 4:05 am

Re: OpenCV Tutorial Source Code

PostMon Dec 14, 2020 12:06 am

Hi Oliver,

Can you check why CreateDeckLinkDiscoveryInstance is called by your code, this code path should only be valid for Mac and Linux builds. On Windows, the preprocessed path should call CoCreateInstance.

Regards
Cameron
Offline

bjarque

  • Posts: 1
  • Joined: Thu Nov 23, 2023 9:38 am
  • Real Name: Bjarke Thorbjørn Aagaard

Re: OpenCV Tutorial Source Code

PostThu Nov 23, 2023 9:46 am

Hi,
Reviving an old post here, but I am trying to get this to work with an 8k Pro, and getting the same errors as HEILMAO.

Cameron, CoCreateInstance is called as it should, its just the error message saying "CreateDeckLinkDiscoveryInstance " from this line
Code: Select all
 throw std::runtime_error("CreateDeckLinkDiscoveryInstance failed: check driver is installed");


I tried to debug it on Windows, and CoCreateInstance doesnt seem to return a decklink instance to &discovery. That is why the exception above is thrown.
Any input to next steps to get this to work?

Thanks in advance!

Return to Software Developers

Who is online

Users browsing this forum: No registered users and 9 guests