python提取图像指定物体轮廓

问题遇到的现象和发生背景

针对下图的船进行轮廓提取,

img

问题相关代码,请勿粘贴截图

img = cv2.imread('./img/yuantu.jpg')

image = cv2.imread('./tytyt_mask.png')

gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
blurred = cv2.GaussianBlur(gray, (3, 3), 0)
ret, binary = cv2.threshold(blurred, 127, 255, cv2.THRESH_BINARY)
contours, hierarchy = cv2.findContours(binary, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
cv2.drawContours(img, contours, -1, (0, 255, 0), 2)

cv2.imshow('lunkuo', img)
cv2.waitKey(0)
cv2.destroyAllWindows()

运行结果及报错内容

运行结果就是,提取了图像中全部的轮廓。

img

我的解答思路和尝试过的方法
我想要达到的结果

img

应改用模板匹配算法