contours, hierarchy = cv2.findContours(opening,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
idx =0
for cnt in contours:
if cv2.contourArea(cnt) >3000:
idx += 1
x,y,w,h = cv2.boundingRect(cnt)
roi=img[y:y+h,x:x+w]
cv2.imwrite(str(idx) + ".jpg", roi)
cv2.rectangle(img,(x,y),(x+w,y+h),(200,0,0),2)
It works, but the crop contours saved randomly. I need the crop image saved respected to X value from low to high.