Esempio n. 1
0
    def compute_dr_wrt(self, wrt):
        result = super(TexturedRenderer, self).compute_dr_wrt(wrt)

        if wrt is self.vc:
            cim = self.draw_color_image(with_vertex_colors=False).ravel()
            cim = sp.spdiags(row(cim), [0], cim.size, cim.size)
            result = cim.dot(result)
        elif wrt is self.texture_image:
            IS = np.nonzero(self.visibility_image.ravel() != 4294967295)[0]
            JS = self.texcoord_image_quantized.ravel()[IS]

            clr_im = self.draw_color_image(with_vertex_colors=True,
                                           with_texture_on=False)

            if False:
                cv2.imshow('clr_im', clr_im)
                cv2.imshow('texmap', self.texture_image.r)
                cv2.waitKey(1)

            r = clr_im[:, :, 0].ravel()[IS]
            g = clr_im[:, :, 1].ravel()[IS]
            b = clr_im[:, :, 2].ravel()[IS]
            data = np.concatenate((r, g, b))

            IS = np.concatenate((IS * 3, IS * 3 + 1, IS * 3 + 2))
            JS = np.concatenate((JS * 3, JS * 3 + 1, JS * 3 + 2))

            return sp.csc_matrix((data, (IS, JS)),
                                 shape=(self.r.size, wrt.r.size))

        return result
Esempio n. 2
0
    def compute_dr_wrt(self, wrt):
        result = super(TexturedRenderer, self).compute_dr_wrt(wrt)
        
        if wrt is self.vc:
            cim = self.draw_color_image(with_vertex_colors=False).ravel()
            cim = sp.spdiags(row(cim), [0], cim.size, cim.size)
            result = cim.dot(result)
        elif wrt is self.texture_image:
            IS = np.nonzero(self.visibility_image.ravel() != 4294967295)[0]
            JS = self.texcoord_image_quantized.ravel()[IS]

            clr_im = self.draw_color_image(with_vertex_colors=True, with_texture_on=False)

            if False:
                cv2.imshow('clr_im', clr_im)
                cv2.imshow('texmap', self.texture_image.r)
                cv2.waitKey(1)

            r = clr_im[:,:,0].ravel()[IS]
            g = clr_im[:,:,1].ravel()[IS]
            b = clr_im[:,:,2].ravel()[IS]
            data = np.concatenate((r,g,b))

            IS = np.concatenate((IS*3, IS*3+1, IS*3+2))
            JS = np.concatenate((JS*3, JS*3+1, JS*3+2))


            return sp.csc_matrix((data, (IS, JS)), shape=(self.r.size, wrt.r.size))

            
        return result
Esempio n. 3
0
def main():
    # Create a black image, a window
    img = np.zeros((300,512,3), np.uint8)
    cv2.namedWindow('image')
    cv2.namedWindow('derivatives')

    rn = get_renderer()

    tracked = {
        'sph0': rn.vc.components[0],
        'sph1': rn.vc.components[1],
        'sph2': rn.vc.components[2],
        'sph3': rn.vc.components[3],
        'k0': rn.camera.k[0],
        'k1': rn.camera.k[1],
        'k2': rn.camera.k[2]
    }

    cnst = 1000
    for k in sorted(tracked.keys()):
        v = tracked[k]
        cv2.createTrackbar(k, 'image', 0,cnst, nothing)

    old_tracked = tracked
    cv2.setTrackbarPos('sph0', 'image', 800)
    while(1):
        cv2.imshow('image',rn.r)
        k = cv2.waitKey(1) & 0xFF
        if k == 27:
            break
    
        for k, v in tracked.items():
            v[:] = np.array(cv2.getTrackbarPos(k, 'image')).astype(np.float32)*4/cnst
            if tracked[k].r[0] != old_tracked[k].r[0]:
                drim = rn.dr_wrt(v).reshape(rn.shape)
                mn = np.mean(drim)
                drim /= np.max(np.abs(drim.ravel()))*2.
                drim += .5
                # drim = drim - np.min(drim)
                # drim = drim / np.max(drim)
                cv2.imshow('derivatives', drim)
               
        cv2.waitKey(1)
        old_tracked = deepcopy(tracked)
    # while True: 
    #     for k_change in sorted(tracked.keys()):
    #         if k_change == 'sph0':
    #             continue
    #         for t in np.arange(0, np.pi, .05):
    #             cv2.setTrackbarPos(k_change, 'image', int(np.sin(t)*1000))
    #             cv2.imshow('image',rn.r)
    #             k = cv2.waitKey(1) & 0xFF
    #             if k == 27:
    #                 break
    # 
    #             for k, v in tracked.items():
    #                 v[:] = np.array(cv2.getTrackbarPos(k, 'image')).astype(np.float32)*4/cnst
    #                 if tracked[k].r[0] != old_tracked[k].r[0]:
    #                     drim = rn.dr_wrt(v).reshape(rn.shape)
    #                     mn = np.mean(drim)
    #                     drim /= np.max(np.abs(drim.ravel()))*2.
    #                     drim += .5
    #                     # drim = drim - np.min(drim)
    #                     # drim = drim / np.max(drim)
    #                     cv2.imshow('derivatives', drim)
    #         
    #         
    #             print rn.vc.components
    # 
    #             cv2.waitKey(1)
    #             old_tracked = deepcopy(tracked)

    cv2.destroyAllWindows()
Esempio n. 4
0
def main():
    # Create a black image, a window
    img = np.zeros((300, 512, 3), np.uint8)
    cv2.namedWindow('image')
    cv2.namedWindow('derivatives')

    rn = get_renderer()

    tracked = {
        'sph0': rn.vc.components[0],
        'sph1': rn.vc.components[1],
        'sph2': rn.vc.components[2],
        'sph3': rn.vc.components[3],
        'k0': rn.camera.k[0],
        'k1': rn.camera.k[1],
        'k2': rn.camera.k[2]
    }

    cnst = 1000
    for k in sorted(tracked.keys()):
        v = tracked[k]
        cv2.createTrackbar(k, 'image', 0, cnst, nothing)

    old_tracked = tracked
    cv2.setTrackbarPos('sph0', 'image', 800)
    while (1):
        cv2.imshow('image', rn.r)
        k = cv2.waitKey(1) & 0xFF
        if k == 27:
            break

        for k, v in tracked.items():
            v[:] = np.array(cv2.getTrackbarPos(k, 'image')).astype(
                np.float32) * 4 / cnst
            if tracked[k].r[0] != old_tracked[k].r[0]:
                drim = rn.dr_wrt(v).reshape(rn.shape)
                mn = np.mean(drim)
                drim /= np.max(np.abs(drim.ravel())) * 2.
                drim += .5
                # drim = drim - np.min(drim)
                # drim = drim / np.max(drim)
                cv2.imshow('derivatives', drim)

        cv2.waitKey(1)
        old_tracked = deepcopy(tracked)
    # while True:
    #     for k_change in sorted(tracked.keys()):
    #         if k_change == 'sph0':
    #             continue
    #         for t in np.arange(0, np.pi, .05):
    #             cv2.setTrackbarPos(k_change, 'image', int(np.sin(t)*1000))
    #             cv2.imshow('image',rn.r)
    #             k = cv2.waitKey(1) & 0xFF
    #             if k == 27:
    #                 break
    #
    #             for k, v in tracked.items():
    #                 v[:] = np.array(cv2.getTrackbarPos(k, 'image')).astype(np.float32)*4/cnst
    #                 if tracked[k].r[0] != old_tracked[k].r[0]:
    #                     drim = rn.dr_wrt(v).reshape(rn.shape)
    #                     mn = np.mean(drim)
    #                     drim /= np.max(np.abs(drim.ravel()))*2.
    #                     drim += .5
    #                     # drim = drim - np.min(drim)
    #                     # drim = drim / np.max(drim)
    #                     cv2.imshow('derivatives', drim)
    #
    #
    #             print rn.vc.components
    #
    #             cv2.waitKey(1)
    #             old_tracked = deepcopy(tracked)

    cv2.destroyAllWindows()