Csharp调用基于Opencv编写的类库文件
下载地址:https://files.cnblogs.com/files/jsxyhelu/GOCW20171217.zip
现在将Csharp调用基于Opencv编写的类库文件(Dll)的方法定下来,我取名叫做GreenOpenCsharpWarper,简称GOCW。
{
pin_ptr <System : :Byte > p1 = &pCBuf1[ 0];
unsigned char * pby1 = p1;
cv : :Mat img_data1(pCBuf1 - >Length, 1,CV_8U,pby1);
cv : :Mat img_object = cv : :imdecode(img_data1,IMREAD_UNCHANGED);
//////////////////////////////////处理过程/////////
cvtColor(img_object,img_object, 40);
/////////////////////////////////////////////////////////////////////////////////
if ( !img_object.data)
return nullptr;
//获得目录,保存文件
cv : :imwrite( "c:/Method.jpg",img_object);
return "c:/Method.jpg";
}
String ^ Class1 : :Method2(cli : :array < unsigned char > ^ pCBuf1)
{
pin_ptr <System : :Byte > p1 = &pCBuf1[ 0];
unsigned char * pby1 = p1;
cv : :Mat img_data1(pCBuf1 - >Length, 1,CV_8U,pby1);
cv : :Mat img_object = cv : :imdecode(img_data1,IMREAD_UNCHANGED);
//////////////////////////////////处理过程///////////////////////
cvtColor(img_object,img_object, 6);
/////////////////////////////////////////////////////////////////////////////////
if ( !img_object.data)
return nullptr;
//获得目录,保存文件
cv : :imwrite( "c:/Method2.jpg",img_object);
return "c:/Method2.jpg";
}
{
Class1 client = new Class1();
string strResult1 = null;
string strResult2 = null;
//输入参数是string或bitmap
public Bitmap ImageProcess(string ImagePath){
Image ImageTemp = Bitmap.FromFile(ImagePath);
return ImageProcess(ImageTemp);
}
//输出结果是bitmap
public Bitmap ImageProcess(Image image)
{
MemoryStream ms = new MemoryStream();
image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] bytes = ms.GetBuffer();
strResult1 = client.Method(bytes);
Image ImageResult = Bitmap.FromFile(strResult1);
return (Bitmap)ImageResult;
}
public Bitmap ImageProcess2(string ImagePath)
{
Image ImageTemp = Bitmap.FromFile(ImagePath);
return ImageProcess2(ImageTemp);
}
//输出结果是bitmap
public Bitmap ImageProcess2(Image image)
{
MemoryStream ms = new MemoryStream();
image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] bytes = ms.GetBuffer();
strResult2 = client.Method2(bytes);
Image ImageResult = Bitmap.FromFile(strResult2);
return (Bitmap)ImageResult;
}
public void Clear()
{
if (File.Exists(strResult1))
File.Delete(strResult1);
if (File.Exists(strResult2))
File.Delete(strResult2);
}
}
{
if (pictureBox1.Image != null)
pictureBox1.Image.Dispose();
if (pictureBox2.Image != null)
pictureBox2.Image.Dispose();
Image image1 = gocsharphelper.ImageProcess( " E:/sandbox/logo.jpg");
pictureBox1.Image = image1;
Image image2 = gocsharphelper.ImageProcess2( "E:/sandbox/lena.jpg");
pictureBox2.Image = image2;
}
目前方向:图像拼接融合、图像识别 联系方式:jsxyhelu@foxmail.com