public int OpenRealData() { uint lResult; pWaitFlag = Marshal.AllocHGlobal(sizeof(uint));//声明一个同样大小的空间 Marshal.WriteInt32(pWaitFlag, 1); int iWaitFlag = Marshal.ReadInt32(pWaitFlag); mycall = new NETSDK.SIRIUS_pfnMessageCallBack(this.MessageCallBack); lResult = NETSDK.SIRIUS_SetMessageCallBack(mycall, pWaitFlag); if (0 != lResult) { Console.WriteLine("注册回调函数失败!错误编码:{0:d}", lResult); return(-1); } Console.WriteLine("注册回调函数成功!"); // 添加摄像机 int iCameraIndex = 0; // 先删除一次 lResult = NETSDK.SIRIUS_DeleteCamera(UserID, iCameraIndex); NETSDK.DEV_LOGIN_INFO stDevLoginInfo; stDevLoginInfo.eType = NETSDK.COLLECTOR_TYPE_USB_CAMERA; stDevLoginInfo.szIPAddr = ""; stDevLoginInfo.iPort = 0; stDevLoginInfo.szUserName = ""; stDevLoginInfo.szPassWord = ""; stDevLoginInfo.iStreamIndex = 0; stDevLoginInfo.szDevName = "USB摄像机"; lResult = NETSDK.SIRIUS_AddCamera(UserID, iCameraIndex, ref stDevLoginInfo); if (0 != lResult) { Console.WriteLine("添加摄像机失败!错误编码:{0:d}", lResult); return(-1); } Console.WriteLine("添加摄像机成功!"); //// 注册码流回调函数 //realDataCall = new NETSDK.SIRIUS_pfnRealDataCallBack(this.RealDataCallBack); //lResult = NETSDK.SIRIUS_SetRealDataCallBack(realDataCall, IntPtr.Zero); //if (0 != lResult) //{ // Console.WriteLine("注册码流回调函数失败!错误编码:{0:d}", lResult); // return -1; //} //Console.WriteLine("注册码流回调函数成功!\n"); //// 启动码流预览 //lResult = NETSDK.SIRIUS_StartRealPlay(UserID, 0); //if (0 != lResult) //{ // Console.WriteLine("启动码流预览失败!错误编码:{0:d}", lResult); // return -1; //} //Console.WriteLine("启动码流预览成功!\n"); return(0); }
public int SearchByPic(string picPath) { uint lResult; pWaitFlag = Marshal.AllocHGlobal(sizeof(uint));//声明一个同样大小的空间 Marshal.WriteInt32(pWaitFlag, 1); int iWaitFlag = Marshal.ReadInt32(pWaitFlag); mycall = new NETSDK.SIRIUS_pfnMessageCallBack(this.MessageCallBack); lResult = NETSDK.SIRIUS_SetMessageCallBack(mycall, pWaitFlag); if (0 != lResult) { Console.WriteLine("注册回调函数失败!错误编码:{0:d}", lResult); return(-1); } Console.WriteLine("注册回调函数成功!"); // 登录服务器 NETSDK.USER_LOGIN_INFO stLoginInfo; stLoginInfo.szIPAddr = "127.0.0.1"; stLoginInfo.iPort = 8612; stLoginInfo.szUserName = "******"; stLoginInfo.szPassWord = "******"; lResult = NETSDK.SIRIUS_Login(ref stLoginInfo, ref UserID); if (0 != lResult) { Console.WriteLine("登录服务器[{0:s}:{1:d}]失败!错误编码:{2:d}" , stLoginInfo.szIPAddr , stLoginInfo.iPort , lResult ); return(-1); } Console.WriteLine("登录服务器[{0:s}:{1:d}]成功!", stLoginInfo.szIPAddr, stLoginInfo.iPort); // 条件对象 NETSDK.SEARCH_COND stSearchCond; stSearchCond.Index = 0; stSearchCond.PageNum = 10; stSearchCond.szStartTime = ""; stSearchCond.szStopTime = ""; stSearchCond.iCameraIndex = 0; stSearchCond.szName = ""; stSearchCond.iMinSim = 0; stSearchCond.iMaxSim = 0; lResult = NETSDK.SIRIUS_SearchModelFaceByPic(UserID, picPath, ref stSearchCond); if (0 != lResult) { Console.WriteLine("以图搜图失败!错误编码:{0:d}", lResult); lResult = NETSDK.SIRIUS_Logout(UserID); Thread.Sleep(1 * 1000); // Notes:等待注销消息 return(-1); } else { Console.WriteLine("以图搜图成功!"); } int iDuration = 3000; while (iDuration-- > 0) { iWaitFlag = Marshal.ReadInt32(pWaitFlag); if (iWaitFlag == 0) { Console.WriteLine("收到反馈消息,等待结束"); break; } else { if (iDuration % 10 == 0) { Console.WriteLine("等待消息..."); } Thread.Sleep(1 * 100); } } // 注销服务器 lResult = NETSDK.SIRIUS_Logout(UserID); if (0 != lResult) { Console.WriteLine("注销服务器失败!错误编码:{2:d}", lResult); return(-2); } Console.WriteLine("注销服务器成功!"); Thread.Sleep(1 * 1000); // Notes:等待注销消息 UserID = 0; return(0); }