I want to extract the outline using the image detection program, so I'm writing it based on the reference book.
ValueError: not enough values to unpack (expected3, got2)
I don't know because I got the error.It seems that the number of variables and elements does not match, but I tried many things, but I couldn't solve it.Please let me know if anyone can tell me.
# Extract contour
import cv2
import matplotlib.pyplot asplt
img_bgr=cv2.imread('earth15_02.jpg')
img_gray=cv2.cvtColor(img_bgr,cv2.COLOR_BGR2GRAY)
retval,thresh=cv2.threshold(img_gray,88,255,0)
img,contours,hierarchy=cv2.findContours(thresh,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)
result_img = cv2.drawContours(img,contours,-1,(0,0,255),3)
#
plt.imshow(result_img);
plt.show()
These articles will apply.
Resolving ValueError: not enough values to unpack in python
[OpenCV]ValueError: not enough values to unpack (expected 3, got 2)
Remove img
at the beginning of img,contours,hierarchy=cv2.findContours(thresh,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)
along with the second article, but the line works immediately uses img
as a parameter.
You will need to match the Python, OpenCV, and matplotlib editions to your reference books, or rewrite the source of the reference books to meet the specifications of the new editions.
By the way, it seems that this article corresponds to the number of new versions.
It may not be possible to compare it in detail with the contents of the reference book, but it is also a plus.
Basic image contour detection in OpenCV (per findContours function)
© 2024 OneMinuteCode. All rights reserved.