Capturing an image with Emgu - black image

∥☆過路亽.° 提交于 2019-12-11 06:56:49

问题


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;                 
        }
    }
}

回答1:


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




回答2:


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;



回答3:


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.



来源:https://stackoverflow.com/questions/5093018/capturing-an-image-with-emgu-black-image

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!