Home »
MCQs
Python OpenCV MCQs (Multiple-Choice Questions)
Python OpenCV is a Python interface for OpenCV, an open-source computer vision library used for image processing, video analysis, object detection, feature detection, and other computer vision tasks. OpenCV-Python works closely with NumPy arrays for representing and manipulating image data.
Python OpenCV MCQs
These Python OpenCV multiple-choice questions cover important concepts such as image reading and writing, color spaces, pixels, NumPy arrays, image transformations, filtering, thresholding, morphology, edge detection, contours, video processing, cameras, and object detection.
List of Python OpenCV MCQs
Practice these Python OpenCV MCQs with answers and explanations to improve your knowledge of OpenCV and prepare for exams, interviews, quizzes, and technical assessments.
1. What does OpenCV primarily provide?
- Computer vision and image processing functionality
- Relational database management
- Web application routing
- Operating system administration
Answer: A) Computer vision and image processing functionality
Explanation:
OpenCV is an open-source library that provides algorithms and tools for computer vision, image processing, video analysis, and related tasks.
2. Which Python package is commonly imported to use OpenCV?
- opencv
- cv2
- openvision
- pyvision
Answer: B) cv2
Explanation:
The Python bindings for OpenCV are commonly imported using import cv2.
3. OpenCV-Python is primarily a set of bindings for which OpenCV language API?
- JavaScript
- C++
- Ruby
- PHP
Answer: B) C++
Explanation:
OpenCV is primarily implemented in C++, while OpenCV-Python provides Python bindings that expose OpenCV functionality to Python programs.
4. Which library is heavily used with OpenCV-Python for image array operations?
- NumPy
- Flask
- Django
- Requests
Answer: A) NumPy
Explanation:
OpenCV-Python represents images as NumPy arrays, making NumPy operations important for accessing pixels, regions of interest, and image data.
5. Which function is used to read an image from a file?
cv2.imread()
cv2.readImage()
cv2.load()
cv2.openImage()
Answer: A) cv2.imread()
Explanation:
cv2.imread() loads an image from a file and returns the image as an array when the file can be read successfully.
6. Which function is used to save an image to a file?
cv2.save()
cv2.imwrite()
cv2.writeImage()
cv2.store()
Answer: B) cv2.imwrite()
Explanation:
cv2.imwrite() writes an image to a specified file.
7. What does cv2.imread() generally return when an image cannot be read?
True
None
- An empty string
- A text error message
Answer: B) None
Explanation:
In Python, cv2.imread() returns None when the image cannot be loaded, such as when the file is missing or invalid.
8. Which function displays an image in an OpenCV window?
cv2.display()
cv2.show()
cv2.imshow()
cv2.view()
Answer: C) cv2.imshow()
Explanation:
cv2.imshow() displays an image in a named OpenCV window.
9. Which function is commonly used to wait for a keyboard event in an OpenCV GUI application?
cv2.waitKey()
cv2.waitEvent()
cv2.keyWait()
cv2.pause()
Answer: A) cv2.waitKey()
Explanation:
cv2.waitKey() waits for a keyboard event for a specified amount of time and is commonly used with OpenCV display windows.
10. Which function creates a named OpenCV window?
cv2.createWindow()
cv2.namedWindow()
cv2.openWindow()
cv2.window()
Answer: B) cv2.namedWindow()
Explanation:
cv2.namedWindow() creates a window that can be used for displaying images and other GUI elements.
11. What color channel order does OpenCV commonly use when reading a color image?
- RGB
- GRB
- BGR
- RBG
Answer: C) BGR
Explanation:
OpenCV commonly represents a three-channel color image in Blue, Green, Red (BGR) order rather than the RGB order commonly used in other libraries.
12. In OpenCV's BGR representation, what does the first channel represent?
- Red
- Green
- Blue
- Alpha
Answer: C) Blue
Explanation:
For a standard three-channel BGR image, the first channel contains blue values, followed by green and red.
13. Which flag can be used with cv2.imread() to load an image as grayscale?
cv2.IMREAD_GRAY
cv2.IMREAD_GRAYSCALE
cv2.GRAYSCALE
cv2.READ_GRAY
Answer: B) cv2.IMREAD_GRAYSCALE
Explanation:
cv2.IMREAD_GRAYSCALE instructs OpenCV to load the image in grayscale mode.
14. Which function converts an image from one color space to another?
cv2.colorChange()
cv2.cvtColor()
cv2.convertColor()
cv2.changeColor()
Answer: B) cv2.cvtColor()
Explanation:
cv2.cvtColor() converts image data between supported color spaces.
15. Which conversion code converts a BGR image to grayscale?
cv2.COLOR_RGB2GRAY
cv2.COLOR_BGR2GRAY
cv2.COLOR_GRAY2BGR
cv2.COLOR_BGR2RGB
Answer: B) cv2.COLOR_BGR2GRAY
Explanation:
cv2.COLOR_BGR2GRAY converts a BGR image into a single-channel grayscale image.
16. Which NumPy property can be used to obtain the dimensions of an image array?
shape
dimension
sizeOf
resolution
Answer: A) shape
Explanation:
The NumPy shape property provides the size of each dimension of an image array.
17. For a typical color image represented as a NumPy array, what do the first two dimensions represent?
- Width and color only
- Height and width
- Channels and width
- Depth and channels
Answer: B) Height and width
Explanation:
For a typical OpenCV color image array, the first dimension represents height and the second represents width. A third dimension represents color channels.
18. How can a region of interest be selected from an image in OpenCV-Python?
- Using NumPy slicing
- Using only
cv2.roi()
- Using SQL queries
- Using
cv2.region()
Answer: A) Using NumPy slicing
Explanation:
OpenCV-Python images are NumPy arrays, so array slicing can be used to select a rectangular region of interest.
19. Which function resizes an image?
cv2.resize()
cv2.scale()
cv2.changeSize()
cv2.resizeImage()
Answer: A) cv2.resize()
Explanation:
cv2.resize() changes the spatial dimensions of an image using a selected interpolation method.
20. Which OpenCV function is commonly used for rotating an image by a predefined 90-degree orientation?
cv2.rotate()
cv2.turn()
cv2.rotation()
cv2.spin()
Answer: A) cv2.rotate()
Explanation:
cv2.rotate() performs rotations using predefined rotation flags such as 90 degrees clockwise or counterclockwise.
21. Which function performs an affine transformation in OpenCV?
cv2.warpAffine()
cv2.affine()
cv2.transformAffine()
cv2.applyAffine()
Answer: A) cv2.warpAffine()
Explanation:
cv2.warpAffine() applies an affine transformation matrix to an image.
22. Which function performs a perspective transformation?
cv2.warpPerspective()
cv2.perspective()
cv2.warpProject()
cv2.projectImage()
Answer: A) cv2.warpPerspective()
Explanation:
cv2.warpPerspective() applies a perspective transformation using a transformation matrix.
23. Which interpolation method uses the nearest pixel when resizing an image?
cv2.INTER_NEAREST
cv2.INTER_LINEAR
cv2.INTER_CUBIC
cv2.INTER_AREA
Answer: A) cv2.INTER_NEAREST
Explanation:
INTER_NEAREST uses nearest-neighbor interpolation, selecting the nearest source pixel.
24. Which function applies a Gaussian blur to an image?
cv2.gaussianBlur()
cv2.GaussianBlur()
cv2.gaussianFilter()
cv2.blurGaussian()
Answer: B) cv2.GaussianBlur()
Explanation:
cv2.GaussianBlur() applies Gaussian filtering to an image and is commonly used for smoothing.
25. Which function performs median filtering?
cv2.medianBlur()
cv2.medianFilter()
cv2.blurMedian()
cv2.filterMedian()
Answer: A) cv2.medianBlur()
Explanation:
cv2.medianBlur() applies median filtering and is commonly useful for reducing certain types of image noise.
26. Which OpenCV function performs bilateral filtering?
cv2.bilateralFilter()
cv2.bilateralBlur()
cv2.edgeFilter()
cv2.edgeBlur()
Answer: A) cv2.bilateralFilter()
Explanation:
cv2.bilateralFilter() performs edge-preserving smoothing by considering both spatial and intensity differences.
27. Which function applies a fixed-level threshold to an image?
cv2.threshold()
cv2.applyThreshold()
cv2.binary()
cv2.segment()
Answer: A) cv2.threshold()
Explanation:
cv2.threshold() applies a fixed thresholding operation to array elements. OpenCV supports several threshold types.
28. Which thresholding method automatically determines a threshold from the image histogram?
- Otsu's thresholding
- Manual thresholding
- Nearest thresholding
- Median thresholding
Answer: A) Otsu's thresholding
Explanation:
Otsu's method automatically determines a threshold value based on the image histogram and is commonly used for separating foreground and background.
29. Which OpenCV function performs adaptive thresholding?
cv2.adaptiveThreshold()
cv2.localThreshold()
cv2.autoThreshold()
cv2.dynamicThreshold()
Answer: A) cv2.adaptiveThreshold()
Explanation:
cv2.adaptiveThreshold() calculates a threshold for smaller regions of an image rather than applying one global threshold to the entire image.
30. Which function performs Canny edge detection?
cv2.edgeDetect()
cv2.Canny()
cv2.detectEdges()
cv2.Edge()
Answer: B) cv2.Canny()
Explanation:
cv2.Canny() implements the Canny edge detection algorithm for detecting significant edges in an image.
31. Which functions are commonly used for image gradients in OpenCV?
cv2.Sobel(), cv2.Scharr(), and cv2.Laplacian()
cv2.Canny(), cv2.Hough(), and cv2.Blur()
cv2.Read(), cv2.Write(), and cv2.Show()
cv2.Merge(), cv2.Split(), and cv2.Resize()
Answer: A) cv2.Sobel(), cv2.Scharr(), and cv2.Laplacian()
Explanation:
OpenCV provides Sobel, Scharr, and Laplacian operations for calculating image gradients and derivatives.
32. Which function performs erosion in OpenCV?
cv2.erode()
cv2.erosion()
cv2.shrink()
cv2.reduceObject()
Answer: A) cv2.erode()
Explanation:
cv2.erode() performs morphological erosion using a specified structuring element.
33. Which function performs dilation?
cv2.expand()
cv2.dilate()
cv2.dilation()
cv2.grow()
Answer: B) cv2.dilate()
Explanation:
cv2.dilate() performs morphological dilation using a structuring element.
34. Which function performs advanced morphological operations such as opening and closing?
cv2.morphologyEx()
cv2.morphology()
cv2.morph()
cv2.advancedMorph()
Answer: A) cv2.morphologyEx()
Explanation:
cv2.morphologyEx() performs advanced morphological transformations based on operations such as erosion and dilation.
35. What is morphological opening generally composed of?
- Dilation followed by erosion
- Erosion followed by dilation
- Thresholding followed by dilation
- Blurring followed by thresholding
Answer: B) Erosion followed by dilation
Explanation:
Morphological opening is defined as erosion followed by dilation using the same structuring element.
36. What is morphological closing generally composed of?
- Erosion followed by dilation
- Dilation followed by erosion
- Thresholding followed by erosion
- Blurring followed by dilation
Answer: B) Dilation followed by erosion
Explanation:
Morphological closing is defined as dilation followed by erosion using the same structuring element.
37. Which function creates a structuring element for morphological operations?
cv2.getStructuringElement()
cv2.createKernel()
cv2.makeStructure()
cv2.kernelElement()
Answer: A) cv2.getStructuringElement()
Explanation:
cv2.getStructuringElement() creates a structuring element such as a rectangle, ellipse, or cross-shaped kernel for morphological operations.
38. What is a contour in OpenCV?
- A curve joining continuous points along a boundary
- A database record
- A color conversion table
- A video codec
Answer: A) A curve joining continuous points along a boundary
Explanation:
Contours represent curves joining continuous points along boundaries with the same color or intensity and are useful for shape analysis and object detection.
39. Which function finds contours in an image?
cv2.findContours()
cv2.detectContours()
cv2.getContours()
cv2.searchContours()
Answer: A) cv2.findContours()
Explanation:
cv2.findContours() detects contours in a binary or suitably prepared image.
40. Which function draws contours on an image?
cv2.paintContours()
cv2.drawContours()
cv2.renderContours()
cv2.showContours()
Answer: B) cv2.drawContours()
Explanation:
cv2.drawContours() draws detected contours onto an image.
41. Which contour retrieval mode retrieves all contours and establishes a full hierarchy?
cv2.RETR_EXTERNAL
cv2.RETR_LIST
cv2.RETR_TREE
cv2.RETR_SIMPLE
Answer: C) cv2.RETR_TREE
Explanation:
cv2.RETR_TREE retrieves contours and reconstructs a complete hierarchy of nested contours.
42. Which function calculates the area of a contour?
cv2.contourArea()
cv2.areaContour()
cv2.calculateArea()
cv2.objectArea()
Answer: A) cv2.contourArea()
Explanation:
cv2.contourArea() calculates the area enclosed by a contour.
43. Which function calculates the perimeter or arc length of a contour?
cv2.arcLength()
cv2.contourLength()
cv2.perimeter()
cv2.lengthContour()
Answer: A) cv2.arcLength()
Explanation:
cv2.arcLength() calculates the arc length of a curve or contour.
44. Which class is commonly used to capture video from a camera in OpenCV-Python?
cv2.VideoCapture
cv2.CameraCapture
cv2.VideoReader
cv2.Camera
Answer: A) cv2.VideoCapture
Explanation:
cv2.VideoCapture provides an interface for capturing frames from cameras, video files, or other supported video sources.
45. Which method reads the next frame from a VideoCapture object?
read()
next()
capture()
frame()
Answer: A) read()
Explanation:
The read() method retrieves the next video frame and returns a success indicator along with the frame.
46. Which OpenCV class is used to write video frames to a video file?
cv2.VideoWriter
cv2.VideoSave
cv2.VideoOutput
cv2.VideoRecorder
Answer: A) cv2.VideoWriter
Explanation:
cv2.VideoWriter provides an interface for writing video frames to a video file.
47. Which function is commonly used to detect circles using the Hough Circle Transform?
cv2.HoughCircles()
cv2.detectCircles()
cv2.findCircles()
cv2.CircleTransform()
Answer: A) cv2.HoughCircles()
Explanation:
cv2.HoughCircles() implements the Hough Circle Transform for detecting circles in images.
48. Which OpenCV technique can be used to detect straight lines?
- Hough Line Transform
- Median Transform
- Color Transform
- Pixel Transform
Answer: A) Hough Line Transform
Explanation:
The Hough Line Transform is used to detect straight lines in images and is available through OpenCV functions such as cv2.HoughLines().
49. Which OpenCV feature is specifically designed for detecting objects such as faces using cascade classifiers?
- Haar Cascade Classifier
- Median Filter
- Gaussian Pyramid
- Color Mapper
Answer: A) Haar Cascade Classifier
Explanation:
OpenCV provides cascade classifiers, including Haar feature-based cascades, for object detection tasks such as face detection.
50. Which statement best describes OpenCV-Python?
- A Python interface for OpenCV used for computer vision tasks
- A Python-only database engine
- A web framework for creating REST APIs
- A package exclusively for numerical statistics
Answer: A) A Python interface for OpenCV used for computer vision tasks
Explanation:
OpenCV-Python provides Python bindings for OpenCV and is used for image processing, video analysis, object detection, feature detection, and many other computer vision applications.
Advertisement
Advertisement