Prefer Scoped Enums over Unscoped Enums (Notes)

Scoped vs Unscoped Enums General rule: declaring a name inside curly braces is limited to that scope. Exception: C++-98 style Enums NOTE My notes on Chapter 3, Item 10 of Effective Modern C++ written by Scott Meyers. Some (or even all) of the text can be similar to what you see in the book, as these are notes: I’ve tried not to be unnecessarily creative with my words. :) ...

August 14, 2021 · 5 min · Kushashwa Ravi Shrimali

Union Find Problem, and a naive implementation (C++)

Hi Everyone, today I want to talk about Union Find Problem. This is going to be a series covering: Union Find Problem (this blog) Solutions to Union Find (1): Quick Find Solutions to Union Find (2): Quick Union Solutions to Union Find (3): Weighted Quick Union Applications of Union Find (perculation and more) Cool project using Union Find Solving some competitive programming questions using Union Find Each blog will try to cover very basic concepts behind the topic, and also what it’s all about. ...

August 14, 2021 · 7 min · Kushashwa Ravi Shrimali

Prefer Alias Declarations to Typedefs (Notes)

One solution to avoiding using long type names: // So C++98 like typedef std::unique_ptr<std::unordered_map<std::string, std::string>> UPtrMapSS; ...

August 12, 2021 · 3 min · Kushashwa Ravi Shrimali

Function Pointers and Function Objects in C++

In today’s blog, we’ll talk about two important concepts in C++: Function Pointers and Function Objects. Please note that, function objects are commonly referred as functors but we have failed to notice any official alias to the name. Hence, we’ll restrict ourselves to using Function Objects in this blog. ...

July 18, 2021 · 9 min · Kushashwa Ravi Shrimali

How to crop a circle in OpenCV? Implementing Portrait Bokeh - Part 2

Hi everyone! In the previous blog we implemented Portrait Bokeh using Face Detection in OpenCV. While the results were good for a start, we definitely want to be closer to the output we expect. The end goal is to blur everything except the face. The main problem we noticed was: The face cropped was a rectangle, and it was clearly visible in the output result. To overcome this, we will be talking about cropping a circle in OpenCV today. This will enable us to get rid of “some” of the background noise we got earlier, for Portrait Bokeh. Let’s take this step by step, and first talk about the intuition. ...

December 10, 2020 · 10 min · Kushashwa Ravi Shrimali

Implementing Portrait Bokeh in OpenCV using Face Detection (Part-1)

OpenCV: Using face detection for Portrait Bokeh (Background Blur) (Part - 1) This blog discusses using Face Detection in OpenCV for Portrait Bokeh. We’ll be implementing Portrait Bokeh (blurring everything but faces) using 3 different methods in this series: Using Face Detection (cropping a rectangle) Using Face Detection (cropping a circle) Using Facial Landmark Detection and Convex Hull Don’t lose hopes if you are confused. We will be going through each method one by one, and hopefully the road will be crearer from here. ...

December 7, 2020 · 5 min · Kushashwa Ravi Shrimali

Releasing Docker Container and Binder for using Xeus-Cling, Libtorch and OpenCV in C++

Today, I am elated to share Docker image for OpenCV, Libtorch and Xeus-Cling. We’ll discuss how to use the dockerfile and binder. Before I move on, the credits for creating and maintaining Docker image goes to Vishwesh Ravi Shrimali. He has been working on some cool stuff, please do get in touch with him if you’re interested to know. First question in your mind would be, Why use Docker or Binder? The answer to it lies in the frequency of queries on the discussion forum of PyTorch and Stackoverflow on Installation of Libtorch with OpenCV in Windows/Linux/OSX. I’ve had nightmares setting up the Windows system myself for Libtorch and nothing could be better than using Docker. Read on, to know why. ...

September 15, 2020 · 3 min · Kushashwa Ravi Shrimali

Understanding how Vectors work in C++ (Part-2): What happens when you initialize a vector?

In the last blog post, I realized there were a lot of methods inherited from the base struct _Vector_base_ and _Vector_impl_data. Instead of directly going to the source code of these structs, I’ll go through their methods and objects by explaining what happens when we initialize a vector. That is, we will start from calling a vector constructor and then see how memory is allocated. If you haven’t looked at the previous blog post, please take a look here. I want to be thorough with the blog post, so I’ll divide this into multiple posts. By the end of this post, you’ll go through the following structs: ...

April 26, 2020 · 7 min · Kushashwa Ravi Shrimali

Understanding how Vectors work in C++ (Part-3): Diving deep into member functions of vectors

In this blog, we’ll continue diving deep into the source code of Vector Containers in GCC compiler. Today, we will be discussing some of the most commonly used methods of vectors, and how they are implemented. Before we start, if you haven’t looked at the previous blogs in the C++ series, please take a look here. If you are already familiar with memory allocation in vector containers and vector’s base structs, then you can skip reading the previous blogs and continue here. If not, I suggest you reading them. ...

April 26, 2020 · 7 min · Kushashwa Ravi Shrimali

Understanding how Vectors work in C++ (Part-1): How does push_back work?

This blog is focused to explain how vectors work in the backend, and we’ll specially look at push_back method of the vector container. Looking at the source code helps to understand the implementation, and how vectors can be used efficiently. Vector Containers are type of sequenced containers in C++ commonly uses as a better alternative of arrays. They are also known as dynamic arrays, and as the term suggests - it’s one of the advantages they hold over native arrays in C++. You might have heard of Standard Library containers like vector, set, queue, priority_queue before. They all implement methods defined by the Container Concept. ...

April 18, 2020 · 7 min · Kushashwa Ravi Shrimali