Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I have a Windows 7 Intel i7 laptop (Toshiba Qosmio). I downloaded OpenCV for
Windows and OpenCVSharp for Windows. I tried to run the simple example - with
no success.

Compiles fine - I get the following error when executed in debug mode:

using (CvCapture cap = CvCapture.FromCamera(0))
TypeInitializationException was unhandled
The type initializer for 'OpenCvSharp.CvInvoke' thres and exception.




I tried lots of things - no luck. I tried copying OpenCV .dll's into
the Debug directory - cannot find the right DLL's - they all lead
with "opencv_core230.dll". I do not think OpenCvSharp wants them named
this way.

I would appreciate help.

Thanks,
Art

C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using System.Runtime.InteropServices;
using OpenCvSharp;

using System.Threading;
using System.Reflection;
using System.Runtime.CompilerServices;
//using System.Diagnostics;

namespace OpenCvSharp_Proj_1
{
    public partial class OpenCvSharp_Proj_1 : Form
    {
        public OpenCvSharp_Proj_1()
        {
            InitializeComponent();

            using (CvCapture cap = CvCapture.FromCamera(0))
            using (CvWindow w = new CvWindow("OpenCV Example"))
            {
                while (CvWindow.WaitKey(10) < 0)
                {
                    using (IplImage src = cap.QueryFrame())
                    using (IplImage gray = new IplImage(src.Size, BitDepth.U8, 1))
                    using (IplImage dstCanny = new IplImage(src.Size, BitDepth.U8, 1))
                    {
                        src.CvtColor(gray, ColorConversion.BgrToGray);
                        Cv.Canny(gray, dstCanny, 50, 50, ApertureSize.Size3);
                        w.Image = dstCanny;
                    }
                }
            }
        }
    }
}
Posted

1 solution

SQL
Try to add References:
   - OpenCVSharp
   - OpenCVSharp.Blob
   - OpenCVSharp.Extensions
   - OpenCVSharp.MachineLearning
   - OpenCVSharp.UserInterface
 
Share this answer
 
Comments
fjdiewornncalwe 27-Jan-12 14:36pm    
1) Please don't answer old questions like this. It is not likely that after 3 months the OP will be back to check on it.
2) Your answer is simply wrong. His references are ok because his error is in the execution of the application, not the building of the projects.
Member 11580525 18-Apr-15 10:50am    
On the other hand, I am googling for the solution of the same problem. Answering old questions is still good, because not only the questioner have the problem.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900