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全部拷貝過去,否則會報看不懂的錯誤。

 




免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM