#dotnet – detecting corners on the 🎦 camera feed with FAST algorithm, #OpenCV and #net5

Buy Me A Coffee

Hi !

Today is a quick one: FAST corner detection algorithm.

FAST (Features from Accelerated Segment Test) algorithm was proposed by Edward Rosten and Tom Drummond in their paper “Machine learning for high-speed corner detection” in 2006 (Later revised it in 2010). A basic summary of the algorithm is presented below. Refer original paper for more details (All the images are taken from original paper).

OpenCV includes the FAST algorithm as part of the base set of operations to perform on an image. You only need 2 lines of code to get this output.

opencv demo using fast algorithm

The OpenCV FAST tutorial (see references) explain the different steps and, I’ll keep this simple, just sharing the code !

public Mat applyEffect(Mat image)
{
var newImage = new Mat();
Cv2.CvtColor(image, newImage, ColorConversionCodes.BGR2GRAY, 0);
KeyPoint[] keypoints = Cv2.FAST(newImage, 50, true);
foreach (KeyPoint kp in keypoints)
newImage.Circle((Point)kp.Pt, 3, Scalar.Red, 1, LineTypes.AntiAlias, 0);
return newImage;
}

That’s all for today!

Happy coding!

Greetings

El Bruno


References

#dotnet – detecting edges on the 🎦 camera feed with Canny algorithm, #OpenCV and #net5

Buy Me A Coffee

Hi !

The Canny edge detection is one the most popular algorithms, and it’s also +30 years old.

The Canny edge detector is an edge detection operator that uses a multi-stage algorithm to detect a wide range of edges in images. It was developed by John F. Canny in 1986.

OpenCV includes the Canny algorithm as part of the base set of operations to perform on an image. You only need 2 lines of code to get this output.

canny demo effect using camera

The OpenCV canny tutorial (see references) explain the different steps to detect edges:

  • Noise Reduction
  • Finding Intensity Gradient of the Image
  • Non-maximum Suppression
  • Hysteresis Thresholding

I’ll keep this simple, just sharing the code !

using OpenCvSharp;
var capture = new VideoCapture(0);
var window = new Window("El Bruno – OpenCVSharp Effects demo");
var image = new Mat();
var imageNew = new Mat();
bool applyCanny = false;
bool run = true;
while (run)
{
capture.Read(image);
if (image.Empty()) break;
if (applyCanny)
imageNew = applyCannyEffect(image);
else
imageNew = image.Clone();
window.ShowImage(imageNew);
switch ((char)Cv2.WaitKey(100))
{
case (char)27: // Esc – Exit
run = false;
break;
case 'c':
applyCanny = !applyCanny;
break;
}
}
Mat applyCannyEffect(Mat image)
{
var newImage = new Mat();
Cv2.Canny(image, newImage, 50, 200);
return newImage;
}

That’s all for today!

Happy coding!

Greetings

El Bruno


References

#dotnet – less than 20 lines to display a 🎦 camera feed with #OpenCV and #net5

Buy Me A Coffee

Hi !

This post is the start of a series of posts around OpenCV and DotNet Core .Net 5. Most of my samples are going to be camera based, so I’ll start with the +20 13 lines needed to access a local camera and show the frames in a window.

opencvsharp camera sample

And the code using Net Core 5:

using OpenCvSharp;
var capture = new VideoCapture(0);
var window = new Window("El Bruno – OpenCVSharp demo");
var image = new Mat();
while (true)
{
capture.Read(image);
if (image.Empty())
break;
window.ShowImage(image);
if (Cv2.WaitKey(1) == 113) // Q
break;
}

A couple of notes on previous code

  • Pressing Q key will stop the program
  • Line 2 define the camera to open based on local indexes, in example
// 0 Logitech Brio
// 1 Msft Lifecam
// ... 
// 4 Logitech Capture
// 5 OBS VirtualCam
  • This is a standard .Net 5 Console App
  • I’m using the great OpenCVSharp nuget packages to have OpenCV capabilities in my app.
opencvsharp nuget packages

And because I’m using Net 5, here goes a before / after preview

That’s all for today!

Happy coding!

Greetings

El Bruno


References

#Event – Resources used during the session “Let’s code a drone 🛸 to follow faces with #dotnet”@dotnetdocsshow

Buy Me A Coffee

Hi !

I had a great time yesterday with the @dotnetdocsshow team talking about how to program a drone. And this time, with a special flavor:

Lets program the drone using dotnet core !

It was an amazing experience, and a really fun moment. Scott, David, Cam and Cecil are great hosts, and they make it very easy to move on from topic to topic.

Slides

Code

https://github.com/elbruno/events/tree/main/2020%2011%2009%20DotNetDocs%20Dev%20Drone%20AI

Resources

Recording

And, I’ll spend sometime in the near future sharing some lessons learned working with OpenCV, sockets and DotNetCore!

Happy coding!

Greetings

El Bruno