A. Missing the image argument in cv2.imshow function.
B. cv2.cvtColor cannot convert color images.
C. cv2.waitKey requires an argument of 1, not 0.
D. cv2.destroyAllWindows should be called before imshow.
Solution
Step 1: Check the usage of cv2.imshow
The function cv2.imshow requires two arguments: a window name and the image to display. Here, the image argument is missing.
Step 2: Verify other function calls
cv2.cvtColor correctly converts color images, waitKey(0) waits indefinitely, and destroyAllWindows is correctly placed after showing images.
Final Answer:
Missing the image argument in cv2.imshow function. -> Option A
Quick Check:
imshow needs image argument [OK]
Hint: imshow always needs image to show [OK]
Common Mistakes:
Forgetting the image argument in imshow
Misunderstanding waitKey argument
Calling destroyAllWindows too early
5. You want to write a program that reads an image, converts it to grayscale, and then saves the grayscale image. Which sequence of OpenCV functions is correct?
hard
A. cv2.imread() -> cv2.cvtColor() -> cv2.imwrite()
B. cv2.imshow() -> cv2.cvtColor() -> cv2.imwrite()
C. cv2.imread() -> cv2.imshow() -> cv2.cvtColor()
D. cv2.imwrite() -> cv2.imread() -> cv2.cvtColor()
Solution
Step 1: Understand the task steps
The program must first read the image, then convert it to grayscale, and finally save the new image.
Step 2: Match functions to steps
cv2.imread() reads the image, cv2.cvtColor() converts color spaces, and cv2.imwrite() saves the image to a file.
Final Answer:
cv2.imread() -> cv2.cvtColor() -> cv2.imwrite() -> Option A
Quick Check:
Read -> Convert -> Save = imread, cvtColor, imwrite [OK]