Click here to Skip to main content
14,391,900 members
Rate this:
Please Sign up or sign in to vote.
I'm currently creating a windows software that will automatically capture using webcam when using login wrongly 3 times and save the captured photo in the folder. Before this, I have try this code in my VB.net project and it works fine but now I want to do it in C# but it gives me this error.

void loadimage()
       {
           try
           {

               if ((Directory.Exists("C:\\USBlocker") == false))
               {
                   Directory.CreateDirectory("C:\\USBlocker");
               }

             Emgu.CV.Image<Emgu.CV.Structure.Bgr, byte> imageviewer = this.imagecapture.QueryFrame ;  //THE ERROR IS HERE
                pictureBox1.Image = imageviewer.Bitmap;


               string fileName = "C:\\USBlocker\\A.jpg";
               int count = 0;
           Find:
               if (File.Exists(fileName))
               {
                   fileName = (("C:\\USBlocker\\A" + Convert.ToString("("))
                               + (count.ToString() + ").jpg"));
                   count++;
                   goto Find;
               }
               else
               {
                   // Add your logic here
                  imageviewer.Save(fileName);
               }

               imagecapture.Dispose();
               this.Hide();
           }
           catch (NullReferenceException ex)
           {
               MessageBox.Show(ex.Message);
           }
       }

       private void timer1_Tick(object sender, EventArgs e)
       {
           if (timeLeft > 0)
           {
               timeLeft = timeLeft - 1;
           }
           else
           {
               timer1.Stop();

               this.Close();
           }

       }

       private void Webcam_Load(object sender, EventArgs e)
       {
           if ((imagecapture == null))
           {
               try
               {
                   imagecapture = new Emgu.CV.VideoCapture();
               }
               catch (Exception ex)
               {
                   MessageBox.Show(ex.Message);
               }

           }



       }


What I have tried:

I try to add () after QueryFrame because I found that the error also can mean that it missing parenthesis but it gives me back the error Cannot implicitly convert type 'Emgu.CV.Mat' to 'Emgu.CV.Image<emgu.cv.structure.bgr, byte="">'
Posted
Updated 3-Dec-19 6:04am
Rate this:
Please Sign up or sign in to vote.

Solution 1

The call to imagecapture.QueryFrame does not return an object of type 'Emgu.CV.Image<emgu.cv.structure.bgr, byte="">'. You need to check the actual returned object to see how to convert it to the type you are trying to use.
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

Quote:
Cannot implicitly convert type 'Emgu.CV.Mat' to 'Emgu.CV.Image<Bgr, byte>'
Looks like you've declared your variable as the wrong type - you should be using the Mat class[^].
Emgu.CV.Mat imageviewer = this.imagecapture.QueryFrame();
pictureBox1.Image = imageviewer.Bitmap;
As far as I can see, all of the members you're trying to use exist on the Mat class.
   
Comments
dyooshi 3-Dec-19 19:53pm
   
Thank you so much for this. The error is gone but the photo still not being saved in the folder after the capture but at least the error is gone now. Thank you

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100