I'm trying to determine the boundaries of the chessboard (they are bounded by a black bar)

I do the following
img = cv2.imread(filename)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
cv2.imwrite("gray.jpg", gray)
thresh = cv2.inRange(gray, hsv_min, hsv_max)
kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (7, 7))
thresh = cv2.dilate(thresh, kernel, iterations = 1)
thresh = cv2.erode(thresh, None, iterations = 4)
and there's no way I can get a better result, after
contours0, hierarchy = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
for cnt in contours0:
rect = cv2.minAreaRect(cnt)
box = cv2.boxPoints(rect)
box = np.int0(box)
cv2.drawContours(img, [box], -1, (255, 0, 0), 0)
cv2.imshow('contours', img)







