-1

emgu CVカメラのキャプチャ画像をフォルダに保存して取り出す方法。null参照例外エラーを保存しようとするたびに。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Emgu.CV;
using Emgu.CV.UI;
using Emgu.CV.Util;
using Emgu.CV.Structure;

namespace camerapart2
{
    public partial class Form1 : Form
    {
        private Capture capture;
        private bool captureinprogress;
        public Form1()
        {
            InitializeComponent();
        }

        private void ProcessFrame(object sender, EventArgs arg)

        Image<Bgr, Byte> ImageFrame = capture.QueryFrame();
        cameraimage.Image = ImageFrame;
        pictureBox1.Image = ImageFrame.ToBitmap();
        ImageFrame.Save(@"E:\MyPic.jpg");

        private void btnStart_Click(object sender, EventArgs e)
        {
            if (capture == null)
            {
                try
                {
                    capture = new Capture();
                }
                catch (NullReferenceException excpt)
                {
                    MessageBox.Show(excpt.Message);
                }
            }

            if (capture != null)
            {
                if (captureinprogress)
                {  //if camera is getting frames then stop the capture and set button Text
                    // "Start" for resuming capture
                    btnstart.Text = "Start!"; //
                    Application.Idle -= ProcessFrame;
                }
                else
                {
                    //if camera is NOT getting frames then start the capture and set button
                    // Text to "Stop" for pausing capture
                    btnstart.Text = "Stop";
                    Application.Idle += ProcessFrame;
                }

                captureinprogress = !captureinprogress;
            }
        }

        private void ReleaseData()
        {
            if (capture != null)
                capture.Dispose();
        }
    }
}

これらの 2 行で、nullrefference エラーが発生しています。

pictureBox1.Image = ImageFrame.ToBitmap();
ImageFrame.Save(@"E:\MyPic.jpg");
4

2 に答える 2