Hello all, just joined (thanks Olivier) and wanted to share a little bit of code with you in case you thought it useful. I got a canon 7d little while ago and noticed that the builtin screen indicates with red boxes which focus points were used. I thought that was interesting so I went trudging through the exif info to see if I could generate images showing the focus points as well. this is what i ended up with. grey boxes showing all focus points. white for subset which were active when the shot was composed, and red for the ones that were used to take the shot. please excuse the code duplication, i haven't cleaned up the code yet to deal with dcraw rotating the image for me. You can just ignore the clauses for rotatepic==true.
I was thinking that perhaps these values (focuspointwidth, focuspointheight, focuspointxpos, focuspointypos, activeafpoints, afpoints) could be exposed more directly. interested in your thoughts. Jason class cr2imagewriter(): def __init__(self, imagedata, metadata, filename): # for exifdatum in metadata.exif_keys: # print 'exif key %s val %s' % (exifdatum, metadata[exifdatum].human_value) # print '11','#' * 80,'\n' try: exif_dim = metadata['Exif.Canon.AFInfo'].value[4:6] focuspointwidth = metadata['Exif.Canon.AFInfo'].value[8:8+19] focuspointheight = metadata['Exif.Canon.AFInfo'].value[27:27+19] focuspointxpos = [unpack('=h', pack('=H', i & 0xffff))[0] for i in metadata['Exif.Canon.AFInfo'].value[46:46+19]] focuspointypos = [unpack('=h', pack('=H', i & 0xffff))[0] for i in metadata['Exif.Canon.AFInfo'].value[65:65+19]] activeafpoints = [unpack('=h', pack('=H', i & 0xffff))[0] for i in metadata['Exif.Canon.AFInfo'].value[84:85]] afpoints = [unpack('=h', pack('=H', i & 0xffff))[0] for i in metadata['Exif.Canon.AFInfo'].value[86:87]] draw = ImageDraw.Draw(imagedata) (xsize, ysize) = imagedata.size print 'my size %dx%d' % (xsize, ysize) rotatepic = False if (ysize > xsize): # dcraw automatically rotates the image it feeds me # my heuristic for determining this is to check y size vs xsize # and then munge my x and y coordinates to scribble # sideways when i write my rectangles rotatepic = True widthadjust = float(exif_dim[0])/float(ysize) heightadjust = float(exif_dim[1])/float(xsize) else: widthadjust = float(exif_dim[0])/float(xsize) heightadjust = float(exif_dim[1])/float(ysize) print 'my size2 %dx%d' % (xsize, ysize) print 'exif_dim %dx%d' % (exif_dim[0], exif_dim[1]) print 'width ratio is %f' % widthadjust print 'height ratio is %f' % heightadjust for i in range(0, len(focuspointwidth)): if 1 == activeafpoints[0]>>i&1: color = ImageColor.getrgb("red") else: if 1 == afpoints[0]>>i&1: color = ImageColor.getrgb("white") else: color = ImageColor.getrgb("grey") if rotatepic: draw.rectangle((-((float(focuspointypos[i])/float(heightadjust)))+float(xsize)/2.0, -(float(focuspointxpos[i])/float(widthadjust))+float(ysize)/2.0, -((float(focuspointypos[i])/float(heightadjust))+(float(focuspointheight[i])/float(heightadjust)))+float(xsize)/2.0, -(float(focuspointxpos[i])/float(widthadjust))+(float(focuspointwidth[i])/float(widthadjust))+float(ysize)/2.0), fill=None, outline=color) else: draw.rectangle(((float(focuspointxpos[i])/float(widthadjust))+float(xsize)/2.0, ((-float(focuspointypos[i])/float(heightadjust)))+float(ysize)/2.0, (float(focuspointxpos[i])/float(widthadjust))+(float(focuspointwidth[i])/float(widthadjust))+float(xsize)/2.0, (-(float(focuspointypos[i])/float(heightadjust))+(float(focuspointheight[i])/float(heightadjust)))+float(ysize)/2.0), fill=None, outline=color) except: raise imagedata.save(file(filename, "w"), 'JPEG', quality=85, optimize=True) where, earlier in the code: metadata = pyexiv2.ImageMetadata(pic) metadata.read() and dcraw = subprocess.Popen(['dcraw', '-b', '2.5', '-c', '-w', '-W', '-v', '-q', '3', pic], stdout=PIPE, universal_newlines=False) dcrawdata = dcraw.communicate()[0] print 'name ', pic print 'dcraw data %d' % len(dcrawdata) ImageFile.MAXBLOCK = 75000000 # default is 64k imagedata = Image.open(cStringIO.StringIO(dcrawdata))
_______________________________________________ Mailing list: https://launchpad.net/~pyexiv2-developers Post to : pyexiv2-developers@lists.launchpad.net Unsubscribe : https://launchpad.net/~pyexiv2-developers More help : https://help.launchpad.net/ListHelp