请高手们帮我找一下错误,在线等, 急!!!!!
下面是我调用API的一个类, 其中最后一个函数中调所声明的API时出错, 请高手帮忙找一下原因,急! using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace CarCardRecognise
{
public class Recognise
{
private const string dllName = "lpclr.dll";
/// <summary>
/// 牌照识别的结果通过 VEHREC 结构返回。VEHREC 结构包含了有关车辆牌照的相关信息,包括牌照号码、牌照颜色、牌照区域、牌照图像等
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public struct Vehrec
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)]
public byte[] vehid;
public int time;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 8)]
public byte[] color_plate;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
public byte[] site;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)]
public byte[] lane;
public int speed;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 8)]
public byte[] model;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 8)]
public byte[] color;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 4)]
public int[] rect_plate;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)]
public byte[] im_info;
public int img_cx;
public int img_cy;
public char img_type;
public long img_size;
public char flag;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)]
public byte[] status;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)]
public byte[] reserved;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = MAX_IMGCODE_SIZE)]
public byte[] img;
}
//常量定义
private const int MAX_IMGCODE_SIZE = 32768; //1024*32
/// <summary>
/// 初始化牌照识别
/// </summary>
/// <param name="nWidth"> </param>
/// <param name="nHeight"> </param>
/// <param name="Mode"> </param>
/// <returns> </returns>
[DllImportAttribute(dllName)]
internal static extern int Init(int nWidth, int nHeight, byte Mode);
/// <summary>
/// 牌照识别
/// </summary>
/// <param name="pImgs"> </param>
/// <param name="lpRec"> </param>
/// <param name="pLUT"> </param>
/// <param name="flag"> </param>
/// <param name="imgrect"> </param>
/// <returns> </returns>
[DllImportAttribute(dllName, CharSet = CharSet.Auto)]
internal static extern int RecognizeLP(System.IntPtr pImgs, ref Vehrec lpRec, long pLUT, long flag, long imgrect);
/// <summary>
/// 参数设置
/// </summary>
[DllImportAttribute(dllName)]
internal static extern void LoadSetting(int index, string cityWord);
/// <summary>
/// 车辆检测
/// </summary>
/// <returns> </returns>
[DllImportAttribute(dllName)]
internal static extern int DetectMoving(byte[] images, byte[] lastImages, Vehrec rec, bool flag);
/// <summary>
/// 识别并显示结果
/// </summary>
public void GetAndDispReuult()
{
System.Windows.Forms.OpenFileDialog objDlg = new OpenFileDialog();
objDlg.Filter = "JPG files(*.jpg) ?*.jpg ?BMP files(*.bmp) ?*.bmp";
objDlg.ReadOnlyChecked = false;
objDlg.Multiselect = false;
objDlg.Title = "选择文件";
if (objDlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
string path = objDlg.FileName;
stream = new (path, );
byte[] bytes = new byte[stream.Length];
stream.Read(bytes, 0, (int)stream.Length);
stream.Dispose();
stream.Close();
ms = new (bytes);
System.Drawing.Image photo = System.Drawing.Image.FromStream(ms);
picImage.Image = photo;
int i = Recognise.Init(photo.Width, photo.Height, 2);
Recognise.LoadSetting(2, "豫");
System.IntPtr pdata = System.Runtime.InteropServices.Marshal.UnsafeAddrOfPinnedArrayElement(bytes, 0);
Vehrec lpRec = new Vehrec();
int ii = Recognise.RecognizeLP(pdata, ref lpRec, 0, 1, 0);
}
}
}
}
是在调用
int ii = Recognise.RecognizeLP(pdata, ref lpRec, 0, 1, 0);
时出错的!
错误内容大制如下:
KERNEL32.dll
EAX=03BFF2C8 CS=001B EIP=7C812A5B EFLAGS=000000202
.....
....
.....
等都是些类似堆栈地址的东西。