--- /dev/null
+import numpy as np\r
+import cv2\r
+\r
+def make_image():\r
+ img = np.zeros((500, 500), np.uint8)\r
+ black, white = 0, 255\r
+ for i in xrange(6):\r
+ dx = (i%2)*250 - 30\r
+ dy = (i/2)*150\r
+ \r
+ if i == 0:\r
+ for j in xrange(11):\r
+ angle = (j+5)*np.pi/21\r
+ c, s = np.cos(angle), np.sin(angle)\r
+ x1, y1 = np.int32([dx+100+j*10-80*c, dy+100-90*s])\r
+ x2, y2 = np.int32([dx+100+j*10-30*c, dy+100-30*s])\r
+ cv2.line(img, (x1, y1), (x2, y2), white)\r
+ \r
+ cv2.ellipse( img, (dx+150, dy+100), (100,70), 0, 0, 360, white, -1 )\r
+ cv2.ellipse( img, (dx+115, dy+70), (30,20), 0, 0, 360, black, -1 )\r
+ cv2.ellipse( img, (dx+185, dy+70), (30,20), 0, 0, 360, black, -1 )\r
+ cv2.ellipse( img, (dx+115, dy+70), (15,15), 0, 0, 360, white, -1 )\r
+ cv2.ellipse( img, (dx+185, dy+70), (15,15), 0, 0, 360, white, -1 )\r
+ cv2.ellipse( img, (dx+115, dy+70), (5,5), 0, 0, 360, black, -1 )\r
+ cv2.ellipse( img, (dx+185, dy+70), (5,5), 0, 0, 360, black, -1 )\r
+ cv2.ellipse( img, (dx+150, dy+100), (10,5), 0, 0, 360, black, -1 )\r
+ cv2.ellipse( img, (dx+150, dy+150), (40,10), 0, 0, 360, black, -1 )\r
+ cv2.ellipse( img, (dx+27, dy+100), (20,35), 0, 0, 360, white, -1 )\r
+ cv2.ellipse( img, (dx+273, dy+100), (20,35), 0, 0, 360, white, -1 )\r
+ return img\r
+\r
+if __name__ == '__main__':\r
+ img = make_image()\r
+ h, w = img.shape[:2]\r
+\r
+ contours0, hierarchy = cv2.findContours( img.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)\r
+ contours = [cv2.approxPolyDP(cnt, 3, True) for cnt in contours0]\r
+ \r
+ def update(levels):\r
+ vis = np.zeros((h, w, 3), np.uint8)\r
+ levels = levels - 3\r
+ cv2.drawContours( vis, contours, (-1, 3)[levels <= 0], (128,255,255), \r
+ 3, cv2.CV_AA, hierarchy, abs(levels) )\r
+ cv2.imshow('contours', vis)\r
+ update(3)\r
+ cv2.createTrackbar( "levels+3", "contours", 3, 7, update )\r
+ cv2.imshow('image', img)\r
+ cv2.waitKey()
\ No newline at end of file