新浪博客

(OPENCV学习)C# 分配固定内存块给C++动态库

2017-11-27 09:22阅读:
C#
sourBitmap = new Bitmap(of.FileName);
Bitmap bm = new Bitmap(of.FileName);
pic_sour.Image = bm;

sourImageWidth = sourBitmap.Width;
sourImageHeight = sourBitmap.Height;
src_bmpData = sourBitmap.LockBits(new Rectangle(0, 0, sourBitmap.Width, sourBitmap.Height), ImageLockMode.ReadWrite, sourBitmap.PixelFormat);
//1代表是8bppindexed,如果不是后续处理要在opencv 这种转成灰度图,这种图形不用转 opencv.srcImage(src_bmpData.Scan0, src_bmpData.Stride, src_bmpData.Height, 1);
C++
#include 'stdafx.h'
#include
#include
#include
using namespace std;
using namespace cv;
unsigned char * pSrcImage;
int src_width;
int src_height;
int channel;
extern 'C' __declspec(dllexport) void srcImage(unsigned char * pImage,int width,int height, int ch)
{
pSrcImage = pImage;
src_width = width;
src_height = height;
channel = ch;
}
//C++中用到图片直接调用分配的这个内存块
//Mat srcImg(Size(src_width, src_height), CV_8UC(channel), pSrcImage);

我的更多文章

下载客户端阅读体验更佳

APP专享