OpenCV

Creating an OpenCV 4 Project in Visual Studio 2017 & 2019

In my previous tutorial, I outlined how to build the OpenCV 4 library on Microsoft Windows 10. In that tutorial, however, I did not mention how to use that library in an actual project. This time around I will be showing you how to create an OpenCV 4 project within Microsoft Visual Studio 2017.

Please note that I am going to assume that your OpenCV install is set up in the way I outlined in my previous tutorial. That is to say that the necessary files are located within an OpenCV folder in your C:\ drive. If this is not the case you’ll have to make some minor modifications to the steps outlined here to suit your setup.

Let’s get started!

Continue reading…

Installing OpenCV 4 on Windows 10

I love working with the OpenCV library, but it can be a royal pain in the butt to get it installed and running on your machine. This is especially true for Microsoft Windows. Despite a Google search turning up plenty of results for articles promising to show you how to do it, they all seem to have issues or be incomplete. This results in a rather frustrating experience when you just want to get things up and running.

The purpose of this tutorial is to walk you through, step-by-step, how to install OpenCV version 4 on your Microsoft Windows 10 system. So, let’s quit talking about it and jump right in!

Continue reading…

Python – How to Capture Video Feed from Webcam Using OpenCV

Have you ever written code to interface with a webcam? Well, if you have then you know that it can be a royal pain in the ass. And God forbid you want it to be a cross-platform solution! The good news is that there is a ready-made solution that can help us out: OpenCV. Yes, you heard me right. Not only is OpenCV and amazing computer vision library, but it also provides a handy, cross-platform way of interfacing with webcams. Let’s take a look at how simple OpenCV makes this. I’ll be using Python for these examples, but the API is similar in other languages.

Shut Up and Show Me the Code!

Okay, okay, we’ll take a look at the code already 🙂

import cv2

# Open a handle to the default webcam
camera = cv2.VideoCapture(0)

# Start the capture loop
while True:
	# Get a frame
	ret_val, frame = camera.read()

	# Show the frame
	cv2.imshow('Webcam Video Feed', frame)

	# Stop the capture by hitting the 'esc' key
	if cv2.waitKey(1) == 27:
		break

# Dispose of all open windows
cv2.destroyAllWindows()

Not too surprisingly, running this simple script will open up a window displaying a live video feed from the default webcam. The window can be closed by hitting the escape key. I think this code is pretty self-explanatory, so I won’t dive into it here, but feel free to hit me up if you have any questions!