Click here to Skip to main content
15,893,381 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying develop a camera solution that will take snap shots of events and send them to a remote server using c#. I want to send an alert if the camera is not capturing, or disabled or mal-functioning.

I used Aforge to take the snap shots like this

#region AFORGE ORIGINAL

/// <summary>
/// This section starts the camera software by way of initialization
/// </summary>
private void StartCameras()
{
InitializeCameras();

//create first video source
VideoCaptureDevice videoSource1 = new VideoCaptureDevice(videoDevices[int.Parse(System.Configuration.ConfigurationManager.AppSettings["VideoSourceIndex"].ToString())].MonikerString);
videoSource1.DesiredFrameRate = 10;
videoSourcePlayer1.VideoSource = videoSource1;

videoSourcePlayer1.Start();

}

/// <summary>
/// this method is used to stop the camera
/// </summary>
private void StopCameras()
{
videoSourcePlayer1.SignalToStop();
//videoSourcePlayer1.WaitForStop();
}

/// <summary>
/// Camera initialisations
/// </summary>
private void InitializeCameras()
{
cameraNames = new ArrayList();

try
{
videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
if (videoDevices.Count == 0)
{
throw new Exception();
}

for (int i = 1, n = videoDevices.Count; i <= n; i++)
{
string cameraName = i + " : " + videoDevices[i - 1].Name;

cameraNames.Add(cameraName);

System.IO.File.AppendAllText(Application.StartupPath + "\\Cams.txt", DateTime.Now.ToString() + " " + cameraName + "\r\n");
}

//check cameras count
if (videoDevices.Count == 1)
{
cameraNames.Add("Only one camera found");

}
else
{

}


}
catch
{
cameraNames.Add("No camers found");
}
}

/// <summary>
/// Frame capture of images
/// </summary>
/// <param name="sender"></param>
/// <param name="image"></param>
private void videoSourcePlayer1_NewFrame(object sender, ref Bitmap image)
{
Bitmap _image = image;

Date = DateTime.Now.Day.ToString("D2") + DateTime.Now.Month.ToString("D2") + DateTime.Now.Year.ToString();
string ImageNameAndPath;
try
{
frameCount++;

if (frameCount > int.Parse(ConfigurationManager.AppSettings["FrameCount"].ToString()))
{
string strYear = "", strMonth = "", strDay = "";
strYear = DateTime.Now.Year.ToString().Substring(2);
strMonth = DateTime.Now.Month.ToString().PadLeft(2, '0');
strDay = DateTime.Now.Day.ToString().PadLeft(2, '0');

string buildPath = strYear + "\\" + strMonth + "\\" + strDay;

if (!Directory.Exists(ImagePath + "\\" + buildPath))
Directory.CreateDirectory(ImagePath + "\\" + buildPath);

ImageNameAndPath = ImagePath + "\\" + buildPath + "\\" + m_getIP + "_" + pan + "_DB PLC " + ConfigurationManager.AppSettings["ATMID"].ToString() + ".jpg";

StopCameras();

string[] splitPan = pan.Split('_');

if (splitPan.Length >= 4)
{
//Write text to the Image
using (Graphics g = Graphics.FromImage(_image))
{
string[] colours = ConfigurationManager.AppSettings["RGBWaterMarkColour"].ToString().Split(',');
SolidBrush solidBrush = new SolidBrush(Color.FromArgb(int.Parse(colours[0]), int.Parse(colours[1]), int.Parse(colours[2])));
FontFamily family = new FontFamily("Verdana");
Font font = new Font(Font.FontFamily, 10, FontStyle.Bold, GraphicsUnit.Pixel);
PointF location = new PointF(3, 3);
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
g.DrawString(splitPan[0] + " " + splitPan[1] + " DB PLC" + "\r\n" + splitPan[2] + " " + splitPan[3] + " " + ConfigurationManager.AppSettings["ATMName"].ToString(), font, solidBrush, location);
ImageNameAndPath = ImageNameAndPath.Replace(":", "");
//image.Save(ImageNameAndPath, ImageFormat.Jpeg);
image.Save(ImagePath + "\\" + buildPath + "\\" + ImageNameAndPath.Substring(ImageNameAndPath.LastIndexOf("\\") + 1), ImageFormat.Jpeg);
}
log += FileSystem.LogBuilder("CR2CAM", string.Format("{0} successfully snapped and saved.\r\n", ImageNameAndPath.Substring(ImageNameAndPath.LastIndexOf("\\") + 1)));
if (!string.IsNullOrEmpty(logPath))
FileSystem.Save(logPath, string.Format("cr2camLog{0}.log", Date), log);
}

frameCount = 0;
}
}
catch (Exception ex)
{
WriteToEventLog(ex.Message + "\r\n" + ex.StackTrace + "\r\n" + "Capture Event");
log += FileSystem.LogBuilder("CR2CAM", string.Format("Camera Error due to {0}.\r\n", ex.Message));
if (!string.IsNullOrEmpty(logPath))
FileSystem.Save(logPath, string.Format("cr2camLog{0}.log", Date), log);
connection.Close();
//Application.Restart();
}
}

#endregion
Posted
Updated 24-May-11 23:04pm
v2
Comments
Sandeep Mewara 25-May-11 4:59am    
'I am trying...'
Share your 'try' and effort made till now. Update question with it.

1 solution

Why not asking the author of AForge.NET?

See here http://www.aforgenet.com[^] or look at Andrews' profile (http://www.codeproject.com/Members/Andrew-Kirillov[^]), articles (http://www.codeproject.com/script/Articles/MemberArticles.aspx?amid=1181072[^]) and contact him at the page where an article is published.

—SA
 
Share this answer
 
Comments
Manfred Rudolf Bihy 25-May-11 9:35am    
Go to the source! You tell him. :) My 5+
Sergey Alexandrovich Kryukov 25-May-11 9:42am    
Thank you, Manfred. (Ts-s... Don't tell Andrew Kirillov I adviced to do so... :-)
--SA

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



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