Page 1 of 2

[C++, OpenCV] Display image CV::Mat queue as video in XAML

Posted: 06 Jun 2019, 12:29
by ducdanganhit
Hello,
I am implementing to show video on GUI from OpenCV cv::Mat. I have a queue of cv::Mat as video frames read from video.
How to show cv::mat into XAML GUI?

Any idea? or an example?
Thanks in advanced!

Re: [C++, OpenCV] Display image CV::Mat queue as video in XAML

Posted: 06 Jun 2019, 15:48
by whidbey
guess you would like to use cbimtmap ..

Re: [C++, OpenCV] Display image CV::Mat queue as video in XAML

Posted: 06 Jun 2019, 18:23
by sfernandez
You need to create a texture that will be updated with that video frame data.
Then create a TextureSource from that texture and use it as image source of an Image (or ImageBrush).
You can take a look at our Images tutorial for more info: https://www.noesisengine.com/docs/Gui.C ... ime-images

Re: [C++, OpenCV] Display image CV::Mat queue as video in XAML

Posted: 07 Jun 2019, 04:39
by ducdanganhit
NIce suggestion. I will try it. Thank you very much.

Re: [C++, OpenCV] Display image CV::Mat queue as video in XAML

Posted: 10 Jun 2019, 12:56
by jsantos
For example, If you are using D3D11 you can create a texture using an external handle with WrapTexture:
struct NS_RENDER_D3D11RENDERDEVICE_API D3D11Factory
{
    static Noesis::Ptr<Noesis::Texture> WrapTexture(ID3D11Texture2D* texture, uint32_t width,
        uint32_t height, uint32_t levels, bool isInverted);
};

Re: [C++, OpenCV] Display image CV::Mat queue as video in XAML

Posted: 13 Jun 2019, 05:29
by ducdanganhit
For example, If you are using D3D11 you can create a texture using an external handle with WrapTexture:
struct NS_RENDER_D3D11RENDERDEVICE_API D3D11Factory
{
    static Noesis::Ptr<Noesis::Texture> WrapTexture(ID3D11Texture2D* texture, uint32_t width,
        uint32_t height, uint32_t levels, bool isInverted);
};
How to convert an image to ID3D11Texture2D* type or Cv::Mat to ID3D11Texture2D* or TextureSource? I have not made any games(need Unity?), so i cant understand how to do this.

Re: [C++, OpenCV] Display image CV::Mat queue as video in XAML

Posted: 14 Jun 2019, 09:49
by ducdanganhit
I tried to convert from cv::Mat to ID3D11Texture2D* but got an error:
Main.cpp:58: undefined reference to `NoesisApp::D3D11Factory::WrapTexture(ID3D11Texture2D*, unsigned int, unsigned int, unsigned int, bool)'

This is my code:
cv::Mat img = cv::imread("./photo_2018-12-25_23-49-35.jpg");
ID3D11Texture2D* d3dTexture;
cv::directx::convertToD3D11Texture2D(img, d3dTexture);
Ptr<Texture> texture = D3D11Factory::WrapTexture(d3dTexture, 512, 512, 1, false);
Image* image = this->FindName<Image>("image1");
image->SetSource(MakePtr<TextureSource>(texture));
I thought i was missing implementation of this header file "NoesisApp::D3D11Factory::WrapTexture"
I included the header /Src/Packages/Render/D3D11RenderDevice/Include/NsRender/D3D11Factory.h

I saw the implementation of "D3D11Factory::WrapTexture" in Src/Packages/Render/D3D11RenderDevice/Src/Render.D3D11RenderDevice.cpp. was it included in libNoesis.so or libNoesisApp.so? Or should i include "Render.D3D11RenderDevice.cpp" manually into project?
Thanks!

Re: [C++, OpenCV] Display image CV::Mat queue as video in XAML

Posted: 14 Jun 2019, 14:24
by jsantos
I tried to convert from cv::Mat to ID3D11Texture2D* but got an error:
Main.cpp:58: undefined reference to `NoesisApp::D3D11Factory::WrapTexture(ID3D11Texture2D*, unsigned int, unsigned int, unsigned int, bool)'
Sorry, I have no idea what is "cv::Mat", you need probably to get assistance in other forums about it. That's not a NoesisGUI thing.
I saw the implementation of "D3D11Factory::WrapTexture" in Src/Packages/Render/D3D11RenderDevice/Src/Render.D3D11RenderDevice.cpp. was it included in libNoesis.so or libNoesisApp.so? Or should i include "Render.D3D11RenderDevice.cpp" manually into project?
All the source you see in our SDK is part of the application framework (libNoesisApp.so). You can use that code as reference to build your own integration with NoesisGUI.

Re: [C++, OpenCV] Display image CV::Mat queue as video in XAML

Posted: 17 Jun 2019, 05:21
by ducdanganhit
For example, If you are using D3D11 you can create a texture using an external handle with WrapTexture:
struct NS_RENDER_D3D11RENDERDEVICE_API D3D11Factory
{
    static Noesis::Ptr<Noesis::Texture> WrapTexture(ID3D11Texture2D* texture, uint32_t width,
        uint32_t height, uint32_t levels, bool isInverted);
};
Hi @jsantos,
I added #include <NsRender/D3D11Factory.h> to use WrapTexture in D3D11Factory. But i got this message:
undefined reference to `NoesisApp::D3D11Factory::WrapTexture(ID3D11Texture2D*, unsigned int, unsigned int, unsigned int, bool)'
It seems that the program could not find implementation of WrapTexture. does libNoesisApp.so or libNoesis.socontain WrapTexture implementation?
Thank you!

Re: [C++, OpenCV] Display image CV::Mat queue as video in XAML

Posted: 18 Jun 2019, 16:55
by jsantos
It seems that the program could not find implementation of WrapTexture. does libNoesisApp.so or libNoesis.socontain WrapTexture implementation?
Thank you!
If you search inside the code you will find the implementation in the D3D11RenderDevice.cpp file.