Added a new edges function to detect only the edges in the video feed

This commit is contained in:
Carter Essen committed 2026-08-06 17:35:46 -04:00
1 parent fe81bcc6b2
commit a2cd3cf09e
3 files changed
+126 -36

No files matched your search

+20
View File
@@ -3,10 +3,30 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17 # Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59 VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Vision", "Vision.csproj", "{D4EF9473-A95B-4307-BC84-E31B3D57F60C}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU 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 EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
+15 -36
View File
@@ -8,46 +8,25 @@ namespace handToMouse
{ {
static void Main(string[] args) static void Main(string[] args)
{ {
VideoCapture capture = new VideoCapture(); string input;
Mat frame = new();
bool pause = false;
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<Bgr, byte> convertFrame = frame.ToImage<Bgr, byte>(); default:
// 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 break;
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;
}
} }
} }
} }
+91
View File
@@ -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;
}
}
}
}
}