jiongquesu3921 2017-11-09 06:30 采纳率: 0%
浏览 1774
已结题

opencv+海康摄像头解析二维码出现一些问题解析不了?

  private void DecCallbackFUN(int nPort, IntPtr pBuf, int nSize, ref PlayCtrl.FRAME_INFO pFrameInfo, int nReserved1, int nReserved2)
    {
        // 将pBuf解码后视频输入写入文件中(解码后YUV数据量极大,尤其是高清码流,不建议在回调函数中处理)
        if (pFrameInfo.nType == 3) //#define T_YV12 3
        {
            try
            {

                byte[] byteBuf = new byte[nSize];
                Marshal.Copy(pBuf, byteBuf, 0, nSize);
                GCHandle handle = GCHandle.Alloc(byteBuf, GCHandleType.Pinned);

                //强制I帧 Make a I frame
                //int lChannel = CaptureChannel; //通道号 Channel number
                //CHCNetSDK.NET_DVR_MakeKeyFrame(m_lUserID, lChannel);
             //   int width = 500;
               // int height = 400;
                Emgu.CV.Image<Bgr, Byte> image = new Emgu.CV.Image<Bgr, Byte>(pFrameInfo.nWidth, pFrameInfo.nHeight);
                using (Image<Bgr, Byte> yuv420p = new Image<Bgr, byte>(pFrameInfo.nWidth, (pFrameInfo.nHeight >> 1) * 3, pFrameInfo.nWidth, handle.AddrOfPinnedObject()))
                {

                    CvInvoke.CvtColor(yuv420p, image, Emgu.CV.CvEnum.ColorConversion.Yuv420P2Bgr);
                    mainwindow.PlayControl.RealPlayWnd.Image = image.ToBitmap();
                    Mat mat = new Mat();

                    BarcodeReader reader = new BarcodeReader();
                    reader.Options.CharacterSet = "UTF-8";
                    //byte[] bt = ms.GetBuffer();
                    LuminanceSource source = new RGBLuminanceSource(byteBuf, yuv420p.Width, yuv420p.Height);
                    BinaryBitmap bitmap = new BinaryBitmap(new ZXing.Common.HybridBinarizer(source));
                    Result result;
                    try
                    {
                        result = new MultiFormatReader().decode(bitmap);
                    }
                    catch (Exception)
                    {
                        return;
                    }
                    if (result != null)
                    {
                        mainwindow.abc.Text = result.Text;
                    }
                };
                if (handle.IsAllocated) handle.Free();

              //  CameraOperation co = new CameraOperation("rtsp://admin:xujuanaabb123@10.0.0.12:554/h264/ch1/main/av_stream");
              //  System.Drawing.Image img = co.CameraPictures();
               // System.IO.MemoryStream ms = new System.IO.MemoryStream();
               // img.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);// 格式自处理,这里用 bitmap

               // // 下行,初始一个 ImageSource 作为 myImage 的Source
               // System.Windows.Media.Imaging.BitmapImage bi = new System.Windows.Media.Imaging.BitmapImage();
               // //int  top=0;
               // // Bitmap imgs = (Bitmap)img.Clone();
               // bi.BeginInit();
               // bi.StreamSource = new MemoryStream(ms.ToArray()); // 不要直接使用 ms
               // bi.EndInit();
               //// mainwindow.PlayControl.RealPlayWnd. = bi; // done!
                //ms.Close();


                //Mat frame = new Mat();
                //frame = capture.QueryFrame();
                ////Image sources = null;
                //Emgu.CV.Image<Bgr, Byte> currentFrame = frame.ToImage<Bgr, Byte>(); //捕获每帧
                //System.Drawing.Image img = currentFrame.Bitmap;
                //System.IO.MemoryStream ms = new System.IO.MemoryStream();
                //img.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
                //System.Windows.Media.Imaging.BitmapImage bi = new System.Windows.Media.Imaging.BitmapImage();
                //bi.BeginInit();
                //bi.StreamSource = new MemoryStream(ms.ToArray()); // 不要直接使用 ms
                //bi.EndInit();
                //ms.Close();
                //byte[] bt = ms.GetBuffer();

            }
            catch (System.Exception ex)
            {
                // Log.WriteLog("", ex.ToString());
            }
            finally
            {
                GC.Collect();
            }
        }
    }
            求指教,哪里有错误?
            有人帮我看一下吗?
            加QQ1315189197
            有红包
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 训练的多模态特征融合模型准确度很低怎么办
    • ¥15 kylin启动报错log4j类冲突
    • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
    • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序
    • ¥15 onvif+openssl,vs2022编译openssl64
    • ¥15 iOS 自定义输入法-第三方输入法
    • ¥15 很想要一个很好的答案或提示
    • ¥15 扫描项目中发现AndroidOS.Agent、Android/SmsThief.LI!tr
    • ¥15 怀疑手机被监控,请问怎么解决和防止
    • ¥15 Qt下使用tcp获取数据的详细操作