Added a new edges function to detect only the edges in the video feed
This commit is contained in:
1 parent
fe81bcc6b2
commit
a2cd3cf09e
3 files changed
+126
-36
No files matched your search
@@ -0,0 +1,91 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using Emgu.CV;
|
||||
using Emgu.CV.Structure;
|
||||
|
||||
namespace handToMouse
|
||||
{
|
||||
class Filters
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void ColorSwap()
|
||||
{
|
||||
VideoCapture capture = new VideoCapture();
|
||||
Mat frame = new();
|
||||
bool pause = false;
|
||||
|
||||
while(!pause)
|
||||
{
|
||||
capture.Read(frame);
|
||||
|
||||
Image<Bgr, byte> convertFrame = frame.ToImage<Bgr, byte>();
|
||||
// Makes a greyscale image and the pixels that are in the range turn on and the rest are off.
|
||||
var image = convertFrame.InRange(new Bgr(75, 0, 0), new Bgr(255, 190, 190));
|
||||
|
||||
// With these loops the program will look accros the rows ans colums for pixes in the rang
|
||||
for (int i = 0; i < image.Rows; i++)
|
||||
{
|
||||
for (int j = 0; j < image.Cols; j++)
|
||||
{
|
||||
var intensity = image[i, j];
|
||||
|
||||
// Takes any pixels the loops find to be on and turns them blue
|
||||
if (intensity.Intensity > 0)
|
||||
{
|
||||
convertFrame[i, j] = new Bgr(convertFrame[i, j].MCvScalar.V0 + 100, convertFrame[i, j].MCvScalar.V1 + 50, convertFrame[i, j].MCvScalar.V2 - 50);
|
||||
}
|
||||
// Takes all the pixels the loops find off and tuns them green
|
||||
if (intensity.Intensity < 1)
|
||||
{
|
||||
convertFrame[i, j] = new Bgr(convertFrame[i, j].MCvScalar.V0 - 50, convertFrame[i, j].MCvScalar.V1 + 100, convertFrame[i, j].MCvScalar.V2 - 50);
|
||||
}
|
||||
}
|
||||
}
|
||||
Mat changedFrame = convertFrame.Mat;
|
||||
|
||||
CvInvoke.Imshow("Video", changedFrame);
|
||||
|
||||
int keyPressed = CvInvoke.WaitKey(1);
|
||||
if (keyPressed == 27)
|
||||
{
|
||||
pause = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void Edges()
|
||||
{
|
||||
VideoCapture capture = new VideoCapture();
|
||||
Mat feed = new Mat();
|
||||
Mat guassianBlur = new Mat();
|
||||
Mat cannyFeed = new Mat();
|
||||
bool play = false;
|
||||
|
||||
while (!play)
|
||||
{
|
||||
capture.Read(feed);
|
||||
|
||||
var averge = feed.ToImage<Gray, byte>().GetAverage();
|
||||
var lowerThreshold = Math.Max(0, (1.0 - 0.33) * averge.Intensity);
|
||||
var upperThreshold = Math.Max(255, (1.0 + 0.33) * averge.Intensity);
|
||||
|
||||
CvInvoke.GaussianBlur(feed, guassianBlur, new System.Drawing.Size(3, 3), 5.0);
|
||||
CvInvoke.Canny(guassianBlur, cannyFeed, lowerThreshold, upperThreshold, 3);
|
||||
|
||||
CvInvoke.Imshow("Video Feed", feed);
|
||||
CvInvoke.Imshow("Edges Feed", cannyFeed);
|
||||
|
||||
int keyPressed = CvInvoke.WaitKey(1);
|
||||
if (keyPressed == 27)
|
||||
{
|
||||
play = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user