ValueError: too many values to unpack (expected 4) code example

Example 1: cv2.solvepnpransac too many values to unpack

So it might help to try out:

_, rvecs, tvecs, inliers  = cv2.solvePnPRansac(objp, corners2, mtx, dist)
or in case you just want to unpack the last 3 elements:

rvecs, tvecs, inliers  = cv2.solvePnPRansac(objp, corners2, mtx, dist)[:-3]

Example 2: ValueError: too many values to unpack (expected 2)

The “valueerror: too many values to unpack (expected 2)” error occurs when you do not unpack all the items in a list. This error is often caused by trying to iterate over the items in a dictionary. To solve this problem, use the items() method to iterate over a dictionary.

Example 3: ValueError: not enough values to unpack (expected 3, got 2)

contours, hierarchy = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)

Tags:

C Example