<em>Mac</em>Book项目 2009年学校开始实施<em>Mac</em>Book项目,所有师生配备一本<em>Mac</em>Book,并同步更新了校园无线网络。学校每周进行电脑技术更新,每月发送技术支持资料,极大改变了教学及学习方式。因此2011
2021-06-01 09:32:01
/// <summary> /// 海康威視SDK /// </summary> public class SDK_Hikvision : SDK_Camera { /// <summary> /// 相機名稱 /// </summary> private string Cam_name; /// <summary> /// 相機範例 /// </summary> private MyCamera m_MyCamera; /// <summary> /// 影象回撥 相機名稱圖源 /// </summary> public override event ImageDelegate Image_Delegate; IntPtr pBufForSaveImage = IntPtr.Zero; //註冊影象回撥函數 MyCamera.cbOutputExdelegate ImageCallback; /// <summary> /// 是否已連線相機 /// </summary> public override bool IsOpen { get { if (m_MyCamera!=null) { return m_MyCamera.MV_CC_IsDeviceConnected_NET(); } return false; } } /// <summary> /// /// </summary> ~SDK_Hikvision() { } /// <summary> /// 實時採集 /// </summary> public override void Acquisition() { if (m_MyCamera == null) return; if (GetTriggerMode()==TriggerMode.On) { SetTriggerMode(TriggerMode.Off); } m_MyCamera.MV_CC_StartGrabbing_NET(); } /// <summary> /// 關閉採集 /// </summary> public override void CloseConsecutive() { if (m_MyCamera == null) return; m_MyCamera.MV_CC_StopGrabbing_NET(); } /// <summary> /// 關閉相機 /// </summary> public override void Close_Camera() { if (m_MyCamera == null) return; m_MyCamera.MV_CC_StopGrabbing_NET(); if (pBufForSaveImage != IntPtr.Zero) { Marshal.Release(pBufForSaveImage); } /* m_MyCamera.MV_CC_StopGrabbing_NET(); m_MyCamera.MV_CC_ClearImageBuffer_NET(); m_MyCamera.MV_CC_CloseDevice_NET(); //銷燬裝置控制程式碼 m_MyCamera.MV_CC_DestroyDevice_NET();*/ m_MyCamera.MV_CC_CloseDevice_NET(); m_MyCamera.MV_CC_DestroyDevice_NET(); } /// <summary> /// 獲取曝光 /// </summary> /// <returns></returns> public override double GetExposureTime() { if (m_MyCamera!=null) { MyCamera.MVCC_FLOATVALUE stParam = new MyCamera.MVCC_FLOATVALUE(); m_MyCamera.MV_CC_GetFloatValue_NET("ExposureTime", ref stParam); return stParam.fCurValue; } return 0; } /// <summary> /// 獲取增益 /// </summary> /// <returns></returns> public override double GetGainRaw() { if (m_MyCamera != null) { MyCamera.MVCC_FLOATVALUE stParam = new MyCamera.MVCC_FLOATVALUE(); m_MyCamera.MV_CC_GetFloatValue_NET("Gain", ref stParam); return stParam.fCurValue; } return 0; } /// <summary> /// 獲取觸發模式 /// </summary> /// <returns></returns> public override TriggerMode GetTriggerMode() { if (m_MyCamera != null) { MyCamera.MVCC_ENUMVALUE MVCC_SOURCE = new MyCamera.MVCC_ENUMVALUE(); m_MyCamera.MV_CC_GetEnumValue_NET("TriggerMode", ref MVCC_SOURCE); MyCamera.MV_CAM_TRIGGER_MODE Value = (MyCamera.MV_CAM_TRIGGER_MODE)MVCC_SOURCE.nCurValue; return (TriggerMode)MVCC_SOURCE.nCurValue; } return TriggerMode.On; } /// <summary> /// 獲取觸發源 /// </summary> /// <returns></returns> public override TriggerSource GetTriggerSource() { if (m_MyCamera != null) { MyCamera.MVCC_ENUMVALUE MVCC_SOURCE = new MyCamera.MVCC_ENUMVALUE(); m_MyCamera.MV_CC_GetEnumValue_NET("TriggerSource", ref MVCC_SOURCE); MyCamera.MV_CAM_TRIGGER_SOURCE Value = (MyCamera.MV_CAM_TRIGGER_SOURCE)MVCC_SOURCE.nCurValue; return (TriggerSource)MVCC_SOURCE.nCurValue; } return TriggerSource.Software; } /// <summary> /// 開啟相機 /// </summary> /// <param name="Cam_Name">相機名稱</param> /// <returns></returns> public override bool Open_Camera(string Cam_Name) { System.GC.Collect(); MyCamera.MV_CC_DEVICE_INFO_LIST m_stDeviceList = new MyCamera.MV_CC_DEVICE_INFO_LIST(); int nRet = MyCamera.MV_CC_EnumDevices_NET(MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE, ref m_stDeviceList); if (0 != nRet) { return false; } for (int i = 0; i < m_stDeviceList.nDeviceNum; i++) { MyCamera.MV_CC_DEVICE_INFO device = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(m_stDeviceList.pDeviceInfo[i], typeof(MyCamera.MV_CC_DEVICE_INFO)); if (device.nTLayerType == MyCamera.MV_GIGE_DEVICE) { IntPtr buffer = Marshal.UnsafeAddrOfPinnedArrayElement(device.SpecialInfo.stGigEInfo, 0); //MyCamera.MV_GIGE_DEVICE_INFO gigeInfo = (MyCamera.MV_GIGE_DEVICE_INFO)MyCamera.ByteToStruct(device.SpecialInfo.stGigEInfo, typeof(MyCamera.MV_GIGE_DEVICE_INFO)); MyCamera.MV_GIGE_DEVICE_INFO gigeInfo = (MyCamera.MV_GIGE_DEVICE_INFO)Marshal.PtrToStructure(buffer, typeof(MyCamera.MV_GIGE_DEVICE_INFO)); this.Cam_name = gigeInfo.chUserDefinedName; } else if (device.nTLayerType == MyCamera.MV_USB_DEVICE) { IntPtr buffer = Marshal.UnsafeAddrOfPinnedArrayElement(device.SpecialInfo.stUsb3VInfo, 0); MyCamera.MV_USB3_DEVICE_INFO usbInfo = (MyCamera.MV_USB3_DEVICE_INFO)Marshal.PtrToStructure(buffer, typeof(MyCamera.MV_USB3_DEVICE_INFO)); //MyCamera.MV_USB3_DEVICE_INFO usbInfo = (MyCamera.MV_USB3_DEVICE_INFO)MyCamera.ByteToStruct(device.SpecialInfo.stUsb3VInfo, typeof(MyCamera.MV_USB3_DEVICE_INFO)); this.Cam_name = usbInfo.chUserDefinedName; } if (Cam_Name == this.Cam_name) { //開啟裝置 if (null == m_MyCamera) { m_MyCamera = new MyCamera(); } //建立裝置 nRet = m_MyCamera.MV_CC_CreateDevice_NET(ref device); if (MyCamera.MV_OK != nRet) { return false; } //開啟裝置 nRet = m_MyCamera.MV_CC_OpenDevice_NET(); if (MyCamera.MV_OK != nRet) { //開啟裝置失敗 銷燬裝置控制程式碼 m_MyCamera.MV_CC_DestroyDevice_NET(); return false; } // 探測網路最佳包大小(只對GigE相機有效) if (device.nTLayerType == MyCamera.MV_GIGE_DEVICE) { int nPacketSize = m_MyCamera.MV_CC_GetOptimalPacketSize_NET(); if (nPacketSize > 0) { m_MyCamera.MV_CC_SetIntValue_NET("GevSCPSPacketSize", (uint)nPacketSize); } } //設定相機模式 //連續採集 m_MyCamera.MV_CC_SetEnumValue_NET("AcquisitionMode", (uint)MyCamera.MV_CAM_ACQUISITION_MODE.MV_ACQ_MODE_CONTINUOUS); //觸發模式 m_MyCamera.MV_CC_SetEnumValue_NET("TriggerMode", (uint)MyCamera.MV_CAM_TRIGGER_MODE.MV_TRIGGER_MODE_ON); //設定影象快取節點個數 m_MyCamera.MV_CC_SetImageNodeNum_NET(8); //註冊影象回撥函數 ImageCallback = new MyCamera.cbOutputExdelegate(GrabImage); //來設定資料回撥函數。 nRet =m_MyCamera.MV_CC_RegisterImageCallBackEx_NET(ImageCallback, IntPtr.Zero); if (MyCamera.MV_OK != nRet) { return false; } //開啟採集 m_MyCamera.MV_CC_StartGrabbing_NET(); return true; } } return false; } /// <summary> /// 影象註冊事件 /// </summary> /// <param name="pData"></param> /// <param name="pFrameInfo"></param> /// <param name="pUser"></param> private void GrabImage(IntPtr pData, ref MyCamera.MV_FRAME_OUT_INFO_EX pFrameInfo, IntPtr pUser) { byte[] SrcData = new byte[pFrameInfo.nHeight * pFrameInfo.nWidth];//影象資料 // Marshal.Copy(pData, SrcData, 0, (int)pFrameInfo.nFrameLen); HObject Hobj; HOperatorSet.GenEmptyObj(out Hobj); byte[] imageData = IntPtr2Bytes(pData, (int)(pFrameInfo.nFrameLen)); uint imageLen = pFrameInfo.nFrameLen; uint imageWidth = pFrameInfo.nWidth; uint imageHight = pFrameInfo.nHeight; if (IsMonoPixelFormat(pFrameInfo.enPixelType))//黑白 { Hobj.Dispose(); HOperatorSet.GenImage1(out Hobj, "byte", pFrameInfo.nWidth, pFrameInfo.nHeight, pData); } else { if (pFrameInfo.enPixelType == MyCamera.MvGvspPixelType.PixelType_Gvsp_RGB8_Packed)//RGB { Hobj.Dispose(); HOperatorSet.GenImageInterleaved(out Hobj, pData, "rgb", (int)pFrameInfo.nWidth, (int)pFrameInfo.nHeight, 0, "byte", (int)pFrameInfo.nWidth, (int)pFrameInfo.nHeight, 0, 0, -1, 0); } else { if (pBufForSaveImage == IntPtr.Zero) { pBufForSaveImage = Marshal.AllocHGlobal((int)(pFrameInfo.nWidth * pFrameInfo.nHeight * 3 + 2048)); } MyCamera.MV_PIXEL_CONVERT_PARAM stConverPixelParam = new MyCamera.MV_PIXEL_CONVERT_PARAM(); stConverPixelParam.nWidth = pFrameInfo.nWidth; stConverPixelParam.nHeight = pFrameInfo.nHeight; stConverPixelParam.pSrcData = pData; stConverPixelParam.nSrcDataLen = pFrameInfo.nFrameLen; stConverPixelParam.enSrcPixelType = pFrameInfo.enPixelType; stConverPixelParam.enDstPixelType = MyCamera.MvGvspPixelType.PixelType_Gvsp_RGB8_Packed;//在此處選擇需要轉換的目標型別 stConverPixelParam.pDstBuffer = pBufForSaveImage; stConverPixelParam.nDstBufferSize = (uint)(pFrameInfo.nWidth * pFrameInfo.nHeight * 3 + 2048); m_MyCamera.MV_CC_ConvertPixelType_NET(ref stConverPixelParam); Hobj.Dispose(); HOperatorSet.GenImageInterleaved(out Hobj, pBufForSaveImage, "rgb", (int)pFrameInfo.nWidth, (int)pFrameInfo.nHeight, 0, "byte", (int)pFrameInfo.nWidth, (int)pFrameInfo.nHeight, 0, 0, -1, 0); } } if (Hobj.CountObj() > 0) { Image_Delegate?.Invoke(Cam_name, Hobj?.Clone()); } Hobj?.Dispose(); System.GC.Collect(); } public static byte[] IntPtr2Bytes(IntPtr ptr, int size) { if (ptr == IntPtr.Zero) { return null; } byte[] bytes = new byte[size]; Marshal.Copy(ptr, bytes, 0, size); return bytes; } /// <summary> /// 黑白影象 /// </summary> /// <param name="enType"></param> /// <returns></returns> private bool IsMonoPixelFormat(MyCamera.MvGvspPixelType enType) { switch (enType) { case MyCamera.MvGvspPixelType.PixelType_Gvsp_Mono8: case MyCamera.MvGvspPixelType.PixelType_Gvsp_Mono10: case MyCamera.MvGvspPixelType.PixelType_Gvsp_Mono10_Packed: case MyCamera.MvGvspPixelType.PixelType_Gvsp_Mono12: case MyCamera.MvGvspPixelType.PixelType_Gvsp_Mono12_Packed: return true; default: return false; } } /// <summary> /// 彩色影象 /// </summary> /// <param name="enType"></param> /// <returns></returns> private bool IsColorPixelFormat(MyCamera.MvGvspPixelType enType) { switch (enType) { case MyCamera.MvGvspPixelType.PixelType_Gvsp_RGB8_Packed: case MyCamera.MvGvspPixelType.PixelType_Gvsp_BGR8_Packed: case MyCamera.MvGvspPixelType.PixelType_Gvsp_RGBA8_Packed: case MyCamera.MvGvspPixelType.PixelType_Gvsp_BGRA8_Packed: case MyCamera.MvGvspPixelType.PixelType_Gvsp_YUV422_Packed: case MyCamera.MvGvspPixelType.PixelType_Gvsp_YUV422_YUYV_Packed: case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerGR8: case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerRG8: case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerGB8: case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerBG8: case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerGB10: case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerGB10_Packed: case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerBG10: case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerBG10_Packed: case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerRG10: case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerRG10_Packed: case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerGR10: case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerGR10_Packed: case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerGB12: case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerGB12_Packed: case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerBG12: case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerBG12_Packed: case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerRG12: case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerRG12_Packed: case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerGR12: case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerGR12_Packed: return true; default: return false; } } /// <summary> /// 設定曝光 /// </summary> /// <param name="Value"></param> /// <returns></returns> public override double SetExposureTime(double Value) { m_MyCamera.MV_CC_SetEnumValue_NET("ExposureAuto", 0); MyCamera.MVCC_FLOATVALUE stParam = new MyCamera.MVCC_FLOATVALUE(); m_MyCamera.MV_CC_GetFloatValue_NET("ExposureTime", ref stParam); if (Value <= stParam.fMax && Value >= stParam.fMin) { m_MyCamera.MV_CC_SetFloatValue_NET("ExposureTime", (float)Value); } return stParam.fCurValue; } /// <summary> /// 設定增益 /// </summary> /// <param name="Value"></param> /// <returns></returns> public override double SetGainRaw(double Value) { m_MyCamera.MV_CC_SetEnumValue_NET("GainAuto", 0); MyCamera.MVCC_FLOATVALUE stParam = new MyCamera.MVCC_FLOATVALUE(); m_MyCamera.MV_CC_GetFloatValue_NET("Gain", ref stParam); if (Value <= stParam.fMax && Value >= stParam.fMin) { m_MyCamera.MV_CC_SetFloatValue_NET("Gain", (float)Value); } return stParam.fCurValue; } /// <summary> /// 獲取觸發模式 /// </summary> /// <param name="mode"></param> public override void SetTriggerMode(TriggerMode mode) { if (mode == TriggerMode.Off) { m_MyCamera.MV_CC_SetEnumValue_NET("TriggerMode", (uint)MyCamera.MV_CAM_TRIGGER_MODE.MV_TRIGGER_MODE_OFF); } else { m_MyCamera.MV_CC_SetEnumValue_NET("TriggerMode", (uint)MyCamera.MV_CAM_TRIGGER_MODE.MV_TRIGGER_MODE_ON); } } /// <summary> /// 設定觸發源 /// </summary> /// <param name="source"></param> public override void SetTriggerSource(TriggerSource source) { m_MyCamera.MV_CC_SetEnumValue_NET("TriggerMode", (uint)MyCamera.MV_CAM_TRIGGER_MODE.MV_TRIGGER_MODE_ON); switch (source) { case TriggerSource.Line1: m_MyCamera.MV_CC_SetEnumValue_NET("TriggerSource", (uint)MyCamera.MV_CAM_TRIGGER_SOURCE.MV_TRIGGER_SOURCE_LINE0); break; case TriggerSource.Line2: m_MyCamera.MV_CC_SetEnumValue_NET("TriggerSource", (uint)MyCamera.MV_CAM_TRIGGER_SOURCE.MV_TRIGGER_SOURCE_LINE1); break; case TriggerSource.Software: m_MyCamera.MV_CC_SetEnumValue_NET("TriggerSource", (uint)MyCamera.MV_CAM_TRIGGER_SOURCE.MV_TRIGGER_SOURCE_SOFTWARE); break; default: break; } } /// <summary> /// 軟觸發一次 /// </summary> public override bool TriggerSoftware() { if (m_MyCamera == null) return false; if (GetTriggerMode()==TriggerMode.Off) { m_MyCamera.MV_CC_SetEnumValue_NET("TriggerMode", (uint)MyCamera.MV_CAM_TRIGGER_MODE.MV_TRIGGER_MODE_ON); m_MyCamera.MV_CC_SetEnumValue_NET("TriggerSource", (uint)MyCamera.MV_CAM_TRIGGER_SOURCE.MV_TRIGGER_SOURCE_SOFTWARE); } m_MyCamera.MV_CC_SetCommandValue_NET("TriggerSoftware"); return true; } }
c#海康威視:System.DllNotFoundException:“無法載入 DLL“…binHCNetSDK.dll”: 找不到指定的模組。 (異常來自 HRESULT:0x8007007E)。”
將海康威視的SDK直接複製到我的專案中時,使用到SDK中的方法就出現這個異常。
將demo裡的dll放在bin資料夾和binDebug資料夾裡時也會出錯。
這個肯定是路徑出錯了,不然不會報這個找不到指定模組的異常。
在程式碼中選中方法函數,右鍵轉到定義:
將binHCNetSDK.dll改成DebugHCNetSDK,這樣就不會報錯了。
以上為個人經驗,希望能給大家一個參考,也希望大家多多支援it145.com。
相關文章
<em>Mac</em>Book项目 2009年学校开始实施<em>Mac</em>Book项目,所有师生配备一本<em>Mac</em>Book,并同步更新了校园无线网络。学校每周进行电脑技术更新,每月发送技术支持资料,极大改变了教学及学习方式。因此2011
2021-06-01 09:32:01
综合看Anker超能充系列的性价比很高,并且与不仅和iPhone12/苹果<em>Mac</em>Book很配,而且适合多设备充电需求的日常使用或差旅场景,不管是安卓还是Switch同样也能用得上它,希望这次分享能给准备购入充电器的小伙伴们有所
2021-06-01 09:31:42
除了L4WUDU与吴亦凡已经多次共事,成为了明面上的厂牌成员,吴亦凡还曾带领20XXCLUB全队参加2020年的一场音乐节,这也是20XXCLUB首次全员合照,王嗣尧Turbo、陈彦希Regi、<em>Mac</em> Ova Seas、林渝植等人全部出场。然而让
2021-06-01 09:31:34
目前应用IPFS的机构:1 谷歌<em>浏览器</em>支持IPFS分布式协议 2 万维网 (历史档案博物馆)数据库 3 火狐<em>浏览器</em>支持 IPFS分布式协议 4 EOS 等数字货币数据存储 5 美国国会图书馆,历史资料永久保存在 IPFS 6 加
2021-06-01 09:31:24
开拓者的车机是兼容苹果和<em>安卓</em>,虽然我不怎么用,但确实兼顾了我家人的很多需求:副驾的门板还配有解锁开关,有的时候老婆开车,下车的时候偶尔会忘记解锁,我在副驾驶可以自己开门:第二排设计很好,不仅配置了一个很大的
2021-06-01 09:30:48
不仅是<em>安卓</em>手机,苹果手机的降价力度也是前所未有了,iPhone12也“跳水价”了,发布价是6799元,如今已经跌至5308元,降价幅度超过1400元,最新定价确认了。iPhone12是苹果首款5G手机,同时也是全球首款5nm芯片的智能机,它
2021-06-01 09:30:45