def siftManyImg(fn, nbcpu=None,cut=2000): result={} if not nbcpu: nbcpu = multiprocessing.cpu_count() for i in range((len(fn)-1)//nbcpu+1): lf=[fn[0]]+[fn[j+1] for j in range(i*nbcpu,(i+1)*nbcpu) if j<len(fn)-1] print lf ld=[img2array(j)[cut:] for j in lf] dr=feature.sift(*ld,verbose=False,vs_first=True) for k,v in dr.items(): result[(lf[k[0]],lf[k[1]])]=v print(lf[k[0]],lf[k[1]],calcShift(v)) return result
def stitch(*img): if len(img) <= 1: return img d = feature.sift(*img, verbose=True) t0 = time.time() for i in d: print i, "calcShift", calcShift(d[i]) so = setOfOffsets(d) bigShape0 = max([i.shape[0] for i in img]) bigShape1 = max([i.shape[1] for i in img]) minPos = [0, 0] maxPos = list(img[0].shape) shifts = [(0, 0)] for i in range(1, len(img)): bp = so.bestPath(0, i)[-1] print ((0, i), bp) s = bp["shift"] shifts.append(s) if s[0] < minPos[0]: minPos[0] = s[0] if s[1] < minPos[1]: minPos[1] = s[1] if s[0] + img[i].shape[0] > maxPos[0]: maxPos[0] = s[0] + img[i].shape[0] if s[1] + img[i].shape[1] > maxPos[1]: maxPos[1] = s[1] + img[i].shape[1] print minPos, maxPos, shifts print "Alignement:", time.time() - t0 big = numpy.zeros((maxPos[0] - minPos[0] + 1, maxPos[1] - minPos[1] + 1)) print big.shape for i in range(len(img)): s0 = int(round(shifts[i][0] - minPos[0])) s1 = int(round(shifts[i][1] - minPos[1])) print img[i].shape print s0, s0 + img[i].shape[0], s1, s1 + img[i].shape[1] big[s0:s0 + img[i].shape[0], s1:s1 + img[i].shape[1]] = img[i] print big.shape print big return big