Once upon a time, in the Universe of Machine Learning, on the planet of Computer Vision, there lived a powerful queen named OpenCV.
Her royal palace stood in the Kingdom of C++, where she had ruled for many years. Her court was magnificent: image processing, object detection, feature extraction, video analysis, and many other capabilities surrounded her.
News of the Queen’s benevolence eventually reached three neighbouring kingdoms: Python, R, and JavaScript.
Their citizens desired the benefits of her rule, but there was a problem: the Queen spoke C++.
Python therefore sent an ambassador to the royal court. The ambassador returned with "cv2", allowing OpenCV’s rule to extend into Python territory.
R followed, sending its own emissaries to the Queen’s court. They returned with OpenCV bindings, allowing her capabilities to be accessed from R.
JavaScript also sent emissaries, who returned with OpenCV.js, allowing the Queen to extend her rule into JavaScript territory.
Hence, the Queen’s rule extended beyond the Kingdom of C++, reaching the kingdoms of Python, R, and JavaScript.
Of course, that was merely the medieval version of the story. More seriously, there is an important lesson here: your OpenCV knowledge is transferable.
Once you have learned OpenCV in one language, moving to another does not mean learning Computer Vision from the beginning. The syntax and interfaces may differ, but many of the underlying concepts and operations remain familiar.
Let’s take a look.
OpenCV in Python and R
Suppose we want to read an image and convert it to grayscale.
In C++:
#include <opencv2/opencv.hpp>
int main() {
cv::Mat image = cv::imread("image.jpg");
cv::Mat gray;
cv::cvtColor(image, gray, cv::COLOR_BGR2GRAY);
return 0;
}
In Python:
import cv2
image = cv2.imread("image.jpg")
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
In R, the OpenCV package provides an interface to OpenCV:
library(opencv)
image <- ocv_read("image.jpg")
gray <- ocv_gray(image)
The syntax is different, but the task remains the same: read the image and convert it to grayscale.
OpenCV in JavaScript
JavaScript has OpenCV.js, which brings OpenCV to JavaScript applications and the browser.
A similar operation can be performed with the following HTML and JavaScript:
<script async src="opencv.js" type="text/javascript"></script>
js
let image = cv.imread("image");
let gray = new cv.Mat();
cv.cvtColor(image, gray, cv.COLOR_RGBA2GRAY);
Again, several things are immediately familiar if you already know OpenCV: "imread()", "cvtColor()", and the colour-conversion constants.
Moreover, a number of other kingdoms eventually benefited from the Queen’s rule as well. They include Java, MATLAB, and C#, through various bindings, interfaces, and wrappers that make OpenCV accessible from these languages.
The Queen’s influence, therefore, extends far beyond her original Kingdom of C++.
The same principle applies to many other operations, including resizing, thresholding, filtering, edge detection, and contours.
So, if you have learned OpenCV in one of these languages, changing languages does not necessarily mean beginning your Computer Vision journey again.
The Queen may extend her rule across different kingdoms, but learning her ways in one kingdom gives you a head start in another.