I am using EmguCV with C#, I am facing a problem when I want to grab frames from my web cam, red underline appears on statement:
imgOrg = capturecam.QueryFrame();
error: Cannot implicitly convert type 'Emgu.CV.Mat' to 'Emgu.CV.Image
how can I solve this problem?
my code:
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.CV.CvEnum;
using Emgu.CV.Structure;
using Emgu.CV.UI;
namespace test2
{
public partial class Form1 : Form
{
Image<Bgr, Byte> imgOrg; //image type RGB (or Bgr as we say in Open CV)
private Capture capturecam;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
try
{
capturecam = new Capture();
}
catch (NullReferenceException exception)
{
MessageBox.Show(exception.Message);
return;
}
Application.Idle += new EventHandler(ProcessFunction);
}
private void ProcessFunction(object sender, EventArgs arg)
{
imgOrg = capturecam.QueryFrame(); // error line
imageBox1.Image = imgOrg;
}
}
}
该语句有效:
Image<Bgr, Byte> img = mat.ToImage<Bgr, Byte>();
imgOrg = new Image(capturecam.QueryFrame().Bitmap);
This Code Worked For me. I hope working for you too.
Try this:
imgOrg = capturecam.QueryFrame().ToImage<Bgr, Byte>();
Look here: how to convert mat to image in (Emgu CV version 3) in c#?
Or change your Image variable to Mat:
Mat imgOrg = new Mat(); // instead of: Image<Bgr, Byte> imgOrg;
imgOrg = capture.QueryFrame();
imageBox1.Image = imgOrg;
图片FRAME2 = frame.ToImage();
This is pretty straight forward. This works in Emgu CV 3.3++.
vidCap = new VideoCapture([filename or webcam device]);
Mat mat = new Mat();
vidCap.Read(mat); //This calls Grab() as grabbing a frame and then Retrieve();
imageBox1.Image = mat.Bitmap;
Reference the example, the QueryFrame() not be used anymore at EmguCV 3.0. it be replaced by Retrieve() function.
Sample as shown below:
Mat frame = new Mat();
cap.Retrieve(frame, 0);
Mat grayFrame = new Mat();
CvInvoke.CvtColor(frame, grayFrame, ColorConversion.Bgr2Gray);
imageBox1.Image = frame;
imageBox2.Image = grayFrame;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.