# Opencv With Python Quiz

Approved & Edited by ProProfs Editorial Team
At ProProfs Quizzes, our dedicated in-house team of experts takes pride in their work. With a sharp eye for detail, they meticulously review each quiz. This ensures that every quiz, taken by over 100 million users, meets our standards of accuracy, clarity, and engagement.
| Written by Abhilashk424
A
Abhilashk424
Community Contributor
Quizzes Created: 1 | Total Attempts: 12,457
Questions: 10 | Attempts: 12,465  Settings  • 1.

### What does the import cv2 statement do?

• A.

Imports the SciPy library for numerical processing.

• B.

Imports the NumPy library for numerical processing.

• C.

Imports our OpenCV Python bindings.

• D.

Displays an image to our screen.

C. Imports our OpenCV Python bindings.
Explanation
The import cv2 statement is used to import the OpenCV Python bindings. OpenCV is a popular library used for computer vision tasks such as image and video processing. By importing the cv2 module, we can access various functions and classes provided by OpenCV to perform tasks like reading and manipulating images, applying filters, detecting objects, and more in our Python code.

Rate this question:

• 2.

### Given the following NumPy array shape, how would we interpret the width, height, and number of channels in the image: (400, 600, 3):

• A.

Width=600, height=400, channels=3

• B.

Width=600, height=3, channels=400

• C.

Width=400, height=600, channels=3

• D.

width=3, width=600, channels=400

A. Width=600, height=400, channels=3
Explanation
The given NumPy array shape is (400, 600, 3). This means that the image has a width of 600 pixels, a height of 400 pixels, and 3 channels. The channels refer to the color channels of the image, which in this case is 3, indicating that the image is in RGB format. Therefore, the correct interpretation of the width, height, and number of channels in the image is width=600, height=400, channels=3.

Rate this question:

• 3.

### Suppose our image has a width of 700 pixels, a height of 550 pixels, and 3 channels, one for each Red, Green, and Blue component. How would we express this image as a NumPy array shape?

• A.

(550, 700, 3)

• B.

(3, 550, 700)

• C.

(700, 550, 3)

• D.

(3, 700, 550)

A. (550, 700, 3)
Explanation
The shape of a NumPy array is expressed as (height, width, channels). In this case, the height is 550 pixels, the width is 700 pixels, and there are 3 channels for the Red, Green, and Blue components. Therefore, the correct answer is (550, 700, 3).

Rate this question:

• 4.

### We have an image that is 393 pixels wide and 312 tall. How many total pixels are in the image?

• A.

367,848

• B.

122,616

• C.

280,800

• D.

93,600

B. 122,616
Explanation
The total number of pixels in an image can be calculated by multiplying the width and height of the image. In this case, the image is 393 pixels wide and 312 pixels tall. Multiplying these two values gives us 122,616, which is the total number of pixels in the image.

Rate this question:

• 5.

### OpenCV stores RGB pixels in what order?

• A.

GBR

• B.

RGB

• C.

BRG

• D.

BGR

D. BGR
Explanation
OpenCV stores RGB pixels in the order of BGR. This means that the blue channel value is stored first, followed by the green channel value, and then the red channel value. This ordering is different from the traditional RGB order, where the red channel value is stored first. OpenCV uses the BGR order because it was initially developed for the Intel Image Processing Library, which also used this ordering.

Rate this question:

• 6.

### The RGB tuple (255, 0, 0) codes for red. But OpenCV would actually interpret this color as:

• A.

Orange

• B.

Blue

• C.

Green

• D.

Yellow

B. Blue
Explanation
OpenCV would interpret the RGB tuple (255, 0, 0) as blue because OpenCV uses a different color channel order known as BGR (Blue, Green, Red) instead of the usual RGB (Red, Green, Blue) order. So, in OpenCV, the first value in the tuple corresponds to the blue channel, the second value corresponds to the green channel, and the third value corresponds to the red channel. Therefore, the correct interpretation of (255, 0, 0) in OpenCV is blue.

Rate this question:

• 7.

### Translation: What is the correct line of code that defines a translation matrix that shifts an image 10 pixels up and 20 pixels to the right?

• A.

M = np.float32([[1, 0, -20], [0, 1, 10]])

• B.

M = np.float32([[1, 0, 20], [0, 1, -10]])

• C.

M = np.float32([[1, 0, -10], [0, 1, 20]])

• D.

M = np.float32([[1, 0, 10], [0, 1, -20]])

B. M = np.float32([[1, 0, 20], [0, 1, -10]])
Explanation
The correct line of code that defines a translation matrix that shifts an image 10 pixels up and 20 pixels to the right is M = np.float32([[1, 0, 20], [0, 1, -10]]). This code creates a 2x3 matrix using np.float32, where the first row represents the x-axis translation (20 pixels to the right) and the second row represents the y-axis translation (10 pixels up).

Rate this question:

• 8.

### Translation: What is the correct line of code that defines a translation matrix that shifts an image 30 pixels down and 180 pixels to the left?

• A.

M = np.float32([[1, 0, -180], [0, 1, -30]])

• B.

M = np.float32([[1, 0, -180], [0, 1, 30]])

• C.

M = np.float32([[1, 0, 30], [0, 1, 180]])

• D.

M = np.float32([[1, 0, -30], [0, 1, -180]])

B. M = np.float32([[1, 0, -180], [0, 1, 30]])
Explanation
The correct answer is M = np.float32([[1, 0, -180], [0, 1, 30]]). This line of code defines a translation matrix that shifts an image 30 pixels down and 180 pixels to the left. The first row of the matrix represents the horizontal shift, where the value -180 indicates the shift to the left. The second row represents the vertical shift, where the value 30 indicates the shift downwards. The np.float32() function is used to convert the matrix elements to floating-point numbers.

Rate this question:

• 9.

### Cropping: I want to extract a rectangular region from my image starting at x=9, y=47 and ending at x=97, y=96. What is the correct line of code to perform this cropping?

• A.

Crop = image[9:97, 47:96]

• B.

Crop = image[47:96, 9:97]

• C.

Crop = image[9:47, 97:96]

• D.

crop = image[97:96, 9:47]

B. Crop = image[47:96, 9:97]
Explanation
The correct line of code to perform the cropping is "crop = image[47:96, 9:97]". This is because the syntax for cropping an image in Python is image[y1:y2, x1:x2], where (x1, y1) represents the top-left coordinates and (x2, y2) represents the bottom-right coordinates of the rectangular region to be extracted. In this case, the top-left coordinates are (9, 47) and the bottom-right coordinates are (97, 96), so the correct line of code is image[47:96, 9:97].

Rate this question:

• 10.

### Cropping: Now, suppose I want to extract a second rectangular region from my image starting at x=1, y=48 and ending at x=80, y=69. What is the correct line of code to perform this cropping?

• A.

Crop = image[80:69, 1:48]

• B.

Crop = image[1:48, 80:69]

• C.

Crop = image[48:80, 48:69]

• D.

Crop = image[48:69, 1:80] Back to top