I am working on project project that do some process on live video of camera using ICImagingControl in c# .net Framework 4.5,
i am recieving video and
i want to do some image processing like Line detection. i have the function which is used for capturing and displaying images in a video stream.
here is the source code that i have.
<pre> void icVideo_ImageAvailable(object sender, ICImagingControl.ImageAvailableEventArgs e)
{
try
{
Currentbuffer = e.ImageBuffer;
icVideo.DisplayImageBuffer(Currentbuffer);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
What I have tried:
here is some code that i have tried but it throws runtime
error.
and not getting what i intended to get(line detection on the image).
<pre>void icVideo_ImageAvailable(object sender, ICImagingControl.ImageAvailableEventArgs e)
{
try
{
Currentbuffer = e.ImageBuffer;
Mat image = new Mat(Currentbuffer.BitsPerPixel, Currentbuffer.BitsPerPixel, (int)DepthType.Cv8U, Currentbuffer.BytesPerLine);
Mat grayImage = new Mat();
CvInvoke.CvtColor(image, grayImage, ColorConversion.Bgr2Gray);
double cannyThreshold = 180.0;
double cannyThresholdLinking = cannyThreshold * 0.4;
Mat cannyEdges = new Mat();
CvInvoke.Canny(grayImage, cannyEdges, cannyThreshold, cannyThresholdLinking);
double rho = 1.0;
double theta = Math.PI / 180.0;
int threshold = 100;
double minLineLength = 100.0;
double maxLineGap = 10.0;
LineSegment2D[] lines = CvInvoke.HoughLinesP(cannyEdges, rho, theta, threshold, minLineLength, maxLineGap);
foreach (LineSegment2D line in lines)
{
CvInvoke.Line(image, line.P1, line.P2, new MCvScalar(0, 0, 255), 2);
}
icVideo.DisplayImageBuffer(Currentbuffer);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}