So my question is how can I do this in my application.
I share my code for video processing:
- Code: Select all
void FinalVideoSource_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
Grayscale filter = new Grayscale(0.2125, 0.7154, 0.0721);
Bitmap image = (Bitmap)eventArgs.Frame.Clone();
Bitmap copyimage = (Bitmap)eventArgs.Frame.Clone();
image = filter.Apply(image);
BitmapData imageData = image.LockBits(
new Rectangle(0, 0, image.Width, image.Height),
ImageLockMode.ReadWrite, image.PixelFormat);
UnmanagedImage grayImage = new UnmanagedImage(imageData);
DifferenceEdgeDetector edgeDetector = new DifferenceEdgeDetector();
UnmanagedImage edgesImage = edgeDetector.Apply(grayImage);
Threshold thresholdFilter = new Threshold(40);
thresholdFilter.ApplyInPlace(edgesImage);
BlobCounter blobCounter = new BlobCounter();
blobCounter.MinHeight = 48;
blobCounter.MinWidth = 48;
blobCounter.FilterBlobs = true;
blobCounter.ObjectsOrder = ObjectsOrder.Size;
blobCounter.ProcessImage(edgesImage);
Blob[] blobs = blobCounter.GetObjectsInformation();
for (int i = 0, n = blobs.Length; i < n; i++)
{
List<IntPoint> edgePoints = blobCounter.GetBlobsEdgePoints(blobs[i]);
List<IntPoint> corners = new List<IntPoint>();
corners.Add(new IntPoint(99, 99));
corners.Add(new IntPoint(156, 79));
corners.Add(new IntPoint(184, 126));
corners.Add(new IntPoint(122, 150));
if (shapeChecker.IsQuadrilateral(edgePoints, out corners))
{
List<IntPoint> leftEdgePoints, rightEdgePoints;
blobCounter.GetBlobsLeftAndRightEdges(blobs[i],
out leftEdgePoints, out rightEdgePoints);
float diff = CalculateAverageEdgesBrightnessDifference(
leftEdgePoints, rightEdgePoints, grayImage);
if (diff > 20)
{
Quadrilateral = corners;
Bitmap sourceImage = new Bitmap(@"C:\Users\XaKeRA\Desktop\icon.png");
BackwardQuadrilateralTransformation backfilter =
new BackwardQuadrilateralTransformation(sourceImage, Quadrilateral);
QuadrilateralTransformation quadrilateralTransformation =
new QuadrilateralTransformation(Quadrilateral, 100, 100);
glyphImage = quadrilateralTransformation.Apply(grayImage);
newImage = backfilter.Apply(copyimage);
OtsuThreshold otsuThresholdFilter = new OtsuThreshold();
otsuThresholdFilter.ApplyInPlace(glyphImage);
byte[,] glyphValues = Recognize(glyphImage,
new Rectangle(0, 0, glyphImage.Width, glyphImage.Height), out confidence);
if (confidence >= minConfidenceLevel)
{
resMatching = CheckForMatching(Glyph_01, glyphValues);
if (resMatching != -1)
{
rotation = CheckForMatching(Glyph_01, glyphValues);
glif = "Glyph_01";
}
resMatching = CheckForMatching(Glyph_02, glyphValues);
if (resMatching != -1)
{
rotation = CheckForMatching(Glyph_02, glyphValues);
glif = "Glyph_02";
}
resMatching = CheckForMatching(Glyph_03, glyphValues);
if (resMatching != -1)
{
rotation = CheckForMatching(Glyph_03, glyphValues);
glif = "Glyph_03";
}
resMatching = CheckForMatching(Glyph_04, glyphValues);
if (resMatching != -1)
{
rotation = CheckForMatching(Glyph_04, glyphValues);
glif = "Glyph_04";
}
ImgRes.Image = glyphImage.ToManagedImage();
updateLabelText(glif);
}
}
}
}
pictureBox1.Image = grayImage.ToManagedImage();
}