Hi everyone
I'm working on an image processing project these days.
everything seems to be working effectively but suddenly it stopped.
I don't know what the reason is because it was successfully working before.
The idea is that I want the user to open a text file where some information we need is,path chosen by the user also contains 18 jpg photos which program should read and store in a bitmap array previously defined
This is the code:
public partial class Form1 : Form
{
Bitmap[] Weapons_imgs = new Bitmap[18];
double[,] Learning_Vectors = new double[18, 2];
Rectangle[] Weapons_rects;
BlobCounter BC = new BlobCounter();
GrayscaleY Gray_filter = new GrayscaleY();
Invert negative_filter = new Invert();
Threshold thre_filter = new Threshold(10);
private void Get_Data_Click(object sender, EventArgs e)
{
OpenFileDialog OFD = new OpenFileDialog();
if (OFD.ShowDialog() == DialogResult.OK)
{
string str;
StreamReader reader = File.OpenText(OFD.FileName);
string dir = Path.GetDirectoryName(OFD.FileName);
for (int i = 0; (str = reader.ReadLine()) != null; i++)
{
string[] strs = str.Split(':');
Weapons_imgs[i] = new Bitmap(dir+"\\"+strs[0]+".jpg") ;
Bitmap img = Gray_filter.Apply(Weapons_imgs[i]);
negative_filter.ApplyInPlace(img);
thre_filter.ApplyInPlace(img);
BC.ProcessImage(img);
Weapons_rects = BC.GetObjectsRectangles();
double WH = (double)Weapons_rects[0].Width / (double)Weapons_rects[0].Height;
Learning_Vectors[i, 0] = WH;
Learning_Vectors[i, 1] = double.Parse(strs[1]);
Weapon_Features.Series[0].Points.AddXY(Learning_Vectors[i, 0], Learning_Vectors[i, 1]);
Weapon_combo.Items.Add(strs[0]);
}
}
}
when coding it doesn't generate errors but when executing it show me this message:
"
An unhandled exception of type 'System.ArgumentException' occurred in System.Drawing.dll
"
and it points on this line of code:
Weapons_imgs[i] = new Bitmap(dir+"\\"+strs[0]+".jpg") ;
what's the reason of all that?
I don't know what to do because I don't the reason for this
What I have tried:
I've tried to convert the photos to bitmap images and change the line of code to be like:
Weapons_imgs[i] = new Bitmap(dir+"\\"+strs[0]+".bmp");
and I rebuilt the whole project