diff --git a/Emgu.CV-Learning-Projects.sln b/Emgu.CV-Learning-Projects.sln index 58ea566..b4f163a 100644 --- a/Emgu.CV-Learning-Projects.sln +++ b/Emgu.CV-Learning-Projects.sln @@ -3,10 +3,30 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.0.31903.59 MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Vision", "Vision.csproj", "{D4EF9473-A95B-4307-BC84-E31B3D57F60C}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {D4EF9473-A95B-4307-BC84-E31B3D57F60C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D4EF9473-A95B-4307-BC84-E31B3D57F60C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D4EF9473-A95B-4307-BC84-E31B3D57F60C}.Debug|x64.ActiveCfg = Debug|Any CPU + {D4EF9473-A95B-4307-BC84-E31B3D57F60C}.Debug|x64.Build.0 = Debug|Any CPU + {D4EF9473-A95B-4307-BC84-E31B3D57F60C}.Debug|x86.ActiveCfg = Debug|Any CPU + {D4EF9473-A95B-4307-BC84-E31B3D57F60C}.Debug|x86.Build.0 = Debug|Any CPU + {D4EF9473-A95B-4307-BC84-E31B3D57F60C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D4EF9473-A95B-4307-BC84-E31B3D57F60C}.Release|Any CPU.Build.0 = Release|Any CPU + {D4EF9473-A95B-4307-BC84-E31B3D57F60C}.Release|x64.ActiveCfg = Release|Any CPU + {D4EF9473-A95B-4307-BC84-E31B3D57F60C}.Release|x64.Build.0 = Release|Any CPU + {D4EF9473-A95B-4307-BC84-E31B3D57F60C}.Release|x86.ActiveCfg = Release|Any CPU + {D4EF9473-A95B-4307-BC84-E31B3D57F60C}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/program.cs b/src/program.cs index ec11298..74177c7 100644 --- a/src/program.cs +++ b/src/program.cs @@ -8,46 +8,25 @@ namespace handToMouse { static void Main(string[] args) { - VideoCapture capture = new VideoCapture(); - Mat frame = new(); - bool pause = false; + string input; - while(!pause) + Console.WriteLine("What filter do you want to apply?"); + input = Console.ReadLine(); + + switch (input) { - capture.Read(frame); + case "color swap": + Filters colorSwap = new Filters(); + colorSwap.ColorSwap(); + break; + case "edges": + Filters edges = new Filters(); + edges.Edges(); + break; - Image convertFrame = frame.ToImage(); - // 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)); + default: - // 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; - } + break; } } } diff --git a/src/videoFilters.cs b/src/videoFilters.cs new file mode 100644 index 0000000..90615a9 --- /dev/null +++ b/src/videoFilters.cs @@ -0,0 +1,91 @@ +using System; +using System.Drawing; +using Emgu.CV; +using Emgu.CV.Structure; + +namespace handToMouse +{ + class Filters + { + /// + /// + /// + public void ColorSwap() + { + VideoCapture capture = new VideoCapture(); + Mat frame = new(); + bool pause = false; + + while(!pause) + { + capture.Read(frame); + + Image convertFrame = frame.ToImage(); + // 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; + } + } + } + + /// + /// + /// + 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().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; + } + } + } + } +} \ No newline at end of file