• 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全部拷贝过去,否则会报看不懂的错误。



  • 相关阅读:
    JavaScript高级程序设计学习笔记--变量、作用域和内存问题
    JavaScript高级程序设计学习笔记--基本概念
    Silverlight 动画性能
    Silverlight动画之 Animation Easing
    Silverlight 动画详解
    WCF重写ServiceHost,实现独立配置文件
    WP8 双击返回键退出
    Asp.Net之自定义表达式构造器(ExpressionBuilder)
    通过configSource提高web.config配置灵活性
    C# 操作IIS方法集合
  • 原文地址:https://www.cnblogs.com/jsxyhelu/p/7421497.html
Copyright © 2020-2023  润新知