예제 #1
0
파일: match.py 프로젝트: znah/yoxel-voxel
    def __init__(self):
        fnames = ['data/g125.jpg', 'data/g126.jpg']
        #fnames = ['vish/IM (25).JPG', 'vish/IM (26).JPG']
        #fnames = ['data/racurs/48.tif', 'data/racurs/49.tif']
        self.frames = frames = [Frame(fn) for fn in fnames]
        H12, p1, p2 = find_homography(frames[0], frames[1])
        np.save('h', H12)

        preview_size = (800, 800)
        extent = (-1000, -1000, 8000, 8000)
        wld2prev = rect2rect_mtx(extent, preview_size)
        
        vis2 = cv2.warpPerspective(frames[1].lods[0], wld2prev, preview_size)
        vis1 = cv2.warpPerspective(frames[0].lods[0], np.dot(wld2prev, H12), preview_size)

        preview = vis1/2 + vis2/2
        cv2.imshow('preview', preview)

        self.shot_idx = 0

        def onmouse(event, x, y, flags, param):
            if event != cv.CV_EVENT_LBUTTONDOWN:
                return
            cx, cy = np.dot((x, y, 1), inv(wld2prev).T)[:2]
            w, h = 800, 800
            wld2view = rect2rect_mtx([cx-w/2, cy-h/2, cx+w/2, cy+h/2], (w, h))

            self.cur_preview = preview.copy()
            view2preview = np.dot(wld2prev, inv(wld2view))
            x0, y0 = np.int32( np.dot((0, 0, 1), view2preview.T)[:2] )
            x1, y1 = np.int32( np.dot((w, h, 1), view2preview.T)[:2] )
            cv2.rectangle(self.cur_preview, (x0, y0), (x1, y1), (255, 255, 255))
            cv2.imshow('preview', self.cur_preview)

            H2 = wld2view
            H1 = np.dot(wld2view, H12)
            vis2 = cv2.warpPerspective(frames[1].lods[0], H2, (w, h))
            vis1 = cv2.warpPerspective(frames[0].lods[0], H1, (w, h))

            self.match_stereo(vis1, vis2, H1, H2)    

        cv.SetMouseCallback('preview', onmouse, None)
예제 #2
0
파일: match.py 프로젝트: znah/yoxel-voxel
        def onmouse(event, x, y, flags, param):
            if event != cv.CV_EVENT_LBUTTONDOWN:
                return
            cx, cy = np.dot((x, y, 1), inv(wld2prev).T)[:2]
            w, h = 800, 800
            wld2view = rect2rect_mtx([cx-w/2, cy-h/2, cx+w/2, cy+h/2], (w, h))

            self.cur_preview = preview.copy()
            view2preview = np.dot(wld2prev, inv(wld2view))
            x0, y0 = np.int32( np.dot((0, 0, 1), view2preview.T)[:2] )
            x1, y1 = np.int32( np.dot((w, h, 1), view2preview.T)[:2] )
            cv2.rectangle(self.cur_preview, (x0, y0), (x1, y1), (255, 255, 255))
            cv2.imshow('preview', self.cur_preview)

            H2 = wld2view
            H1 = np.dot(wld2view, H12)
            vis2 = cv2.warpPerspective(frames[1].lods[0], H2, (w, h))
            vis1 = cv2.warpPerspective(frames[0].lods[0], H1, (w, h))

            self.match_stereo(vis1, vis2, H1, H2)