diff --git a/Display-Image.cs b/Display-Image.cs index f9daf82..8d957b6 100644 --- a/Display-Image.cs +++ b/Display-Image.cs @@ -1,9 +1,14 @@ using System; +using System.Numerics; using Emgu.CV; using Emgu.CV.Structure; +using Emgu.CV.Util; namespace ImageMinipulation { + /// + /// All programs are made using videos from (Programming with Chris) video seiress + /// public class vanGoghFilters { /// @@ -101,7 +106,7 @@ namespace ImageMinipulation { } /// - /// + /// Adds a sharpen filter to a picture based on an array /// public void Five() { @@ -130,5 +135,123 @@ namespace ImageMinipulation { CvInvoke.WaitKey(); } + + /// + /// Uses the sobel edge detection to output just the edges in the image + /// + public void Six() + { + Mat pic = CvInvoke.Imread("./img/iPhone.jpg"); + + Mat guassianBlur = new Mat(); + Mat sobelX = new Mat(); + Mat sobelY = new Mat(); + Mat sobelXY = new Mat(); + + pic.CopyTo(sobelX); + pic.CopyTo(sobelY); + pic.CopyTo(sobelXY); + + CvInvoke.GaussianBlur(pic, guassianBlur, new System.Drawing.Size(3, 3), 5.0); + + CvInvoke.Sobel(guassianBlur, sobelX, Emgu.CV.CvEnum.DepthType.Default, 1, 0, 5); + CvInvoke.Sobel(guassianBlur, sobelY, Emgu.CV.CvEnum.DepthType.Default, 0, 1, 5); + CvInvoke.Sobel(guassianBlur, sobelXY, Emgu.CV.CvEnum.DepthType.Default, 1, 1, 5); + + CvInvoke.Imshow("sobelX", sobelX); + CvInvoke.Imshow("sobelY", sobelY); + CvInvoke.Imshow("sobelXY", sobelXY); + + CvInvoke.WaitKey(); + } + + /// + /// Uses the canny edge detection to output the edges in an image (this method can be a little sharper depending on the image) + /// + public void Seven() + { + Mat pic = CvInvoke.Imread("./img/iPhone.jpg"); + + Mat guassianBlur = new Mat(); + Mat cannyPic = new Mat(); + + var averge = pic.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(pic, guassianBlur, new System.Drawing.Size(3, 3), 5.0); + CvInvoke.Canny(guassianBlur, cannyPic, lowerthreshold, upperthreshold, 3); + + CvInvoke.Imshow("Canny", cannyPic); + + CvInvoke.WaitKey(); + } + + /// + /// Makes a threshold image to tell us where the contours are then defines those contours with green lines and fills the contourd parts in with blue + /// + public void Eight() + { + Mat pic = CvInvoke.Imread("./img/iPhone.jpg"); + Mat thresholdPic = new Mat(); + Mat hierarchy = new Mat(); + + VectorOfVectorOfPoint contours = new VectorOfVectorOfPoint(); + + Image grayPic = pic.ToImage(); + + CvInvoke.Threshold(grayPic, thresholdPic, 210, 255, Emgu.CV.CvEnum.ThresholdType.Binary); + CvInvoke.FindContours(thresholdPic, contours, hierarchy, Emgu.CV.CvEnum.RetrType.Tree, Emgu.CV.CvEnum.ChainApproxMethod.ChainApproxNone); + CvInvoke.DrawContours(pic, contours, -1, new MCvScalar(0, 255, 0), 2); + + CvInvoke.FillPoly(pic, contours, new MCvScalar(255, 0, 0)); + + CvInvoke.Imshow("Threshold", thresholdPic); + CvInvoke.Imshow("pic with contours", pic); + + CvInvoke.WaitKey(); + } + + + public void Nine() + { + Mat answeredPic = CvInvoke.Imread("./img/GraderPage-Answered.jpg"); + Mat aWasAnswered = CvInvoke.Imread("./img/A_abcd.jpg"); + Mat templateOuput = new Mat(); + + CvInvoke.Resize(answeredPic, answeredPic, new System.Drawing.Size(0, 0), 0.7d, 0.7d); + CvInvoke.Resize(aWasAnswered, aWasAnswered, new System.Drawing.Size(0, 0), 0.7d, 0.7d); + + CvInvoke.MatchTemplate(answeredPic, aWasAnswered, templateOuput, Emgu.CV.CvEnum.TemplateMatchingType.CcoeffNormed); + + double minVal = 0.0d; + double maxVal = 0.0d; + System.Drawing.Point minLoc = new System.Drawing.Point(); + System.Drawing.Point maxLoc = new System.Drawing.Point(); + + CvInvoke.MinMaxLoc(templateOuput, ref minVal, ref maxVal, ref minLoc, ref maxLoc); + CvInvoke.Threshold(templateOuput, templateOuput, 0.85, 1, Emgu.CV.CvEnum.ThresholdType.ToZero); + + var matches = templateOuput.ToImage(); + + for (int i = 0; i < matches.Rows; i++) + { + for (int j = 0; j < matches.Cols; j++) + { + if (matches[i, j].Intensity > .8) + { + System.Drawing.Point loc = new System.Drawing.Point(j, i); + System.Drawing.Rectangle box = new System.Drawing.Rectangle(loc, aWasAnswered.Size); + + CvInvoke.Rectangle(answeredPic, box, new MCvScalar(0, 255, 0), 2); + } + } + } + + CvInvoke.Imshow("template detected", answeredPic); + + CvInvoke.WaitKey(); + } } } \ No newline at end of file diff --git a/Object-Detection.cs b/Object-Detection.cs index 7fb5abb..3c342f7 100644 --- a/Object-Detection.cs +++ b/Object-Detection.cs @@ -33,6 +33,22 @@ namespace ImageMinipulation vanGoghFilters sharpendNight = new vanGoghFilters(); sharpendNight.Five(); break; + case "Six": + vanGoghFilters sobelEdgeDetection = new vanGoghFilters(); + sobelEdgeDetection.Six(); + break; + case "Seven": + vanGoghFilters cannyEdgeDetection = new vanGoghFilters(); + cannyEdgeDetection.Seven(); + break; + case "Eight": + vanGoghFilters contour = new vanGoghFilters(); + contour.Eight(); + break; + case "Nine": + vanGoghFilters templateMatching = new vanGoghFilters(); + templateMatching.Nine(); + break; default: Console.WriteLine("That command didn't match any command on record."); break; diff --git a/bin/Debug/net9.0/Vision.dll b/bin/Debug/net9.0/Vision.dll index dcbb4c7..cc51578 100644 Binary files a/bin/Debug/net9.0/Vision.dll and b/bin/Debug/net9.0/Vision.dll differ diff --git a/bin/Debug/net9.0/Vision.exe b/bin/Debug/net9.0/Vision.exe index c79e926..cd31d3a 100644 Binary files a/bin/Debug/net9.0/Vision.exe and b/bin/Debug/net9.0/Vision.exe differ diff --git a/bin/Debug/net9.0/Vision.pdb b/bin/Debug/net9.0/Vision.pdb index d4755a7..8f8f4cb 100644 Binary files a/bin/Debug/net9.0/Vision.pdb and b/bin/Debug/net9.0/Vision.pdb differ diff --git a/img/A_abcd.jpg b/img/A_abcd.jpg new file mode 100644 index 0000000..f95b598 Binary files /dev/null and b/img/A_abcd.jpg differ diff --git a/img/GraderPage-Answered.jpg b/img/GraderPage-Answered.jpg new file mode 100644 index 0000000..fef6235 Binary files /dev/null and b/img/GraderPage-Answered.jpg differ diff --git a/img/iPhone.jpg b/img/iPhone.jpg new file mode 100644 index 0000000..7559557 Binary files /dev/null and b/img/iPhone.jpg differ diff --git a/obj/Debug/net9.0/Vision.AssemblyInfo.cs b/obj/Debug/net9.0/Vision.AssemblyInfo.cs index 691a056..d9751be 100644 --- a/obj/Debug/net9.0/Vision.AssemblyInfo.cs +++ b/obj/Debug/net9.0/Vision.AssemblyInfo.cs @@ -13,7 +13,7 @@ using System.Reflection; [assembly: System.Reflection.AssemblyCompanyAttribute("Vision")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] -[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+4a46119095f143590950b4c187458a1070c574b7")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+424280a29c9881a5ecf2ff086dd56660a7dfb2b8")] [assembly: System.Reflection.AssemblyProductAttribute("Vision")] [assembly: System.Reflection.AssemblyTitleAttribute("Vision")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] diff --git a/obj/Debug/net9.0/Vision.AssemblyInfoInputs.cache b/obj/Debug/net9.0/Vision.AssemblyInfoInputs.cache index fc2ddbe..8b2f1c4 100644 --- a/obj/Debug/net9.0/Vision.AssemblyInfoInputs.cache +++ b/obj/Debug/net9.0/Vision.AssemblyInfoInputs.cache @@ -1 +1 @@ -e17d606bef8dc49ab9098d852070f254921c1acafd1e4b9c0a795a2c3ae7c891 +be2338dcd47ff95872abf6d323fccdcf0b3d6fd8fe8e4067c056329d421dd863 diff --git a/obj/Debug/net9.0/Vision.dll b/obj/Debug/net9.0/Vision.dll index dcbb4c7..cc51578 100644 Binary files a/obj/Debug/net9.0/Vision.dll and b/obj/Debug/net9.0/Vision.dll differ diff --git a/obj/Debug/net9.0/Vision.pdb b/obj/Debug/net9.0/Vision.pdb index d4755a7..8f8f4cb 100644 Binary files a/obj/Debug/net9.0/Vision.pdb and b/obj/Debug/net9.0/Vision.pdb differ diff --git a/obj/Debug/net9.0/apphost.exe b/obj/Debug/net9.0/apphost.exe index c79e926..cd31d3a 100644 Binary files a/obj/Debug/net9.0/apphost.exe and b/obj/Debug/net9.0/apphost.exe differ diff --git a/obj/Debug/net9.0/ref/Vision.dll b/obj/Debug/net9.0/ref/Vision.dll index 03bdb01..3ddf348 100644 Binary files a/obj/Debug/net9.0/ref/Vision.dll and b/obj/Debug/net9.0/ref/Vision.dll differ diff --git a/obj/Debug/net9.0/refint/Vision.dll b/obj/Debug/net9.0/refint/Vision.dll index 03bdb01..3ddf348 100644 Binary files a/obj/Debug/net9.0/refint/Vision.dll and b/obj/Debug/net9.0/refint/Vision.dll differ