How can I convert Image to Matrix and then Matrix to Bitmap in EmguCV?











up vote
1
down vote

favorite












I am trying to do something like the following:



public partial class Form1 : Form
{
const string path = @"lena.png";

public Form1()
{
InitializeComponent();

Image<Bgr, byte> color = new Image<Bgr, byte>(path);

Matrix<byte> matrix = new Matrix<byte>(color.Rows, color.Cols);

matrix.Data = color.ToMatrix();// just an analogy

pictureBox1.Image = col.Bitmap;
pictureBox2.Image = gray.Bitmap;
}
}


How can I convert Image to Matrix in EmguCV?



How can I convert Matrix to Bitmap?










share|improve this question
























  • If I read the docs right, they both inherit from CvArray, so maybe the CopyTo member? Btw, since the Image is 3-channel (BGR), then the Matrix should be as well for it to work.
    – Dan Mašek
    Nov 5 at 20:35










  • OK, so which one is it -- Image to Matrix or Matrix to Bitmap? ;) I just got my C# + EmguCV env set up (as I haven't really touched C# since the early days) to be able to give you a proper answer, and the shifting target is honestly a bit discouraging (I recall reading a meta post of yours where someone pointed this out as well).
    – Dan Mašek
    Nov 7 at 0:46












  • @DanMašek, your 1st comment solved my 1st problem. Now, I am stuck with the second one.
    – stackoverflow.com
    Nov 7 at 0:50










  • @DanMašek, I am rolling back the question to previous one.
    – stackoverflow.com
    Nov 7 at 0:51










  • @DanMašek, by the way, I am deleting my profile. So, don't be so tensed about meta.
    – stackoverflow.com
    Nov 7 at 0:51















up vote
1
down vote

favorite












I am trying to do something like the following:



public partial class Form1 : Form
{
const string path = @"lena.png";

public Form1()
{
InitializeComponent();

Image<Bgr, byte> color = new Image<Bgr, byte>(path);

Matrix<byte> matrix = new Matrix<byte>(color.Rows, color.Cols);

matrix.Data = color.ToMatrix();// just an analogy

pictureBox1.Image = col.Bitmap;
pictureBox2.Image = gray.Bitmap;
}
}


How can I convert Image to Matrix in EmguCV?



How can I convert Matrix to Bitmap?










share|improve this question
























  • If I read the docs right, they both inherit from CvArray, so maybe the CopyTo member? Btw, since the Image is 3-channel (BGR), then the Matrix should be as well for it to work.
    – Dan Mašek
    Nov 5 at 20:35










  • OK, so which one is it -- Image to Matrix or Matrix to Bitmap? ;) I just got my C# + EmguCV env set up (as I haven't really touched C# since the early days) to be able to give you a proper answer, and the shifting target is honestly a bit discouraging (I recall reading a meta post of yours where someone pointed this out as well).
    – Dan Mašek
    Nov 7 at 0:46












  • @DanMašek, your 1st comment solved my 1st problem. Now, I am stuck with the second one.
    – stackoverflow.com
    Nov 7 at 0:50










  • @DanMašek, I am rolling back the question to previous one.
    – stackoverflow.com
    Nov 7 at 0:51










  • @DanMašek, by the way, I am deleting my profile. So, don't be so tensed about meta.
    – stackoverflow.com
    Nov 7 at 0:51













up vote
1
down vote

favorite









up vote
1
down vote

favorite











I am trying to do something like the following:



public partial class Form1 : Form
{
const string path = @"lena.png";

public Form1()
{
InitializeComponent();

Image<Bgr, byte> color = new Image<Bgr, byte>(path);

Matrix<byte> matrix = new Matrix<byte>(color.Rows, color.Cols);

matrix.Data = color.ToMatrix();// just an analogy

pictureBox1.Image = col.Bitmap;
pictureBox2.Image = gray.Bitmap;
}
}


How can I convert Image to Matrix in EmguCV?



How can I convert Matrix to Bitmap?










share|improve this question















I am trying to do something like the following:



public partial class Form1 : Form
{
const string path = @"lena.png";

public Form1()
{
InitializeComponent();

Image<Bgr, byte> color = new Image<Bgr, byte>(path);

Matrix<byte> matrix = new Matrix<byte>(color.Rows, color.Cols);

matrix.Data = color.ToMatrix();// just an analogy

pictureBox1.Image = col.Bitmap;
pictureBox2.Image = gray.Bitmap;
}
}


How can I convert Image to Matrix in EmguCV?



How can I convert Matrix to Bitmap?







c# opencv emgucv






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 7 at 3:14









Dan Mašek

8,30632445




8,30632445










asked Nov 5 at 18:06









stackoverflow.com

3,52642155310




3,52642155310












  • If I read the docs right, they both inherit from CvArray, so maybe the CopyTo member? Btw, since the Image is 3-channel (BGR), then the Matrix should be as well for it to work.
    – Dan Mašek
    Nov 5 at 20:35










  • OK, so which one is it -- Image to Matrix or Matrix to Bitmap? ;) I just got my C# + EmguCV env set up (as I haven't really touched C# since the early days) to be able to give you a proper answer, and the shifting target is honestly a bit discouraging (I recall reading a meta post of yours where someone pointed this out as well).
    – Dan Mašek
    Nov 7 at 0:46












  • @DanMašek, your 1st comment solved my 1st problem. Now, I am stuck with the second one.
    – stackoverflow.com
    Nov 7 at 0:50










  • @DanMašek, I am rolling back the question to previous one.
    – stackoverflow.com
    Nov 7 at 0:51










  • @DanMašek, by the way, I am deleting my profile. So, don't be so tensed about meta.
    – stackoverflow.com
    Nov 7 at 0:51


















  • If I read the docs right, they both inherit from CvArray, so maybe the CopyTo member? Btw, since the Image is 3-channel (BGR), then the Matrix should be as well for it to work.
    – Dan Mašek
    Nov 5 at 20:35










  • OK, so which one is it -- Image to Matrix or Matrix to Bitmap? ;) I just got my C# + EmguCV env set up (as I haven't really touched C# since the early days) to be able to give you a proper answer, and the shifting target is honestly a bit discouraging (I recall reading a meta post of yours where someone pointed this out as well).
    – Dan Mašek
    Nov 7 at 0:46












  • @DanMašek, your 1st comment solved my 1st problem. Now, I am stuck with the second one.
    – stackoverflow.com
    Nov 7 at 0:50










  • @DanMašek, I am rolling back the question to previous one.
    – stackoverflow.com
    Nov 7 at 0:51










  • @DanMašek, by the way, I am deleting my profile. So, don't be so tensed about meta.
    – stackoverflow.com
    Nov 7 at 0:51
















If I read the docs right, they both inherit from CvArray, so maybe the CopyTo member? Btw, since the Image is 3-channel (BGR), then the Matrix should be as well for it to work.
– Dan Mašek
Nov 5 at 20:35




If I read the docs right, they both inherit from CvArray, so maybe the CopyTo member? Btw, since the Image is 3-channel (BGR), then the Matrix should be as well for it to work.
– Dan Mašek
Nov 5 at 20:35












OK, so which one is it -- Image to Matrix or Matrix to Bitmap? ;) I just got my C# + EmguCV env set up (as I haven't really touched C# since the early days) to be able to give you a proper answer, and the shifting target is honestly a bit discouraging (I recall reading a meta post of yours where someone pointed this out as well).
– Dan Mašek
Nov 7 at 0:46






OK, so which one is it -- Image to Matrix or Matrix to Bitmap? ;) I just got my C# + EmguCV env set up (as I haven't really touched C# since the early days) to be able to give you a proper answer, and the shifting target is honestly a bit discouraging (I recall reading a meta post of yours where someone pointed this out as well).
– Dan Mašek
Nov 7 at 0:46














@DanMašek, your 1st comment solved my 1st problem. Now, I am stuck with the second one.
– stackoverflow.com
Nov 7 at 0:50




@DanMašek, your 1st comment solved my 1st problem. Now, I am stuck with the second one.
– stackoverflow.com
Nov 7 at 0:50












@DanMašek, I am rolling back the question to previous one.
– stackoverflow.com
Nov 7 at 0:51




@DanMašek, I am rolling back the question to previous one.
– stackoverflow.com
Nov 7 at 0:51












@DanMašek, by the way, I am deleting my profile. So, don't be so tensed about meta.
– stackoverflow.com
Nov 7 at 0:51




@DanMašek, by the way, I am deleting my profile. So, don't be so tensed about meta.
– stackoverflow.com
Nov 7 at 0:51












1 Answer
1






active

oldest

votes

















up vote
0
down vote



accepted










Converting Image to Matrix



The important thing to notice here is that both Image and Matrix inherit from CvArray. That means it is possible to use the (inherited) method CopyTo to copy the data from an Image instance to a Matrix instance of identical depth and dimensions.



NB: There are 3 dimensions of relevance -- width, height, and channel count.



Image<Bgr, byte> color = ... ; // Initialized in some manner

Matrix<byte> matrix = new Matrix<byte>(color.Rows, color.Cols, color.NumberOfChannels);

color.CopyTo(matrix);


NB: There's a cost involved with this approach, due to the necessity to make a copy of the entire data array.



Converting Matrix to Bitmap



This one is actually quite simple. Matrix inherits the property Mat, which returns a Mat header (meaning a thin wrapper around an existing data array) for the array data. Since this just creates a header, it's very quick (no copies involved).



NB: Due to being a header, I assume based on my experience with the C++ API (even though this doesn't seem documented) that the Mat object is valid as long as the underlying Matrix object stays in scope.



Mat provides a Bitmap property, which behaves identically to Image.Bitmap.



Bitmap b = matrix.Mat.Bitmap;


The other option is to use the same approach as before to copy the data back to the Image instance.



matrix.CopyTo(color);


Then you could use the Bitmap property (fast, but requires the Image instance to live as long as you use the Bitmap).



Bitmap b = color.Bitmap;


Another alternative would be to use the ToBitmap method, which copies the data, and therefore doesn't carry the dependency on the source Image instance.



Bitmap b = color.ToBitmap();




Source used for testing:



using System;
using System.Drawing;
using Emgu.CV;
using Emgu.CV.Structure;
// ============================================================================
namespace CS1 {
// ============================================================================
class Test
{
static void Main()
{
Image<Bgr, byte> color = new Image<Bgr, byte>(2, 2);
for (int r = 0; r < color.Rows; r++) {
for (int c = 0; c < color.Cols; c++) {
int n = (c + r * color.Cols) * 3;
color[r, c] = new Bgr(n, n+1, n+2);
}
}

Matrix<byte> matrix = new Matrix<byte>(color.Rows, color.Cols, color.NumberOfChannels);

color.CopyTo(matrix);

Bitmap b = matrix.Mat.Bitmap;

matrix.CopyTo(color);

b = color.Bitmap;

b = color.ToBitmap();
}
}
// ============================================================================
} // namespace CS1
// ============================================================================


The CMake file I used to generate a solution to compile this:



cmake_minimum_required(VERSION 3.11)
project(CS1 VERSION 0.1.0 LANGUAGES CSharp)

add_executable(cs1
src/test.cs
)

set_property(TARGET cs1
PROPERTY VS_DOTNET_TARGET_FRAMEWORK_VERSION "v4.6.1"
)

set_property(TARGET cs1
PROPERTY VS_DOTNET_REFERENCES
"System"
"System.Drawing"
)

set_target_properties(cs1 PROPERTIES
VS_DOTNET_REFERENCE_emgu_cv_world "deps/Emgu.CV.World.dll"
)





share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53159851%2fhow-can-i-convert-image-to-matrix-and-then-matrix-to-bitmap-in-emgucv%23new-answer', 'question_page');
    }
    );

    Post as a guest
































    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote



    accepted










    Converting Image to Matrix



    The important thing to notice here is that both Image and Matrix inherit from CvArray. That means it is possible to use the (inherited) method CopyTo to copy the data from an Image instance to a Matrix instance of identical depth and dimensions.



    NB: There are 3 dimensions of relevance -- width, height, and channel count.



    Image<Bgr, byte> color = ... ; // Initialized in some manner

    Matrix<byte> matrix = new Matrix<byte>(color.Rows, color.Cols, color.NumberOfChannels);

    color.CopyTo(matrix);


    NB: There's a cost involved with this approach, due to the necessity to make a copy of the entire data array.



    Converting Matrix to Bitmap



    This one is actually quite simple. Matrix inherits the property Mat, which returns a Mat header (meaning a thin wrapper around an existing data array) for the array data. Since this just creates a header, it's very quick (no copies involved).



    NB: Due to being a header, I assume based on my experience with the C++ API (even though this doesn't seem documented) that the Mat object is valid as long as the underlying Matrix object stays in scope.



    Mat provides a Bitmap property, which behaves identically to Image.Bitmap.



    Bitmap b = matrix.Mat.Bitmap;


    The other option is to use the same approach as before to copy the data back to the Image instance.



    matrix.CopyTo(color);


    Then you could use the Bitmap property (fast, but requires the Image instance to live as long as you use the Bitmap).



    Bitmap b = color.Bitmap;


    Another alternative would be to use the ToBitmap method, which copies the data, and therefore doesn't carry the dependency on the source Image instance.



    Bitmap b = color.ToBitmap();




    Source used for testing:



    using System;
    using System.Drawing;
    using Emgu.CV;
    using Emgu.CV.Structure;
    // ============================================================================
    namespace CS1 {
    // ============================================================================
    class Test
    {
    static void Main()
    {
    Image<Bgr, byte> color = new Image<Bgr, byte>(2, 2);
    for (int r = 0; r < color.Rows; r++) {
    for (int c = 0; c < color.Cols; c++) {
    int n = (c + r * color.Cols) * 3;
    color[r, c] = new Bgr(n, n+1, n+2);
    }
    }

    Matrix<byte> matrix = new Matrix<byte>(color.Rows, color.Cols, color.NumberOfChannels);

    color.CopyTo(matrix);

    Bitmap b = matrix.Mat.Bitmap;

    matrix.CopyTo(color);

    b = color.Bitmap;

    b = color.ToBitmap();
    }
    }
    // ============================================================================
    } // namespace CS1
    // ============================================================================


    The CMake file I used to generate a solution to compile this:



    cmake_minimum_required(VERSION 3.11)
    project(CS1 VERSION 0.1.0 LANGUAGES CSharp)

    add_executable(cs1
    src/test.cs
    )

    set_property(TARGET cs1
    PROPERTY VS_DOTNET_TARGET_FRAMEWORK_VERSION "v4.6.1"
    )

    set_property(TARGET cs1
    PROPERTY VS_DOTNET_REFERENCES
    "System"
    "System.Drawing"
    )

    set_target_properties(cs1 PROPERTIES
    VS_DOTNET_REFERENCE_emgu_cv_world "deps/Emgu.CV.World.dll"
    )





    share|improve this answer

























      up vote
      0
      down vote



      accepted










      Converting Image to Matrix



      The important thing to notice here is that both Image and Matrix inherit from CvArray. That means it is possible to use the (inherited) method CopyTo to copy the data from an Image instance to a Matrix instance of identical depth and dimensions.



      NB: There are 3 dimensions of relevance -- width, height, and channel count.



      Image<Bgr, byte> color = ... ; // Initialized in some manner

      Matrix<byte> matrix = new Matrix<byte>(color.Rows, color.Cols, color.NumberOfChannels);

      color.CopyTo(matrix);


      NB: There's a cost involved with this approach, due to the necessity to make a copy of the entire data array.



      Converting Matrix to Bitmap



      This one is actually quite simple. Matrix inherits the property Mat, which returns a Mat header (meaning a thin wrapper around an existing data array) for the array data. Since this just creates a header, it's very quick (no copies involved).



      NB: Due to being a header, I assume based on my experience with the C++ API (even though this doesn't seem documented) that the Mat object is valid as long as the underlying Matrix object stays in scope.



      Mat provides a Bitmap property, which behaves identically to Image.Bitmap.



      Bitmap b = matrix.Mat.Bitmap;


      The other option is to use the same approach as before to copy the data back to the Image instance.



      matrix.CopyTo(color);


      Then you could use the Bitmap property (fast, but requires the Image instance to live as long as you use the Bitmap).



      Bitmap b = color.Bitmap;


      Another alternative would be to use the ToBitmap method, which copies the data, and therefore doesn't carry the dependency on the source Image instance.



      Bitmap b = color.ToBitmap();




      Source used for testing:



      using System;
      using System.Drawing;
      using Emgu.CV;
      using Emgu.CV.Structure;
      // ============================================================================
      namespace CS1 {
      // ============================================================================
      class Test
      {
      static void Main()
      {
      Image<Bgr, byte> color = new Image<Bgr, byte>(2, 2);
      for (int r = 0; r < color.Rows; r++) {
      for (int c = 0; c < color.Cols; c++) {
      int n = (c + r * color.Cols) * 3;
      color[r, c] = new Bgr(n, n+1, n+2);
      }
      }

      Matrix<byte> matrix = new Matrix<byte>(color.Rows, color.Cols, color.NumberOfChannels);

      color.CopyTo(matrix);

      Bitmap b = matrix.Mat.Bitmap;

      matrix.CopyTo(color);

      b = color.Bitmap;

      b = color.ToBitmap();
      }
      }
      // ============================================================================
      } // namespace CS1
      // ============================================================================


      The CMake file I used to generate a solution to compile this:



      cmake_minimum_required(VERSION 3.11)
      project(CS1 VERSION 0.1.0 LANGUAGES CSharp)

      add_executable(cs1
      src/test.cs
      )

      set_property(TARGET cs1
      PROPERTY VS_DOTNET_TARGET_FRAMEWORK_VERSION "v4.6.1"
      )

      set_property(TARGET cs1
      PROPERTY VS_DOTNET_REFERENCES
      "System"
      "System.Drawing"
      )

      set_target_properties(cs1 PROPERTIES
      VS_DOTNET_REFERENCE_emgu_cv_world "deps/Emgu.CV.World.dll"
      )





      share|improve this answer























        up vote
        0
        down vote



        accepted







        up vote
        0
        down vote



        accepted






        Converting Image to Matrix



        The important thing to notice here is that both Image and Matrix inherit from CvArray. That means it is possible to use the (inherited) method CopyTo to copy the data from an Image instance to a Matrix instance of identical depth and dimensions.



        NB: There are 3 dimensions of relevance -- width, height, and channel count.



        Image<Bgr, byte> color = ... ; // Initialized in some manner

        Matrix<byte> matrix = new Matrix<byte>(color.Rows, color.Cols, color.NumberOfChannels);

        color.CopyTo(matrix);


        NB: There's a cost involved with this approach, due to the necessity to make a copy of the entire data array.



        Converting Matrix to Bitmap



        This one is actually quite simple. Matrix inherits the property Mat, which returns a Mat header (meaning a thin wrapper around an existing data array) for the array data. Since this just creates a header, it's very quick (no copies involved).



        NB: Due to being a header, I assume based on my experience with the C++ API (even though this doesn't seem documented) that the Mat object is valid as long as the underlying Matrix object stays in scope.



        Mat provides a Bitmap property, which behaves identically to Image.Bitmap.



        Bitmap b = matrix.Mat.Bitmap;


        The other option is to use the same approach as before to copy the data back to the Image instance.



        matrix.CopyTo(color);


        Then you could use the Bitmap property (fast, but requires the Image instance to live as long as you use the Bitmap).



        Bitmap b = color.Bitmap;


        Another alternative would be to use the ToBitmap method, which copies the data, and therefore doesn't carry the dependency on the source Image instance.



        Bitmap b = color.ToBitmap();




        Source used for testing:



        using System;
        using System.Drawing;
        using Emgu.CV;
        using Emgu.CV.Structure;
        // ============================================================================
        namespace CS1 {
        // ============================================================================
        class Test
        {
        static void Main()
        {
        Image<Bgr, byte> color = new Image<Bgr, byte>(2, 2);
        for (int r = 0; r < color.Rows; r++) {
        for (int c = 0; c < color.Cols; c++) {
        int n = (c + r * color.Cols) * 3;
        color[r, c] = new Bgr(n, n+1, n+2);
        }
        }

        Matrix<byte> matrix = new Matrix<byte>(color.Rows, color.Cols, color.NumberOfChannels);

        color.CopyTo(matrix);

        Bitmap b = matrix.Mat.Bitmap;

        matrix.CopyTo(color);

        b = color.Bitmap;

        b = color.ToBitmap();
        }
        }
        // ============================================================================
        } // namespace CS1
        // ============================================================================


        The CMake file I used to generate a solution to compile this:



        cmake_minimum_required(VERSION 3.11)
        project(CS1 VERSION 0.1.0 LANGUAGES CSharp)

        add_executable(cs1
        src/test.cs
        )

        set_property(TARGET cs1
        PROPERTY VS_DOTNET_TARGET_FRAMEWORK_VERSION "v4.6.1"
        )

        set_property(TARGET cs1
        PROPERTY VS_DOTNET_REFERENCES
        "System"
        "System.Drawing"
        )

        set_target_properties(cs1 PROPERTIES
        VS_DOTNET_REFERENCE_emgu_cv_world "deps/Emgu.CV.World.dll"
        )





        share|improve this answer












        Converting Image to Matrix



        The important thing to notice here is that both Image and Matrix inherit from CvArray. That means it is possible to use the (inherited) method CopyTo to copy the data from an Image instance to a Matrix instance of identical depth and dimensions.



        NB: There are 3 dimensions of relevance -- width, height, and channel count.



        Image<Bgr, byte> color = ... ; // Initialized in some manner

        Matrix<byte> matrix = new Matrix<byte>(color.Rows, color.Cols, color.NumberOfChannels);

        color.CopyTo(matrix);


        NB: There's a cost involved with this approach, due to the necessity to make a copy of the entire data array.



        Converting Matrix to Bitmap



        This one is actually quite simple. Matrix inherits the property Mat, which returns a Mat header (meaning a thin wrapper around an existing data array) for the array data. Since this just creates a header, it's very quick (no copies involved).



        NB: Due to being a header, I assume based on my experience with the C++ API (even though this doesn't seem documented) that the Mat object is valid as long as the underlying Matrix object stays in scope.



        Mat provides a Bitmap property, which behaves identically to Image.Bitmap.



        Bitmap b = matrix.Mat.Bitmap;


        The other option is to use the same approach as before to copy the data back to the Image instance.



        matrix.CopyTo(color);


        Then you could use the Bitmap property (fast, but requires the Image instance to live as long as you use the Bitmap).



        Bitmap b = color.Bitmap;


        Another alternative would be to use the ToBitmap method, which copies the data, and therefore doesn't carry the dependency on the source Image instance.



        Bitmap b = color.ToBitmap();




        Source used for testing:



        using System;
        using System.Drawing;
        using Emgu.CV;
        using Emgu.CV.Structure;
        // ============================================================================
        namespace CS1 {
        // ============================================================================
        class Test
        {
        static void Main()
        {
        Image<Bgr, byte> color = new Image<Bgr, byte>(2, 2);
        for (int r = 0; r < color.Rows; r++) {
        for (int c = 0; c < color.Cols; c++) {
        int n = (c + r * color.Cols) * 3;
        color[r, c] = new Bgr(n, n+1, n+2);
        }
        }

        Matrix<byte> matrix = new Matrix<byte>(color.Rows, color.Cols, color.NumberOfChannels);

        color.CopyTo(matrix);

        Bitmap b = matrix.Mat.Bitmap;

        matrix.CopyTo(color);

        b = color.Bitmap;

        b = color.ToBitmap();
        }
        }
        // ============================================================================
        } // namespace CS1
        // ============================================================================


        The CMake file I used to generate a solution to compile this:



        cmake_minimum_required(VERSION 3.11)
        project(CS1 VERSION 0.1.0 LANGUAGES CSharp)

        add_executable(cs1
        src/test.cs
        )

        set_property(TARGET cs1
        PROPERTY VS_DOTNET_TARGET_FRAMEWORK_VERSION "v4.6.1"
        )

        set_property(TARGET cs1
        PROPERTY VS_DOTNET_REFERENCES
        "System"
        "System.Drawing"
        )

        set_target_properties(cs1 PROPERTIES
        VS_DOTNET_REFERENCE_emgu_cv_world "deps/Emgu.CV.World.dll"
        )






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 7 at 3:03









        Dan Mašek

        8,30632445




        8,30632445






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53159851%2fhow-can-i-convert-image-to-matrix-and-then-matrix-to-bitmap-in-emgucv%23new-answer', 'question_page');
            }
            );

            Post as a guest




















































































            這個網誌中的熱門文章

            Academy of Television Arts & Sciences

            L'Équipe

            1995 France bombings