asp.net调用opencv类库,实现图像处理显示

asp.net调用opencv类库,实现图像处理显示
 
   ​      原理上来说,通过dll的调用,无论是asp.net还是winform都可以调用opencv及其类库。但是在实现的过程还是有许多细节是经过摸索和总结才得到结果的。作为界面显示的方法,asp.net的网页界面和winform的传统界面应该说是各有所长,应当灵活运用。这里是我如何采用asp.net调用opencv类库,实现图像处理显示的小结。
        一、主要过程
        我这里阐述的是最方便、最容易操作的过程,但不一定是最科学的过程
        1)将以GOIMAGE.DLL为主体的,和其支持库,全部拷贝到system32文件夹下
       
       
          在代码中显示引用库文件
        const string dllpath = "GOImage.dll";
    [DllImport(dllpath,
    EntryPoint = "getgray",
    CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    public static extern int getgray(string ImagePath, string ImagePath_Res, ref int errcode);
 
 
    [DllImport(dllpath,
    EntryPoint = "getgreen",
    CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    public static extern int getgreen(string ImagePath, string ImagePath_Res, ref int errcode);
     2)编写具体的引用代码
         //网页调用opencv类库,实现图像处理
// jsxyhelu 2015年3月31日
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Runtime.InteropServices;
public partial class _Default : System.Web.UI.Page
{
 
    [DllImport("GOImage.dll",
    EntryPoint = "getgreen",
    CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    public static extern int getgreen(string ImagePath, string ImagePath_Res, ref int errcode);
    //结果是成功的。
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        //返回值
        int iret = 0;
        int ierror = 0;
        string strresult = "错误";
        //图片输出位置
        string strOutput = Server.MapPath(@"~/imgs/result.jpg");
        //获得输入图片地址
        string strInput = TextBox1.Text.ToString();
        //进行处理
        iret = getgreen(strInput, strOutput, ref ierror);
        //输出结果
        Image1.ImageUrl = strOutput;
        if (0==iret)
        {
            strresult = "正常";
        }
        else if (1==iret)
        {
            strresult = "干旱";
        }
        else
        {
            strresult = "虫蛀";
        }
        tbresult.Text = "当前的图像类型为" + strresult;
    }
}
 
        二、注意事项
       在调用的时候,一定要把所有的相关的dll全部拷贝过去,否则会报看不懂的错误。

 



posted on   jsxyhelu  阅读(185)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

点击右上角即可分享
微信分享提示