This forum contains outdated content and is available for reading only. Please contact technical support if you have any questions.

Notification

Icon
Error

Options
Go to last post Go to first unread
lauren@photoboothsupplyco.com  
#1 Posted : Monday, July 31, 2017 7:23:58 AM(UTC)
lauren@photoboothsupplyco.com

Rank: Member

Groups: Guest
Joined: 7/30/2017(UTC)
Posts: 18

Thanks: 7 times
HI,

I apologize if this an elementary question but I'm a noob with Graphics Mill and tried doing a search as well as looking at the docs before posting this and did not find an answer to these questions. As a little background on my environment, I'm working on a WPF C# project where I am currently making use of the System.Drawing.Bitmap class.

  • I see where the constructor of a Graphics Mill is able to take a Bitmap as a parameter. Is this a Graphics Mill Bitmap or a System.Drawing.Bitmap?

  • I am also making use of the Emgu CV library and have a cv.Mat object. Is there a way to convert this to a Graphics Mill Bitmap? I guess if I can construct a Graphics Mill Bitmap from a System.Drawing.Bitmap this would be easy enough via the Bitmap property of the CV class.

  • I have the raw byte data of an image captured from a camera, what is the easiest way to construct a Graphics Mill Bitmap from this byte data?

Thanks!

Fedor  
#2 Posted : Monday, July 31, 2017 9:56:32 AM(UTC)
Fedor

Rank: Advanced Member

Groups: Guest
Joined: 7/28/2003(UTC)
Posts: 1,660

Thanks: 5 times
Was thanked: 76 time(s) in 74 post(s)
lauren@photoboothsupplyco.com wrote:
I see where the constructor of a Graphics Mill is able to take a Bitmap as a parameter. Is this a Graphics Mill Bitmap or a System.Drawing.Bitmap?

The constructor accepts both Aurigma.GraphicsMill.Bitmap and System.Drawing.Bitmap types:

Code:
using (var sdBitmap = new System.Drawing.Bitmap("../../../eagle.jpg"))
using (var gmBitmap = new Aurigma.GraphicsMill.Bitmap(sdBitmap))
{
	gmBitmap.Save("../../../out1.jpg");
}

lauren@photoboothsupplyco.com wrote:
I am also making use of the Emgu CV library and have a cv.Mat object. Is there a way to convert this to a Graphics Mill Bitmap? I guess if I can construct a Graphics Mill Bitmap from a System.Drawing.Bitmap this would be easy enough via the Bitmap property of the CV class.

Yes, you can use the System.Drawing.Bitmap class for the conversion from cv.Mat to Graphics Mill Bitmap:

Code:
using (Mat mat = CvInvoke.Imread("../../../eagle.jpg", Emgu.CV.CvEnum.ImreadModes.AnyColor))
using (var gmBitmap = new Aurigma.GraphicsMill.Bitmap(mat.Bitmap))
{
	gmBitmap.Save("../../../out2.jpg");
}

Please let me know if you experience any problems with speed and need the direct conversion from cv.Mat to Graphics Mill Bitmap.

lauren@photoboothsupplyco.com wrote:
I have the raw byte data of an image captured from a camera, what is the easiest way to construct a Graphics Mill Bitmap from this byte data?

What is format of raw byte data?

Best regards,

Fedor Skvortsov

lauren@photoboothsupplyco.com  
#3 Posted : Monday, July 31, 2017 11:02:51 AM(UTC)
lauren@photoboothsupplyco.com

Rank: Member

Groups: Guest
Joined: 7/30/2017(UTC)
Posts: 18

Thanks: 7 times
Thanks for the quick reply on this. To start with the last question, I'm not sure what the format of the raw byte data is actually. I'm using a Basler camera and will have to look into the settings of that in order to get the format. I know right now the image grabbed from the camera is being converted to a cv.Mat object and then I start to manipulate it from there. I was thinking if I could actually pull out the OpenCV stuff and use the Graphics Mill library it might save me some time since I am switching over anyway.

And I am very much concerned with speed to any help you can give in regards to converting a cv.Mat object to a Graphics Mill Bitmap is greatly appreciated.

Thanks!

Eugene Kosmin  
#4 Posted : Tuesday, August 1, 2017 9:27:52 PM(UTC)
Eugene Kosmin

Rank: Advanced Member

Groups: Guest
Joined: 9/19/2006(UTC)
Posts: 505

Was thanked: 41 time(s) in 41 post(s)
Hi,

The fastest way is to use one Bitmap and copy content from Mat object. You need to choose pixel format properly looking at NumberOfChannels and Depth properties.

If possible, you should use Rgb24 format. GraphicsMill doesn't support YUV and float pixel formats.

Pay attention to the order of color channels. In Graphics Mill all channels are placed in the reverse order. For example, Format24bppRgb format actually looks like BGRBGR internally.

Here is a pseudocode:

Code:
var bitmap = new Bitmap(width, height, pixelFormat);

unsafe
{
    byte* scanline = (byte*)bitmap.Scan0.ToPointer();
    byte* matRow= (byte*)mat.DataPointer.ToPointer();

    for (int i = 0; i < bitmap.Height; i++)
    {
        System.Buffer.MemoryCopy(matRow, scanline, bitmap.Stride, mat.Step);
        scanline += bitmap.Stride;
        matRow += mat.Step;
    }
}

// Some further operations with Bitmap...
Best regards,

Eugene Kosmin

The Aurigma Development Team

lauren@photoboothsupplyco.com  
#5 Posted : Saturday, August 5, 2017 5:08:34 PM(UTC)
lauren@photoboothsupplyco.com

Rank: Member

Groups: Guest
Joined: 7/30/2017(UTC)
Posts: 18

Thanks: 7 times
As a follow up question, what is the best way to go from a GraphicsMill bitmap to a System.Drawing.Bitmap?
Eugene Kosmin  
#6 Posted : Sunday, August 6, 2017 5:39:08 PM(UTC)
Eugene Kosmin

Rank: Advanced Member

Groups: Guest
Joined: 9/19/2006(UTC)
Posts: 505

Was thanked: 41 time(s) in 41 post(s)
There is only one way: Bitmap.ToGdiPlusBitmap.
Best regards,

Eugene Kosmin

The Aurigma Development Team

thanks 1 user thanked Eugene Kosmin for this useful post.
lauren@photoboothsupplyco.com  
#7 Posted : Sunday, October 29, 2017 9:26:21 PM(UTC)
lauren@photoboothsupplyco.com

Rank: Member

Groups: Guest
Joined: 7/30/2017(UTC)
Posts: 18

Thanks: 7 times
I know it's been awhile since I posted on this thread but I came across a situation where I need to convert a Graphics Mill Bitmap to an Emgu CV Mat object and was wondering how that would be accomplished?

TIA

Eugene Kosmin  
#8 Posted : Tuesday, October 31, 2017 4:59:25 PM(UTC)
Eugene Kosmin

Rank: Advanced Member

Groups: Guest
Joined: 9/19/2006(UTC)
Posts: 505

Was thanked: 41 time(s) in 41 post(s)
Please have a look at this question on StackOverflow. You can get Mat object from System.Drawing.Bitmap or you can try to use the same technique with GM Bitmap.

It also provides the access to pixel data through Scan0 and Stride properties.

So the code would be something like that:

Code:

var gmBitmap = new Aurigma.GraphicsMill.Bitmap(...);
//....
Image<Bgra, byte> cvImage = new Image<Bgra, byte>(gmBitmap.Width, gmBitmap.Height, gmBitmap.Stride, (IntPtr)gmBitmap.Scan0);
return cvImage.Mat

Best regards,

Eugene Kosmin

The Aurigma Development Team

thanks 1 user thanked Eugene Kosmin for this useful post.
lauren@photoboothsupplyco.com on 11/1/2017(UTC)
Users browsing this topic
Guest (3)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.