I'm trying to find the contour of the attached image of a tshirt. FindContours returns a rectangular frame around the tshirt, and doesn't find any additional contours.
My goal is to find the external contour of the tshirt.
Any idea what am I doing wrong?
Code below. Thanks. Li
from PIL import Image
import os
import numpy
import bs4
import scipy
import cv2
STANDARD_SIZE = (200, 200)
# read image file
image_obj_orig = cv2.imread(image_file)
image_name = os.path.split(image_file)[-1]
name, extension = os.path.splitext(image_name)
# normalize to a standard size
image_obj = cv2.resize(image_obj_orig, STANDARD_SIZE)
# convert to grey-scale
greyscale_image = cv2.cvtColor(image_obj,cv2.COLOR_BGR2GRAY)
cv2.imwrite(os.path.join(trg_dir, name + '_GS' + extension), greyscale_image)
h, w = greyscale_image.shape[:2]
contours, hierarchy = cv2.findContours( greyscale_image.copy(), cv2.RETR_TREE , cv2.CHAIN_APPROX_SIMPLE)
cv2.drawContours( greyscale_image, contours, -1, (128,255,255))
cv2.imshow('image', greyscale_image)