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()
dataset/ETHPy150Open mattloper/opendr/slider_demo.py/main/original