新建
上传
首页
助手
最?/div>
资料?/div>
工具

C#Bitmap

?/p>

C++ opencv Mat

相互转换

 

C#

调用

C++ 

编译成的

dll

,这?/p>

dll

中包?/p>

Opencv

个的

Mat

?/p>

c#

?/p>

Bitmap

转换,具体代码如下:

 

C++

部分?/p>

 

首先创建

win32

应用程序,选择类库模板

 

 

DLL_API

 

uchar

 * 

_stdcall

 run1(

char

* 

filename

, 

int

 & 

width

, 

int

 & 

height

, 

int

 & 

step

) 

{ 

 

 

IplImage

* uu = cvLoadImage(

filename

); 

 

IplImage

* dst1 = cvCreateImage(cvSize(uu->width, uu->height), 8, 1); 

 

cvCvtColor(uu, dst1, 

CV_RGB2GRAY

); 

 

Mat

 ss = cvarrToMat(uu); 

 

uchar

 * data = 

new 

uchar

[uu->width*uu->height * 3]; 

 

data = ss.data; 

 

width

 = ss.size

()

.width; 

 

height

 = ss.size

()

.height; 

 

step

 = ss.step; 

 

return

 data; 

} 

C#

中调用这?/p>

dll 

[

DllImport

(

@"E:\Files\BarcodeProject\Code\testCode\OpenCvAssemblies\Debug\OpenC

vAssemblies.dll"

)] 

        

public

 

static

 

extern

 

IntPtr

 

run1(

string

 

a, 

out

 

int

 

width, 

out

 

int

 

height, 

out

 

int

 step); 

至此完成

C++ Mat 

?/p>

Bitmap

的转?/p>

 

 

 

下面?/p>

Bitmap 

?/p>

 Mat 

的转?/p>

 

C# 

部分

 

public

 

static

 

BitmapInfo

 GetImagePixel(

Bitmap

 Source) 

        { 

            

byte

[] result; 

            

int

 step; 

            

int

 iWidth = Source.Width; 

            

int

 iHeight = Source.Height; 

            

Rectangle

 rect = 

new

 

Rectangle

(0, 0, iWidth, iHeight); 

            System.Drawing.Imaging.

BitmapData

 bmpData = Source.LockBits(rect, 

System.Drawing.Imaging.

ImageLockMode

.ReadWrite, Source.PixelFormat); 

            

IntPtr

 iPtr = bmpData.Scan0; 

            

int

 iBytes = iWidth * iHeight * 3;  

//

根据通道数进行设?/p>

  

 

Ͼλ
新建
上传
首页
助手
最?/div>
资料?/div>
工具

C#Bitmap

?/p>

C++ opencv Mat

相互转换

 

C#

调用

C++ 

编译成的

dll

,这?/p>

dll

中包?/p>

Opencv

个的

Mat

?/p>

c#

?/p>

Bitmap

转换,具体代码如下:

 

C++

部分?/p>

 

首先创建

win32

应用程序,选择类库模板

 

 

DLL_API

 

uchar

 * 

_stdcall

 run1(

char

* 

filename

, 

int

 & 

width

, 

int

 & 

height

, 

int

 & 

step

) 

{ 

 

 

IplImage

* uu = cvLoadImage(

filename

); 

 

IplImage

* dst1 = cvCreateImage(cvSize(uu->width, uu->height), 8, 1); 

 

cvCvtColor(uu, dst1, 

CV_RGB2GRAY

); 

 

Mat

 ss = cvarrToMat(uu); 

 

uchar

 * data = 

new 

uchar

[uu->width*uu->height * 3]; 

 

data = ss.data; 

 

width

 = ss.size

()

.width; 

 

height

 = ss.size

()

.height; 

 

step

 = ss.step; 

 

return

 data; 

} 

C#

中调用这?/p>

dll 

[

DllImport

(

@"E:\Files\BarcodeProject\Code\testCode\OpenCvAssemblies\Debug\OpenC

vAssemblies.dll"

)] 

        

public

 

static

 

extern

 

IntPtr

 

run1(

string

 

a, 

out

 

int

 

width, 

out

 

int

 

height, 

out

 

int

 step); 

至此完成

C++ Mat 

?/p>

Bitmap

的转?/p>

 

 

 

下面?/p>

Bitmap 

?/p>

 Mat 

的转?/p>

 

C# 

部分

 

public

 

static

 

BitmapInfo

 GetImagePixel(

Bitmap

 Source) 

        { 

            

byte

[] result; 

            

int

 step; 

            

int

 iWidth = Source.Width; 

            

int

 iHeight = Source.Height; 

            

Rectangle

 rect = 

new

 

Rectangle

(0, 0, iWidth, iHeight); 

            System.Drawing.Imaging.

BitmapData

 bmpData = Source.LockBits(rect, 

System.Drawing.Imaging.

ImageLockMode

.ReadWrite, Source.PixelFormat); 

            

IntPtr

 iPtr = bmpData.Scan0; 

            

int

 iBytes = iWidth * iHeight * 3;  

//

根据通道数进行设?/p>

  

 

">
新建
上传
首页
助手
最?/div>
资料?/div>
工具

C#Bitmap

?/p>

C++ opencv Mat

相互转换

 

C#

调用

C++ 

编译成的

dll

,这?/p>

dll

中包?/p>

Opencv

个的

Mat

?/p>

c#

?/p>

Bitmap

转换,具体代码如下:

 

C++

部分?/p>

 

首先创建

win32

应用程序,选择类库模板

 

 

DLL_API

 

uchar

 * 

_stdcall

 run1(

char

* 

filename

, 

int

 & 

width

, 

int

 & 

height

, 

int

 & 

step

) 

{ 

 

 

IplImage

* uu = cvLoadImage(

filename

); 

 

IplImage

* dst1 = cvCreateImage(cvSize(uu->width, uu->height), 8, 1); 

 

cvCvtColor(uu, dst1, 

CV_RGB2GRAY

); 

 

Mat

 ss = cvarrToMat(uu); 

 

uchar

 * data = 

new 

uchar

[uu->width*uu->height * 3]; 

 

data = ss.data; 

 

width

 = ss.size

()

.width; 

 

height

 = ss.size

()

.height; 

 

step

 = ss.step; 

 

return

 data; 

} 

C#

中调用这?/p>

dll 

[

DllImport

(

@"E:\Files\BarcodeProject\Code\testCode\OpenCvAssemblies\Debug\OpenC

vAssemblies.dll"

)] 

        

public

 

static

 

extern

 

IntPtr

 

run1(

string

 

a, 

out

 

int

 

width, 

out

 

int

 

height, 

out

 

int

 step); 

至此完成

C++ Mat 

?/p>

Bitmap

的转?/p>

 

 

 

下面?/p>

Bitmap 

?/p>

 Mat 

的转?/p>

 

C# 

部分

 

public

 

static

 

BitmapInfo

 GetImagePixel(

Bitmap

 Source) 

        { 

            

byte

[] result; 

            

int

 step; 

            

int

 iWidth = Source.Width; 

            

int

 iHeight = Source.Height; 

            

Rectangle

 rect = 

new

 

Rectangle

(0, 0, iWidth, iHeight); 

            System.Drawing.Imaging.

BitmapData

 bmpData = Source.LockBits(rect, 

System.Drawing.Imaging.

ImageLockMode

.ReadWrite, Source.PixelFormat); 

            

IntPtr

 iPtr = bmpData.Scan0; 

            

int

 iBytes = iWidth * iHeight * 3;  

//

根据通道数进行设?/p>

  

 

Ͼλ">
Ͼλ
Ŀ

c#Bitmap与c++ Mat 相互转换 - 百度文库
新建
上传
首页
助手
最?/div>
资料?/div>
工具

C#Bitmap

?/p>

C++ opencv Mat

相互转换

 

C#

调用

C++ 

编译成的

dll

,这?/p>

dll

中包?/p>

Opencv

个的

Mat

?/p>

c#

?/p>

Bitmap

转换,具体代码如下:

 

C++

部分?/p>

 

首先创建

win32

应用程序,选择类库模板

 

 

DLL_API

 

uchar

 * 

_stdcall

 run1(

char

* 

filename

, 

int

 & 

width

, 

int

 & 

height

, 

int

 & 

step

) 

{ 

 

 

IplImage

* uu = cvLoadImage(

filename

); 

 

IplImage

* dst1 = cvCreateImage(cvSize(uu->width, uu->height), 8, 1); 

 

cvCvtColor(uu, dst1, 

CV_RGB2GRAY

); 

 

Mat

 ss = cvarrToMat(uu); 

 

uchar

 * data = 

new 

uchar

[uu->width*uu->height * 3]; 

 

data = ss.data; 

 

width

 = ss.size

()

.width; 

 

height

 = ss.size

()

.height; 

 

step

 = ss.step; 

 

return

 data; 

} 

C#

中调用这?/p>

dll 

[

DllImport

(

@"E:\Files\BarcodeProject\Code\testCode\OpenCvAssemblies\Debug\OpenC

vAssemblies.dll"

)] 

        

public

 

static

 

extern

 

IntPtr

 

run1(

string

 

a, 

out

 

int

 

width, 

out

 

int

 

height, 

out

 

int

 step); 

至此完成

C++ Mat 

?/p>

Bitmap

的转?/p>

 

 

 

下面?/p>

Bitmap 

?/p>

 Mat 

的转?/p>

 

C# 

部分

 

public

 

static

 

BitmapInfo

 GetImagePixel(

Bitmap

 Source) 

        { 

            

byte

[] result; 

            

int

 step; 

            

int

 iWidth = Source.Width; 

            

int

 iHeight = Source.Height; 

            

Rectangle

 rect = 

new

 

Rectangle

(0, 0, iWidth, iHeight); 

            System.Drawing.Imaging.

BitmapData

 bmpData = Source.LockBits(rect, 

System.Drawing.Imaging.

ImageLockMode

.ReadWrite, Source.PixelFormat); 

            

IntPtr

 iPtr = bmpData.Scan0; 

            

int

 iBytes = iWidth * iHeight * 3;  

//

根据通道数进行设?/p>

  

 



ļ׺.doc޸Ϊ.docĶ

  • IP硷ʵѧԶ̽ ׶ҵ
  • ڵƬˢֱ.Ҫ
  • γѡο
  • 2015-2020йֻҵսԱ - ͼ
  • йܻеҵг״ͶʷչǰԤⱨ2016-2021
  • ѯʦ԰һ⣩
  • ˼ϰ()--(1)
  • Ͽ19ѧ(1709180318091903)ִѧѧţ
  • ƶơ
  • ֱѧһд - п

վ

԰ Ͼλ
ϵͷ779662525#qq.com(#滻Ϊ@)