为什么我用chumpy和opendr对纹理进行的优化在第一次迭代后停止,因此没有修改textu

2024-09-28 22:25:57 发布

您现在位置:Python中文网/ 问答频道 /正文

我的代码有一些问题,希望能得到帮助:)

我试图优化模型的纹理,使渲染图像看起来像给定的地面真实图像。目前,我正在用opendr演示版“优化”中的代码进行测试,使用chumpy进行优化。
由于某些原因,优化只执行一个步骤,不会更改纹理。有人知道为什么吗?
(为了能够运行代码,我不得不将chumpy中稀疏解算器的默认值(对于狗腿最小化)从'spsolve'更改为'cg')

import numpy as np
import chumpy as ch
import cv2
from opendr.renderer import ColoredRenderer, TexturedRenderer
from opendr.simple import *

import skimage.io as io
from opendr.util_tests import get_earthmesh
import matplotlib.pyplot as plt

def earth_mesh_vis():
    img = io.imread("earth_round.png") # ground truth image
    w, h = 320, 240
    m = get_earthmesh(trans=ch.array([0,0,0]), rotation=ch.zeros(3))
    m.texture_image = ch.array(m.texture_image)
    V = ch.array(m.v)
    A = SphericalHarmonics(vn=VertNormals(v=V, f=m.f),components=[3.,2.,0.,0.,0.,0.,0.,0.,0.], light_color=ch.ones(3))    
    U = ProjectPoints(v=V, f=[w,w], c=[w/2.,h/2.], k=ch.zeros(5), t=ch.zeros(3), rt=ch.zeros(3))
    f = TexturedRenderer(vc=A, camera=U, f=m.f, bgcolor=[0.,0.,0.],                 
                         texture_image=m.texture_image, vt=m.vt, ft=m.ft,           
                         frustum={'width':w, 'height':h, 'near':1,'far':20})
    translation, rotation = ch.array([0,0,8]), ch.zeros(3)                          
    f.v = translation + V.dot(Rodrigues(rotation)) 

    return f, img, m.texture_image, A.components

def visualize():
    f, img, texture, Acomps = earth_mesh_vis()

    E_raw = ch.sum((f - img)**2.)
    #Energy.show_tree()

    free_variables=[texture]
    ch.minimize({'raw': E_raw}, x0=free_variables, method='dogleg') #, options={'delta_0': 10})     

def main():
    visualize()

if __name__ == '__main__':
    main()

优化应该修改模型的纹理,以便在渲染时看起来像地面真实图像。你知道吗


Tags: 代码fromio图像imageimportimgas