# -*- coding: utf-8 -*-
"""
"""

import cv2
import numpy as np
import matplotlib.pyplot as plt
from preproces_max import *

img_num = 101468
per = 50#%


img = cv2.imread('images_test_rev1/'+str(img_num)+'.jpg', 0)
tt = int((per/100.0)*max_img(img))
#print tt
ret,thresh = cv2.threshold(img,tt,255,0)
contours,hierarchy = cv2.findContours(thresh, 1, 2)
#contours, hierarchy = cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)

img = cv2.imread('images_test_rev1/'+str(img_num)+'.jpg')
cv2.drawContours(img,contours,-1,(0,255,0),3)

print len(contours)
plt.subplot(1,2,1), plt.imshow(img)
plt.title('Threshold 50%')
plt.axis('off')
per = 20#%
img = cv2.imread('images_test_rev1/'+str(img_num)+'.jpg', 0)
tt = int((per/100.0)*max_img(img))
#print tt
ret,thresh = cv2.threshold(img,tt,255,0)
contours,hierarchy = cv2.findContours(thresh, 1, 2)
#contours, hierarchy = cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
img = cv2.imread('images_test_rev1/'+str(img_num)+'.jpg')
cv2.drawContours(img,contours,-1,(0,255,0),3)
plt.subplot(1,2,2), plt.imshow(img)
plt.title('Threshold 20%')
plt.axis('off')
#
#cnt = contours[0]
#M = cv2.moments(cnt)
##print M
#cx = int(M['m10']/M['m00'])
#cy = int(M['m01']/M['m00'])
#print cx, cy