使用OpenCVDotNet对象捕获图像 [英] Use OpenCVDotNet object to Capture image

查看:71
本文介绍了使用OpenCVDotNet对象捕获图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

//我想从USB摄像头捕获图像,但是我的应用程序显示错误:

// I want to capture image from USB camera but my application show error:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using OpenCVDotNet;

namespace WindowsApplication6
{
    public partial class Form1 : Form
    {
        private CVCapture capture;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            capture = new CVCapture(0);
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
                using (CVImage nextFrame = capture.QueryFrame())
                {
                    selectPictureBox1.Image = nextFrame.ToBitmap(); // THIS LINE ERROR
	            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            timer1.Enabled = !(timer1.Enabled);
        }
    }
}


错误显示:"对象引用未设置为对象的实例"

请帮助我解决此错误.谢谢!


Error show : "Object reference not set to an instance of an object"

Please help me fix this error. Thanks !

推荐答案

selectPictureBox1nextFrame或两者都没有在标记行执行时被初始化.

也许QueryFrame()失败并将nextFrame设置为null?
Either selectPictureBox1 or nextFrame, or both, is/are not initialized at the moment the marked line is executed.

Maybe QueryFrame() failed and left nextFrame set to null?


,该错误消息非常笼统..
使用之前,请检查所有对象的null条件.
例如,它将使您知道哪个对象为null.

the error message is very generic..
check null condition for all your objects before use.
like, it will give you an idea that which object is null.

if(nextFrame != null)
{
   if(selectPictureBox1 != null)
   { 
      selectPictureBox1.Image = nextFrame.ToBitmap(); 
   }
}



如果selectPictureBox1对象为null,则进行检查.如果nextFrame对象为null,请检查有关此问题的解决方案,这意味着您的使用(CVImage nextFrame = capture.QueryFrame())"无效.
->检查相机连接,如果可能,请在与您的应用一起使用之前先单击照片以进行验证.
->检查CVCapture API中的帮助



if selectPictureBox1 object is null, check for that. if nextFrame object is null check for the solution regarding that, means your ''using (CVImage nextFrame = capture.QueryFrame())'' is not working.
-> check camera connection, if possible click photos before using with your app for varification.
-> check for help in CVCapture API


这篇关于使用OpenCVDotNet对象捕获图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆