Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

cv::Mat to DirectX11 Texture (OpenCV 3.1.0)

Let's say I'm trying to display my webcam image in a game in DirectX11. I am using the prebuilt 3.1.0 libraries and I seem to be having difficulties with OpenCL while converting a Mat to a DirectX texture. I am using VS2013 Update 5 under Win10 and I am building a x64 windows application. The machine uses 2 x Nvidia Geforce GTX1080.

// CREATING DIRECTX TEXTURE
ID3D11Texture2D* myTexture = 0;
D3D11_TEXTURE2D_DEC desc_rgba;
desc_rgba.Width = 1024;
desc_rgba.Height = 768;
desc_rgba.MipLevels =1;
desc_rgba.ArraySize =1;
desc_rgba.Format = DXGI_FORMAT_R8G8B8A8_UNORM; // should be CV_8UC4
desc_rgba.SampleDesc.Count = 1;
desc_rgba.SampleDesc.Quality = 0;
desc_rgba.BindFlags = D3D11_BIND_SHADER_RESOURCE;
desc_rgba.Usage = D3D11_USAGE_DYNAMIC;
desc_rgba.CPUAccessFalgs = D3D11_CPU_ACCESS_WRITE;
desc_rgba.MiscFlags = 0;

HRESULT r = DIRECTX.Device->CreateTexture2D(&desc_rgba, 0, &myTexture);
if (FAILED(r)){
    throw std::runtime_error("Can't create DX texture!");
}

//CV::MAT --> DIRECTX
bool enabledOpenCl = cv::ocl::haveOpenCL(); // Throws internal exception and returns 0
cv::Mat webCamImg = ...; // get valid image somehow
cv::Mat convertedImg;
cv::cvtColor(webCamImg, convertedImage, CV_BGR2BGRA); //CV_8UC3 -> CV_8UC4
cv::directx::convertToD3D11Texture2D(convertedImg, myTexture); // Throws exception!

Here's the cv::Exception::what():

C:\builds\master_PackSlave-win64-vc12-shared\opencv\modules\core\src\opencl\runtime\opencl_core.cpp:276: error (-220) OpenCL function is not available: [clGetPlatformIDs] in function opencl_check_fn

Here's the config log: http://pastebin.com/8i34sSRM

OpenCL is enabled in the config, but it's still not working. Any hints? Also, I don't jump to the code anymore when I get a cv::Exception(). What's up with that?

cv::Mat to DirectX11 Texture (OpenCV 3.1.0)

Let's say I'm trying to display my webcam image in a game in DirectX11. I am using the prebuilt 3.1.0 libraries and I seem to be having difficulties with OpenCL while converting a Mat to a DirectX texture. I am using VS2013 Update 5 under Win10 and I am building a x64 windows application. The machine uses 2 x Nvidia Geforce GTX1080.

// CREATING DIRECTX TEXTURE
ID3D11Texture2D* myTexture = 0;
D3D11_TEXTURE2D_DEC desc_rgba;
desc_rgba.Width = 1024;
desc_rgba.Height = 768;
desc_rgba.MipLevels =1;
desc_rgba.ArraySize =1;
desc_rgba.Format = DXGI_FORMAT_R8G8B8A8_UNORM; // should be CV_8UC4
desc_rgba.SampleDesc.Count = 1;
desc_rgba.SampleDesc.Quality = 0;
desc_rgba.BindFlags = D3D11_BIND_SHADER_RESOURCE;
desc_rgba.Usage = D3D11_USAGE_DYNAMIC;
desc_rgba.CPUAccessFalgs = D3D11_CPU_ACCESS_WRITE;
desc_rgba.MiscFlags = 0;

HRESULT r = DIRECTX.Device->CreateTexture2D(&desc_rgba, 0, &myTexture);
if (FAILED(r)){
    throw std::runtime_error("Can't create DX texture!");
}

//CV::MAT --> DIRECTX
bool enabledOpenCl = cv::ocl::haveOpenCL(); // cv::ocl::Context oclContext;
if (cv::ocl::haveOpenCL()){// Throws internal exception and returns 0
0        
    oclContext = cv::directx::ocl::initializeContextFromD3D11Device(DIRECTX.Device);
} 

//...

// GAME LOOP
// CV::MAT --> DIRECTX
cv::Mat webCamImg = ...; // get valid image somehow
cv::Mat convertedImg;
cv::cvtColor(webCamImg, convertedImage, CV_BGR2BGRA); //CV_8UC3 -> CV_8UC4
cv::directx::convertToD3D11Texture2D(convertedImg, myTexture); // Throws exception!

Here's the cv::Exception::what():cv::Exception::what() at the first loop run:

C:\builds\master_PackSlave-win64-vc12-shared\opencv\modules\core\src\opencl\runtime\opencl_core.cpp:276: error (-220) OpenCL function is not available: [clGetPlatformIDs] in function opencl_check_fn

Next iterations yield different cv::Exception:

C:\builds\master_PackSlave-win64-vc12-shared\opencv\modules\core\src\directx.cpp:803: error (-222) OpenCL: Can't find functions for D3D11 in function cv::directx::__OpenCLinitializeD3D11

Here's the config log: http://pastebin.com/8i34sSRM

OpenCL is enabled in the config, but it's still not working. Any hints? Also, I don't jump to the code anymore when I get a cv::Exception(). What's up with that?

EDIT1: Added cv::ocl::Context code and new exception (-222).

cv::Mat to DirectX11 Texture (OpenCV 3.1.0)

Let's say I'm trying to display my webcam image in a game in DirectX11. I am using the prebuilt 3.1.0 libraries and I seem to be having difficulties with OpenCL while converting a Mat to a DirectX texture. I am using VS2013 Update 5 under Win10 and I am building a x64 windows application. The machine uses 2 x Nvidia Geforce GTX1080.

// CREATING DIRECTX TEXTURE
ID3D11Texture2D* myTexture = 0;
D3D11_TEXTURE2D_DEC desc_rgba;
desc_rgba.Width = 1024;
desc_rgba.Height = 768;
desc_rgba.MipLevels =1;
desc_rgba.ArraySize =1;
desc_rgba.Format = DXGI_FORMAT_R8G8B8A8_UNORM; // should be CV_8UC4
desc_rgba.SampleDesc.Count = 1;
desc_rgba.SampleDesc.Quality = 0;
desc_rgba.BindFlags = D3D11_BIND_SHADER_RESOURCE;
desc_rgba.Usage = D3D11_USAGE_DYNAMIC;
desc_rgba.CPUAccessFalgs = D3D11_CPU_ACCESS_WRITE;
desc_rgba.MiscFlags = 0;

HRESULT r = DIRECTX.Device->CreateTexture2D(&desc_rgba, 0, &myTexture);
if (FAILED(r)){
    throw std::runtime_error("Can't create DX texture!");
}

cv::ocl::Context oclContext;
if (cv::ocl::haveOpenCL()){// Throws internal exception and returns 0        
Returns 1        
    // NEW: Exception right here, writing at 0x0000...0
    oclContext = cv::directx::ocl::initializeContextFromD3D11Device(DIRECTX.Device);
cv::directx::ocl::initializeContextFromD3D11Device(DIRECTX.Device); 
} 

//...

// GAME LOOP
// CV::MAT --> DIRECTX
cv::Mat webCamImg = ...; // get valid image somehow
cv::Mat convertedImg;
cv::cvtColor(webCamImg, convertedImage, CV_BGR2BGRA); //CV_8UC3 -> CV_8UC4
cv::directx::convertToD3D11Texture2D(convertedImg, myTexture); // (OLD: Throws exception!
exception!)

Here's the cv::Exception::what() at the first loop run:

C:\builds\master_PackSlave-win64-vc12-shared\opencv\modules\core\src\opencl\runtime\opencl_core.cpp:276: error (-220) OpenCL function is not available: [clGetPlatformIDs] in function opencl_check_fn

Next iterations yield different cv::Exception:

C:\builds\master_PackSlave-win64-vc12-shared\opencv\modules\core\src\directx.cpp:803: error (-222) OpenCL: Can't find functions for D3D11 in function cv::directx::__OpenCLinitializeD3D11

Here's the config log: http://pastebin.com/8i34sSRM

OpenCL is enabled in the config, but it's still not working. Any hints? Update Edit 2: After reinstalling my graphics drivers and CUDA 7.5, haveOpenCL() returns 1 suddenly. Also, I don't jump to the code anymore when I get a cv::Exception(). What's up with that?

EDIT1: Added cv::ocl::Context code and new exception (-222).

EDIT2: Problem shifted to cv::ocl::Context initialization after updating drivers.

cv::Mat to DirectX11 Texture (OpenCV 3.1.0)

Let's say I'm trying to display my webcam image in a game in DirectX11. I am using the prebuilt 3.1.0 libraries and I seem to be having difficulties with OpenCL while converting a Mat to a DirectX texture. I am using VS2013 Update 5 under Win10 and I am building a x64 windows application. The machine uses 2 x Nvidia Geforce GTX1080.

// CREATING DIRECTX TEXTURE
ID3D11Texture2D* myTexture = 0;
D3D11_TEXTURE2D_DEC desc_rgba;
desc_rgba.Width = 1024;
desc_rgba.Height = 768;
desc_rgba.MipLevels =1;
desc_rgba.ArraySize =1;
desc_rgba.Format = DXGI_FORMAT_R8G8B8A8_UNORM; // should be CV_8UC4
desc_rgba.SampleDesc.Count = 1;
desc_rgba.SampleDesc.Quality = 0;
desc_rgba.BindFlags = D3D11_BIND_SHADER_RESOURCE;
desc_rgba.Usage = D3D11_USAGE_DYNAMIC;
desc_rgba.CPUAccessFalgs = D3D11_CPU_ACCESS_WRITE;
desc_rgba.MiscFlags = 0;

HRESULT r = DIRECTX.Device->CreateTexture2D(&desc_rgba, 0, &myTexture);
if (FAILED(r)){
    throw std::runtime_error("Can't create DX texture!");
}

cv::ocl::Context oclContext;
if (cv::ocl::haveOpenCL()){// Returns 1        
    // NEW: Exception right here, writing at 0x0000...0
    oclContext = cv::directx::ocl::initializeContextFromD3D11Device(DIRECTX.Device); 
} 

//...

// GAME LOOP
// CV::MAT --> DIRECTX
cv::Mat webCamImg = ...; // get valid image somehow
cv::Mat convertedImg;
cv::cvtColor(webCamImg, convertedImage, CV_BGR2BGRA); //CV_8UC3 -> CV_8UC4
cv::directx::convertToD3D11Texture2D(convertedImg, myTexture); // (OLD: Throws exception!)

Here's the cv::Exception::what() at the first loop run:

C:\builds\master_PackSlave-win64-vc12-shared\opencv\modules\core\src\opencl\runtime\opencl_core.cpp:276: error (-220) OpenCL function is not available: [clGetPlatformIDs] in function opencl_check_fn

Next iterations yield different cv::Exception:

C:\builds\master_PackSlave-win64-vc12-shared\opencv\modules\core\src\directx.cpp:803: error (-222) OpenCL: Can't find functions for D3D11 in function cv::directx::__OpenCLinitializeD3D11

Here's the config log: http://pastebin.com/8i34sSRM

OpenCL is enabled in the config, but it's still not working. Any hints? Update Edit 2: After reinstalling my graphics drivers and CUDA 7.5, haveOpenCL() returns 1 suddenly. Also, I don't jump to the code anymore when I get a cv::Exception(). What's up with that?


EDIT1: Added cv::ocl::Context code and new exception (-222).

EDIT2: Problem shifted to cv::ocl::Context initialization after updating drivers.

cv::Mat to DirectX11 Texture (OpenCV 3.1.0)

Let's say I'm trying to display my webcam image in a game in DirectX11. I am using the prebuilt 3.1.0 libraries and I seem to be having difficulties with OpenCL while converting a Mat to a DirectX texture. I am using VS2013 Update 5 under Win10 and I am building a x64 windows application. The machine uses 2 x Nvidia Geforce GTX1080.

// CREATING DIRECTX TEXTURE
ID3D11Texture2D* myTexture = 0;
D3D11_TEXTURE2D_DEC desc_rgba;
desc_rgba.Width = 1024;
desc_rgba.Height = 768;
desc_rgba.MipLevels =1;
desc_rgba.ArraySize =1;
desc_rgba.Format = DXGI_FORMAT_R8G8B8A8_UNORM; // should be CV_8UC4
desc_rgba.SampleDesc.Count = 1;
desc_rgba.SampleDesc.Quality = 0;
desc_rgba.BindFlags = D3D11_BIND_SHADER_RESOURCE;
desc_rgba.Usage = D3D11_USAGE_DYNAMIC;
desc_rgba.CPUAccessFalgs = D3D11_CPU_ACCESS_WRITE;
desc_rgba.MiscFlags = 0;

HRESULT r = DIRECTX.Device->CreateTexture2D(&desc_rgba, 0, &myTexture);
if (FAILED(r)){
    throw std::runtime_error("Can't create DX texture!");
}

cv::ocl::Context oclContext;
if (cv::ocl::haveOpenCL()){// Returns 1        
    // NEW: Exception right here, writing at 0x0000...0
    oclContext = cv::directx::ocl::initializeContextFromD3D11Device(DIRECTX.Device); 
} 

//...

// GAME LOOP
// CV::MAT --> DIRECTX
cv::Mat webCamImg = ...; // get valid image somehow
cv::Mat convertedImg;
cv::cvtColor(webCamImg, convertedImage, CV_BGR2BGRA); //CV_8UC3 -> CV_8UC4
cv::directx::convertToD3D11Texture2D(convertedImg, myTexture); // (OLD: Throws exception!)

Here's the cv::Exception::what() at the first loop run:

C:\builds\master_PackSlave-win64-vc12-shared\opencv\modules\core\src\opencl\runtime\opencl_core.cpp:276: error (-220) OpenCL function is not available: [clGetPlatformIDs] in function opencl_check_fn

Next iterations yield different cv::Exception:

C:\builds\master_PackSlave-win64-vc12-shared\opencv\modules\core\src\directx.cpp:803: error (-222) OpenCL: Can't find functions for D3D11 in function cv::directx::__OpenCLinitializeD3D11

Here's the config log: http://pastebin.com/8i34sSRM

OpenCL is enabled in the config, but it's still not working. Any hints? Update Edit 2: After reinstalling my graphics drivers and CUDA 7.5, haveOpenCL() returns 1 suddenly. Also, I don't jump to the code anymore when I get a cv::Exception(). What's up with that?


EDIT1: Added cv::ocl::Context code and new exception (-222).

EDIT2: Problem shifted to cv::ocl::Context initialization after updating drivers.

EDIT3: Tried out the official DirectX11 sample code and I get the same exception.

cv::Mat to DirectX11 Texture (OpenCV 3.1.0)

Let's say I'm trying to display my webcam image in a game in DirectX11. I am using the prebuilt 3.1.0 libraries and I seem to be having difficulties with OpenCL while converting a Mat to a DirectX texture. I am using VS2013 Update 5 under Win10 and I am building a x64 windows application. The machine uses 2 x Nvidia Geforce GTX1080.

// CREATING DIRECTX TEXTURE
ID3D11Texture2D* myTexture = 0;
D3D11_TEXTURE2D_DEC desc_rgba;
desc_rgba.Width = 1024;
desc_rgba.Height = 768;
desc_rgba.MipLevels =1;
desc_rgba.ArraySize =1;
desc_rgba.Format = DXGI_FORMAT_R8G8B8A8_UNORM; // should be CV_8UC4
desc_rgba.SampleDesc.Count = 1;
desc_rgba.SampleDesc.Quality = 0;
desc_rgba.BindFlags = D3D11_BIND_SHADER_RESOURCE;
desc_rgba.Usage = D3D11_USAGE_DYNAMIC;
desc_rgba.CPUAccessFalgs = D3D11_CPU_ACCESS_WRITE;
desc_rgba.MiscFlags = 0;

HRESULT r = DIRECTX.Device->CreateTexture2D(&desc_rgba, 0, &myTexture);
if (FAILED(r)){
    throw std::runtime_error("Can't create DX texture!");
}

cv::ocl::Context oclContext;
if (cv::ocl::haveOpenCL()){// Returns 1        
    // NEW: Exception right here, writing at 0x0000...0
    oclContext = cv::directx::ocl::initializeContextFromD3D11Device(DIRECTX.Device); 
} 

//...

// GAME LOOP
// CV::MAT --> DIRECTX
cv::Mat webCamImg = ...; // get valid image somehow
cv::Mat convertedImg;
cv::cvtColor(webCamImg, convertedImage, CV_BGR2BGRA); //CV_8UC3 -> CV_8UC4
cv::directx::convertToD3D11Texture2D(convertedImg, myTexture); // (OLD: Throws exception!)

Here's the cv::Exception::what() at the first loop run:

C:\builds\master_PackSlave-win64-vc12-shared\opencv\modules\core\src\opencl\runtime\opencl_core.cpp:276: error (-220) OpenCL function initializeContextFromD3D11Device is troubling me. Even all the samples are not available: [clGetPlatformIDs] in function opencl_check_fn

Next iterations yield different cv::Exception:

C:\builds\master_PackSlave-win64-vc12-shared\opencv\modules\core\src\directx.cpp:803: error (-222) OpenCL: Can't find functions working for D3D11 in function cv::directx::__OpenCLinitializeD3D11me, but the OpenGL one does.

Here's the config log: http://pastebin.com/8i34sSRM

OpenCL is enabled in the config, but it's still not working. Any hints? Update Edit 2: After reinstalling my graphics drivers and CUDA 7.5, haveOpenCL() returns 1 suddenly. suddenly. Also, I don't jump to the code anymore when I get a cv::Exception(). What's up with that?


EDIT1: OLD! (EDIT1: Added cv::ocl::Context code and new exception (-222).(-222).)

EDIT2: Problem shifted to the cv::ocl::Context initialization after updating drivers.

EDIT3: Tried out the official DirectX11 sample code (EXAMPLE_DIRECTX d3d11_interop) and I get the same exception.

exception at the same place.

EDIT4:

  • EXAMPLE_DIRECTX d3d10_interop fails at the same line.
  • EXAMPLE_DIRECTX d3d9_interop fails at the same line.
  • EXAMPLE_DIRECTX d3d9ex_interop fails at the same line.
  • EXAMPLE _OPENGL opengl_interop actually works!

cv::Mat to DirectX11 Texture (OpenCV 3.1.0)

Let's say I'm trying to display my webcam image in a game in DirectX11. I am using the prebuilt 3.1.0 libraries and I seem to be having difficulties with OpenCL while converting a Mat to a DirectX texture. I am using VS2013 Update 5 under Win10 and I am building a x64 windows application. The machine uses 2 x Nvidia Geforce GTX1080.

// CREATING DIRECTX TEXTURE
ID3D11Texture2D* myTexture = 0;
D3D11_TEXTURE2D_DEC desc_rgba;
desc_rgba.Width = 1024;
desc_rgba.Height = 768;
desc_rgba.MipLevels =1;
desc_rgba.ArraySize =1;
desc_rgba.Format = DXGI_FORMAT_R8G8B8A8_UNORM; // should be CV_8UC4
desc_rgba.SampleDesc.Count = 1;
desc_rgba.SampleDesc.Quality = 0;
desc_rgba.BindFlags = D3D11_BIND_SHADER_RESOURCE;
desc_rgba.Usage = D3D11_USAGE_DYNAMIC;
desc_rgba.CPUAccessFalgs = D3D11_CPU_ACCESS_WRITE;
desc_rgba.MiscFlags = 0;

HRESULT r = DIRECTX.Device->CreateTexture2D(&desc_rgba, 0, &myTexture);
if (FAILED(r)){
    throw std::runtime_error("Can't create DX texture!");
}

cv::ocl::Context oclContext;
if (cv::ocl::haveOpenCL()){// Returns 1        
    // NEW: Exception right here, writing at 0x0000...0
    oclContext = cv::directx::ocl::initializeContextFromD3D11Device(DIRECTX.Device); 
} 

//...

// GAME LOOP
// CV::MAT --> DIRECTX
cv::Mat webCamImg = ...; // get valid image somehow
cv::Mat convertedImg;
cv::cvtColor(webCamImg, convertedImage, CV_BGR2BGRA); //CV_8UC3 -> CV_8UC4
cv::directx::convertToD3D11Texture2D(convertedImg, myTexture); // (OLD: Throws exception!)

initializeContextFromD3D11Device is troubling me. Even all the samples are not working for me, me because of this line, but the OpenGL one does.

Here's the config log: http://pastebin.com/8i34sSRM

Update Edit 2: After reinstalling my graphics drivers and CUDA 7.5, haveOpenCL() returns 1 suddenly. Also, I don't jump to the code anymore when I get a cv::Exception(). What's up with that?


OLD! (EDIT1: Added cv::ocl::Context code and new exception (-222).)

EDIT2: Problem shifted to the cv::ocl::Context initialization after updating drivers.

EDIT3: Tried out the official DirectX11 sample code (EXAMPLE_DIRECTX d3d11_interop) and I get the same exception at the same place.

EDIT4:

  • EXAMPLE_DIRECTX d3d10_interop fails at the same line.
  • EXAMPLE_DIRECTX d3d9_interop fails at the same line.
  • EXAMPLE_DIRECTX d3d9ex_interop fails at the same line.
  • EXAMPLE _OPENGL opengl_interop actually works!