#!/usr/bin/env python
import sys #python 2.6 compatability
from id01lib import image
### python >=2.7:
#    parser = argparse.ArgumentParser(description='Process some integers.')
#    parser.add_argument('--crop', 
#                        metavar='px',
#                        type=int, 
#                        nargs="+",
#                        help=('Number of pixels to cut from the edges: '
#                              '(t r b l), (v h) or all'))
#    parser.add_argument('url',
#                        default="http://vidid011.esrf.fr/jpg/1/image.jpg",
#                        type=str,
#                        nargs="?",
#                        help='URL to camera picture to process')
#
#    parser.add_argument('--model',
#                        default="diff",
#                        type=str,
#                        help='Model to calculate contrast. Available: %s'\
#                        %", ".join(_models))
#    
#    args = parser.parse_args()
#    
#    url = args.url
#    crop = args.crop
#    if crop is None:
#        pass
#    elif len(crop)==1:
#        crop = 4*crop
#    elif len(crop)==2:
#        crop = [crop[0], crop[1]]*2
#    elif len(crop)==4:
#        pass
#    else:
#        raise InputError("Invalid argument for --crop")
#    
#    t, r, b, l = (0, 0, 0, 0) if crop is None else crop
###

args = sys.argv[1:]
url = "http://vidid011.esrf.fr/jpg/1/image.jpg"
if len(args)>0:
    if not args[0].startswith("--"):
        url = args[0]


im = image.url2array(url)
height, width = im.shape
#im = im[t:(height-b), l:(width-r)] # cut off text
im = im[60:-70] # cut off text

value = image.com(im)
print("Center of mass in microscope x=%.2f, y=%.2f"%value)


