I am new to working on image processing. I have a folder that has images of various cars. I am trying to extract only their nameplates and put it in a different folder. I am getting an error stating "ValueError: too many values to unpack (expected 2)" in line 5 of the below code. I looked up for this code on the internet and trying to understand it. As far as I could figure out, we are first using the imread function to read the image and converting it into gray color space. The Canny function helps detect edges and findContours helps find the contours of the image. I don't seem to understand the code further ahead. It will be helpful if someone could guide me through the code as well as help me sort the error.
import cv2
image = cv2.imread("path")
imgray = cv2.cvtColor(im,cv2.COLOR_BGR2GRAY)
ret,thresh = cv2.threshold(imgray,127,255,0)
im2, contours, hierarchy =
cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
cnt = contours[4]
cv2.drawContours(im2, [cnt], 0, (0,255,0), 3)
idx = 0
for c in cnts:
x,y,w,h = cv2.boundingRect(c)
if w>50 and h>50:
idx+=1
new_img=image[y:y+h,x:x+w]
cv2.imwrite(str(idx) + '.png', new_img)
cv2.imshow("im",image)
cv2.waitKey(0)