开发者

Capturing an image with Emgu - black image

I'm a newbie in emgu cv and for a major project I'm trying to capture an image from a webcam and show it in an image box, but it's showing a black image.

What is wrong with the following code?

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.Structure;
using Emgu.CV.UI;
using Emgu.Util;

namespace WindowsFormsApplication7
{
    public partial class Form1 : Form
    {
        private Capture capture;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            if (capture == null)
               capture = new Capture();
            Image<Bgr,Byte> img=capture.QueryFrame(开发者_运维知识库);
            imageBox1.Image = img;                 
        }
    }
}


I think there is a minor mistake.

Use this instead:

Declare as global variable:

Capture capture = default(Capture);

Put this in load:

capture = new Capture(0);
Control.CheckForIllegalCrossThreadCalls = false;
System.Threading.Thread t = new System.Threading.Thread(grab);

t.Start();

Create a sub grab and put in,

do {
    ImageBox1.Image = capture.QueryFrame();
} while (true);

Cheers
Shreyas


Call QueryFrame() twice, it works for me:

 if (capture == null)
           capture = new Capture();
 capture.QueryFrame();
 Image<Bgr,Byte> img=capture.QueryFrame().ToImage<Bgr, Byte>();
 imageBox1.Image = img.Bitmap;


In my case Kaspersky AntiVirus was blocking the access to my webcam. After changing some security settings I was able to get emgu capture back working.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜