This set of OpenCV Multiple Choice Questions & Answers (MCQs) focuses on “Basic I/O Scripts”.
1. Which OpenCV method or function is used for loading the file?
a) imread()
b) imwrite()
c) imload()
d) imget()
View Answer
Explanation: imread() is the function or method that is used for loading or reading of the files in the system. Imread() stores the image in matrix form, if the image cannot be read because of improper permissions, invalid format, wrong location, missing file, etc. the method will return an empty matrix.
2. Which OpenCV method or function is used for saving the image?
a) imread()
b) imwrite()
c) imload()
d) imget()
View Answer
Explanation: imwrite() is the method or function that is used for saving the image file to any storage device. The imwrite() function stores the image in specified format like jpg, png, tiff, bmp etc.
3. What is the full form of JPEG?
a) Joint Photographic Experts Group
b) Jumper Photographic Experts Group
c) Java Photo Expert Group
d) Joint Photo Experts Group
View Answer
Explanation: JPEG stands for Joint Photographic Experts Group. It is also known as JPG. It is one of the standard formats for compressing and saving graphic images. It is a lossy technique of compression as some amount of information is lost from the image.
4. By default, imread() function returns an image in RGB color Format.
a) True
b) False
View Answer
Explanation: By default, imread() function return an image in BGR (blue-green-red) color format not RGB (red-green-blue). The value of blue is swapped with the value of red in BGR color format matrix and red value is swapped by blue value in RGB color format matrix.
5. What is the full form of BMP?
a) Binary Map
b) Bit Map Puller
c) Bit Map
d) Bit Micro point
View Answer
Explanation: The full form of BMP is bitmap. It is an image format developed by Microsoft. It is device-independent bitmap (DIB) format that allows Windows to display the bitmap on any type of display devices. The bitmap file format can be stored from a compressed file.
6. Channel mixing is a technique used for remapping colors.
a) True
b) False
View Answer
Explanation: Channel mixing is a technique which is used for remapping colors. Channel mixing is a technique which allows the user to change the color of any element of the image to any other color in the light spectrum.
7. Which of these is the correct code for converting the PNG format image to JPEG format image?
a)
import cv2 image = cv2.read('image.png') cv2.write('new_image.jpeg', image)
b)
import cv2 image = cv.read('image.png') cv2.write('new_image.jpeg', image)
c)
import cv2 image = cv2.read('image.png') cv2.write('new_image.jpeg')
d)
import cv2 image = cv2.read('image.png') cv2.save('new_image.jpeg', image)
Explanation: The read() function reads or loads the image in the system and imwrite() function takes two argument the name of the new image and the variable name where the image is saved. Remember to use cv2 instead of cv.
8. Which of these code converts bytearray containing random bytes to a grayscale image?
a)
import cv2 import numpy randomByteArray = bytearray(os.random(1200000)) flatArray = numpy.array(randomByteArary) grayImage = flatArray.reshape(300,400) cv2.imwrite(‘randomgrayImage.png’, grayImage)
b)
import cv2 import os randomByteArray = bytearray(os.random(1200000)) flatArray = numpy.array(randomByteArary) grayImage = flatArray.reshape(300,400) cv2.imwrite(‘randomgrayImage.png’, grayImage)
c)
import cv2 import numpy import os randomByteArray = bytearray(os.random(1200000)) flatArray = numpy.array(randomByteArary) grayImage = flatArray.reshape(300,400) cv2.imwrite(‘randomgrayImage.png’, grayImage)
d)
import numpy import os randomByteArray = bytearray(os.random(1200000)) flatArray = numpy.array(randomByteArary) grayImage = flatArray.reshape(300,400) cv2.imwrite(‘randomgrayImage.png’, grayImage)
Explanation: The os library imports the random() function which generates the random number given in range, the cv2 library imports imwrite() function that save or converts the image file format and the numpy library imports reshape() function that changes the shape of the image’s matrix.
9. Which OpenCV classes supports video file format?
a) VideoCapture and VideoWriter
b) VideoRead and VideoSave
c) VideoCapture and VideoRead
d) VideoRead and VideoShow
View Answer
Explanation: OpenCV provides VideoCapture and VideoWriter classes that supports different video file formats. Each frame of the video is in default BGR (Blue-Green-Red) color format which can be changed using the different parameters or arguments provided by read() function.
10. What is the full form of MPEG?
a) Motion Picture Experts Group
b) Moving Picture Experts Group
c) Motion Photographs Experts Group
d) Moving Photographs Experts Group
View Answer
Explanation: The Full form of MPEG is Moving Picture Experts Group. It is a video file compression format that compresses the audio and video files. The files with MPEG compression technique will have .mpeg extension.
Sanfoundry Global Education & Learning Series – OpenCV.
To practice all areas of OpenCV, here is complete set of Multiple Choice Questions and Answers.