Top 9 Most Tricky Interview Questions on OpenCV

Aman Preet Last Updated : 21 Nov, 2022
6 min read

This article was published as a part of the Data Science Blogathon.

Introduction

The abbreviation of OpenCV is Open Source Computer vision which is a library that one can use for performing image processing operations and real-world computer vision tasks. The career path for whoever chooses OpenCV as the tool is computer vision developer or IOT Engineer and also in AR/VR (augmented and virtual reality); hence it is one of the hot topics for the interviewer to ask if you are applying for such a role.

OpenCV
 Source: FreeCourseOnline

OpenCV Interview Questions

1. How many types of commonly implemented image filters are you aware of in OpenCV?

There are multiple options when it comes to applying image filters; here are four widely used methods:

  • Averaging: In OpenCV, to perform the average, we use a normalized box filter where just like the normal average, we take the average of all the pixel values in kernel space and replace the same with the central element.
  • Gaussian Filtering: In Averaging, we have a box filter to convolve the image, but here, we have a Gaussian filter. It has a low-pass filter that removes high-frequency pixels from the images.
  • Median Filtering: As in averaging, we are getting the average of pixels similarly. In Median filtering, we get the median of all the pixels by using the dedicated function of OpenCV, i.e., medianBlur(). Not that we use these image filters mainly when we want to remove noise from the image.
  • Bilateral Filtering: The previous filter was used to blur the image. The same thing is done by this filter as well. The only difference is Bilateral filtering also preserves the edges of the image, i.e., it performs edge detection quite well.

2. How many video filters are you aware of in OpenCV?

  • Color Conversion: In this method, we take each video frame and then try to convert it to different color spaces like grayscale or BGR-HSV to serve different purposes.
  • Thresholding: This image segmentation technique returns us the binary/bitonal images based on what threshold value we are passing in the function, i.e., cv2.threshold().
  • Smoothing: This is a beneficial filter in real-time applications as it removes the noise and unwanted edges from the frames. It is also helpful in blurring operations as it removes high-frequency content.
  • Morphology Gradients Canny: One of the edge detection filters in OpenCV returns the difference between dilation and erosion. When we see the results, it will look alike the outline of an object detected.

3. What do you know about cv_8uc1 in OpenCV?

Before knowing what exactly is cv_8uc1 let us consider the scenario where it can be helpful for us to make the code clear. Suppose we are dealing with a matrix that has 10 channels to deal with or even more than that so at that time to maintain the flexible system, one needs to have a channel that will specify those number of channels, cv_8uc1 is that 8-bit single-channel array that not only make things more flexible but also makes the code more clear and readable.

4. How can you increase the quality of images using OpenCV?

In OpenCV or generally in any image processing step, whenever we are asking to increase the quality of the image, so we are looking for image enhancement (knowledge of the right terminology is essential for day-to-day work). Image enhancement is a complete situation based i.e.; each image comes up with different requirements and conditions that require an altogether different approach to deal with we also need to know which type of degradation is pictured in the image.

Based on my understanding, I’m listing down a few:

  1. Suppose your image has a lot of noise, and you don’t want those sharp edges in it, then go for filtering operations like mean median or even gaussian filtering.
  2. If the image you are processing has a high contrast i.e., it is either too dark or too bright, then go for the histogram equalization process, which will help you to dilate the contrast.
  3. Now comes the turn of a blurry image; sharpening your image to some extent is one of the pain when you have a blurred image for that, one can apply sharpening operations (canny detection is one of those).

5. Why is image transformation an important step in OpenCV?

The reason why OpenCV is very much famous in the area of computer vision and image processing is that it provides some serious support in implementing all the image transformation techniques in only a few lines of code, i.e., it helps in the easy implementation of those techniques which are otherwise quite expensive computationally.

Let us consider some real-world situations where image transformation is necessary to step to be taken:

  1. Scaling: Scaling is the operation in OpenCV used to resize the image to compare it with a similar object/image and, in the end, returns the result of whether the corresponding image is related to the current one or not.
  2. Cropping: Image cropping is very famous as we are doing this operation a lot to crop out someone from our good-looking pictures :), this is also one of the image transformation steps.
  3. Translation: In this process, the image is changed from one representation to another to learn the mapping between the input and output image.

6. Are you aware of “Rectification” in image processing?

Image rectification is the process in which multiple images are transformed into a common image plane. If one wanna see the bigger picture, then it simply helps to find the similar points between two or more two images to see whether the image is similar or not.

  • If we deep dive into its mathematical intuition, then with the help of a standard coordinate system, it solves the problem of image distortion by transforming the same.
  • As discussed earlier, it is best to find similar pixel values in corresponding images; hence it also has the real-world implementation of the same in computer stereo vision.
  • Image rectification is also handy in merging the images taken from different perspectives; again the real-world implementation of the same is a geographic information system.

7. Can you create custom classifiers in OpenCV? If yes, then how?

The answer in a word is- Yes; we can create custom classifiers in OpenCV. This can be done using XML-based HAAR cascade classifiers. We already have a few common Haar cascade classifiers like face, car, and eye detection, but what if we are developing a model aimed at detecting specific company products? Then we can create custom classifiers as well. We need a set of positive (authentic product images) and negative images (anything but not that product images) and pass it to the Haar classifier model.

8. Which method is one of the best for detecting faces? Your options are- Grayscale, Binary, Blur detection, or Edge detection. Support your answer with a valid reason as well.

  1. Grayscale converts the image to a single color, i.e., shaded gray other than that, no color is seen.
  2. Whereas Binary images are the one that stimulates two colors only, i.e., black and white.
  3. In Blur detection, fuzzy/blurry images are detected.
  4. In edge detection, the edges and distinct features of the object are detected in the image; hence among all the above options, this will be the best choice for face detection.

9. How Erosion and Dilation are different from each other?

Erosion is the process of removing pixels from the boundaries of an image, while dilation is adding pixels to the boundaries of an image.

  • Erosion is the process where pixels are removed from the boundaries of the image.
  • Dilation: It is just the opposite of erosion, as dilation adds more pixels to the boundaries of the image.

Note: Both adding and removing the pixels depend on the size and structuring of the image.

Conclusion

Here is the last part of this article which might help you understand how an interviewer can turn and twist the questions related to OpenCV or image processing in general, where OpenCV can be used as a tool. This section will provide you with the pathway to go through this article in a nutshell so that it can work as an index and save you time.

  1. First, we started with basic questions like naming and explaining image and video filters that one can implement using OpenCV then, we laid off towards a new term i.e., cv_8uc1, to see what it is capable of.
  2. Then we saw how the image could be enhanced using OpenCV by looking at some general steps and also learned the importance of image transformation. Then we learned about the term “Rectification” in image processing.
  3. Then in the last segment, we deep-dived into some more interesting questions like whether it is possible to create custom classifiers to detect images and also an MCQ question where we have to select the best algorithm for face detection and at last, we learned the basic yet effective difference between erosion and dilation in image processing.

The media shown in this article is not owned by Analytics Vidhya and is used at the Author’s discretion.

Responses From Readers

Clear

We use cookies essential for this site to function well. Please click to help us improve its usefulness with additional cookies. Learn about our use of cookies in our Privacy Policy & Cookies Policy.

Show details