OpenCV中文网站

 找回密码
 立即注册
搜索
热搜: 安装 配置
查看: 3423|回复: 3

emgucv视频处理报错

[复制链接]
发表于 2019-9-4 22:32:30 | 显示全部楼层 |阅读模式
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Emgu.CV;
using Emgu.CV.CvEnum;
using Emgu.CV.Structure;
using Emgu.Util;
namespace WindowsFormsApplication31
{
    public partial class Form1 : Form
    {
        private VideoCapture _capture = null;
        private bool _captureInProgress;
        private Mat _frame;
        private Mat _grayFrame;
        private Mat _smallGrayFrame;
        private Mat _smoothedGrayFrame;
        private Mat _cannyFrame;
        public Form1()
        {
            InitializeComponent();
            CvInvoke.UseOpenCL = false;
            try
            {
                _capture = new VideoCapture();//实例化一个摄像头


                _capture.ImageGrabbed += ProcessFrame;
            }
            catch (NullReferenceException excpt)
            {
                MessageBox.Show(excpt.Message);
            }
            _frame = new Mat();
            _grayFrame = new Mat();
            _smallGrayFrame = new Mat();
            _smoothedGrayFrame = new Mat();
            _cannyFrame = new Mat();
        }
        private void ProcessFrame(object sender, EventArgs arg)
        {
            if (_capture != null && _capture.Ptr != IntPtr.Zero)
            {
                _capture.Retrieve(_frame, 0);
                CvInvoke.CvtColor(_frame, _grayFrame, ColorConversion.Bgr2Gray);
                CvInvoke.PyrDown(_grayFrame, _smallGrayFrame);
                CvInvoke.PyrUp(_smallGrayFrame, _smoothedGrayFrame);
                CvInvoke.Canny(_smoothedGrayFrame, _cannyFrame, 100, 60);
                captureImageBox.Image = _frame;
                grayscaleImageBox.Image = _grayFrame;
                smoothedGrayscaleImageBox.Image = _smoothedGrayFrame;
                cannyImageBox.Image = _cannyFrame;
            }
        }
        private void captureButtonClick(object sender, EventArgs e)
        {
            if (_capture != null)
            {
                if (_captureInProgress)
                {  //stop the capture
                    captureButton.Text = "Start Capture";
                    _capture.Pause();
                }
                else
                {
                    //start the capture
                    captureButton.Text = "Stop";
                    _capture.Start();

                }
                _captureInProgress = !_captureInProgress;
            }
        }
        private void ReleaseData()
        {
            if (_capture != null)
                _capture.Dispose();
        }
        private void FlipHorizontalButtonClick(object sender, EventArgs e)
        {
            if (_capture != null) _capture.FlipHorizontal = !_capture.FlipHorizontal;
        }
        private void FlipVerticalButtonClick(object sender, EventArgs e)
        {
            if (_capture != null) _capture.FlipVertical = !_capture.FlipVertical;
        }
    }
}
运行报错:
严重性        代码        说明        项目        文件        行        禁止显示状态
错误        CS0012        类型“ExceptionHandler”在未引用的程序集中定义。必须添加对程序集“System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089”的引用。

试了网上很多办法都不行,求高手指导


回复

使用道具 举报

 楼主| 发表于 2019-9-4 22:34:11 | 显示全部楼层
  _capture.Start(); 主要是这句引起的 如何解决~
回复 支持 反对

使用道具 举报

 楼主| 发表于 2019-9-13 16:26:08 | 显示全部楼层
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using Emgu.CV;
using Emgu.Util;
using Emgu.CV.CvEnum;
using Emgu.CV.Structure;
using Emgu.Util.TypeEnum;

namespace WindowsFormsApplication38
{
    public partial class Form1 : Form
    {
       // Capture是Emgu.CV提供的摄像头控制类,里面的ImageGrabbed事件表示的是获取到图片后触发。可以用来实现模拟摄像头视频获取(其实是在picturebox中显示图片,由于很快,就跟视频一样)
      // Capture另一个非常关键的方法是QueryFrame()这个方法是用来获取当前的摄像头捕捉到的图面。
        Capture _capture;
        public Form1()
        {
            InitializeComponent();
            _capture = new Capture(@"C:\Users\Administrator\Desktop\video\vtest.avi");
            _capture.SetCaptureProperty(Emgu.CV.CvEnum.CapProp.FrameHeight, 300);
            //设置捕捉到帧的高度为320。
            _capture.SetCaptureProperty(Emgu.CV.CvEnum.CapProp.FrameWidth,
            300);
            //设置捕捉到帧的宽度为240。
            _capture.FlipHorizontal = true;
            //捕捉到帧数据进行水平翻转。
            _capture.ImageGrabbed += _capture_ImageGrabbed;
           
            _capture.Start();
        }

        void _capture_ImageGrabbed(object sender, EventArgs e)
        {
             Mat frame = new Mat();
         
                _capture.Retrieve(frame, 0);

                //var frame1 = _capture.Retrieve(frame,0);
                pic.Image = frame.Bitmap;
               
            


        }
    }
}
回复 支持 反对

使用道具 举报

 楼主| 发表于 2019-9-13 16:29:07 | 显示全部楼层
“System.AccessViolationException”类型的未经处理的异常在 System.Drawing.dll 中发生

其他信息: 尝试读取或写入受保护的内存。这通常指示其他内存已损坏

回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|OpenCV中文网站

GMT+8, 2024-3-29 23:05 , Processed in 0.009901 second(s), 15 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表