i have the code that works fine for the x64 bit OS while x32bit OS generates exception : "The type initializer for 'Emgu.CV.CvInvoke' threw an exception."
i have followed almost solutions from the internet still didn't get rid of the problem.
i have tried to put unmanaged dlls to the execution file directory.
i have build in target framework x86.
i have also tried the dlls to put into c:\windows\system32.
almost every solutions.
also tested demo projects still getting same problems.
it has run perfect on the x64bit OS but gives runtime exception "The type initializer for 'Emgu.CV.CvInvoke' threw an exception.<"
What I have tried:
i am using emgucv library to do some image processing. i have earlier used emgu cv library but never encountered this error. almost tried every solutions from the internet solutions and sources.
here is my sample code from the demo project.
private void Application_Idle(object sender, EventArgs e)
{
String FileName = @"E:\Demo\EmguCv-Histogram-01-master\S\ResizedImages\dblbig.jpg";
Image<Bgr, Byte> InputImage;
InputImage = new Image<Bgr, byte>(FileName);
mainImage = InputImage;
if (mainImage == null) return;
processedImage = mainImage.InRange(new Bgr(120, 0, 0), new Bgr(256, 70, 70));
processedImage = processedImage.SmoothGaussian(9);
CircleF[] circles = processedImage.HoughCircles(new Gray(100), new Gray(50), 2, processedImage.Height / 4, 10, 400).SelectMany(u => u.Select(s => s)).ToArray();
foreach (var c in circles)
{
if (txtLog.Text != "") txtLog.AppendText(Environment.NewLine);
CvInvoke.Circle(mainImage, new Point((int)c.Center.X, (int)c.Center.Y), 3, new MCvScalar(0, 255, 0), -1, Emgu.CV.CvEnum.LineType.AntiAlias, 0);
mainImage.Draw(c, new Bgr(Color.Red), 3);
}
imageBox1.Image = mainImage;
imageBox2.Image = processedImage;
}
Update 1
Update : i don't know why but when i deleted Emgu.CV library from nuget pkg and added dlls from the reference
1.Emgu.CV
2.Emgu.Util
3.Emgu.CV.UI
i was working.
but now the problem is i was using nuget pkg Emgu.CV library of version 3.3.0.2824 it was using Emgu.cv.World.dll and now i am using these three dlls from reference and it uses Emgu.CV.dll so the functions have been changed.
i was using :
var rect = CvInvoke.MinAreaRect(points);
now its giving me error because it not in reference dll
so now which function i can use instead of the :
var rect = CvInvoke.MinAreaRect(points);
i am updating my question and posting the code where i want to change the function.
here is my some of my source code:
private LineSegment2D[] objectLines = new LineSegment2D[0];
int lineCount = 0;
foreach (var line in objectLines)
{
var points = new PointF[] { line.P1, line.P2 };
var rect = CvInvoke.MinAreaRect(points);
angle = rect.Angle;
var center = rect.Center;
startPoint = new Point(Convert.ToInt32(center.X - 100 * Math.Cos(angle * Math.PI / 180.0)),
Convert.ToInt32(center.Y - 100 * Math.Sin(angle * Math.PI / 180.0)));
endPoint = new Point(Convert.ToInt32(center.X + 100 * Math.Cos(angle * Math.PI / 180.0)),
Convert.ToInt32(center.Y + 100 * Math.Sin(angle * Math.PI / 180.0)));
if (lineCount == 0 && isTopLineClicked && upbuttobClick)
{
Display_diamond_checkbox.Checked = false;
Thread.Sleep(1000);
this.ob.DrawLine(Color.Black, startPoint.X, startPoint.Y, endPoint.X, endPoint.Y);
double distanceToTopLine = CalculateDistance(startPoint.X, startPoint.Y, x21, y21, x22, y22);
double distanceToBottomLine = CalculateDistance(startPoint.X, startPoint.Y, x19, y19, x20, y20);
double distanceThreshold = 3;
if (distanceToTopLine <= distanceThreshold || distanceToBottomLine <= distanceThreshold)
{
MessageBox.Show("Line matches!", "Detect Line", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("Does not match!", "Detect Line", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
upbuttobClick = false;
}