简体   繁体   中英

how to read image from a picturebox in EMGU CV

I'm trying to read an image from a picturebox to perform feature matching using EMGU. Below is the code I'm using which I got from the sample project.

        Bitmap img = new Bitmap(pictureBox1.Image);
        Image<Bgr, byte> imgInput = new Image<Bgr, byte>(img);

        using (Mat modelImage = CvInvoke.Imread("C:\\model.jpg", ImreadModes.Color)) //works
        using (Mat observedImage = CvInvoke.Imread(imgInput, ImreadModes.Color)) //doesn't work
        {
            Mat result = DrawMatches.Draw(modelImage, observedImage, out matchTime);
            ImageViewer.Show(result, String.Format("Matched in {0} milliseconds", matchTime));

        }

When I give a path to CvInvoke.ImRead, it works, but if I create a bitmap and use that bitmap as the image, it gives an error saying CvInvoke.ImRead has some invalid arguments.

How do I read the image from picturebox?

CvInvoke.Imread method can be used only for reading from a file. first parameter must be a file name as string. so you can modify your code as follows:

    Bitmap img = new Bitmap(pictureBox1.Image);
    Image<Bgr, byte> imgInput = new Image<Bgr, byte>(img);

    using (Mat modelImage = CvInvoke.Imread("C:\\model.jpg", ImreadModes.Color)) //works
    using (Mat observedImage = new Image<Bgr, byte>(img).Mat) //works too
    {
        Mat result = DrawMatches.Draw(modelImage, observedImage, out matchTime);
        ImageViewer.Show(result, String.Format("Matched in {0} milliseconds", matchTime));

    }

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM