Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segmentation Fault Examples #81

Open
233Xiaowu opened this issue Aug 8, 2024 · 1 comment
Open

Segmentation Fault Examples #81

233Xiaowu opened this issue Aug 8, 2024 · 1 comment

Comments

@233Xiaowu
Copy link

ubuntu:20.04
python:3.8

Mine is currently running
super().optimize(max_iterations)

The error is as follows
139 (interrupted by signal 11:SIGSEGV)

I would like to be able to implement global optimization under image stitching with g2o code
My related code is as follows

class BundleAdjustment(g2o.SparseOptimizer):
def init(self, ):
super().init()
solver = g2o.BlockSolverSE2(g2o.LinearSolverCholmodSE2())
solver = g2o.OptimizationAlgorithmLevenberg(solver)
super().set_algorithm(solver)
super().set_verbose(True) # 打印信息

def optimize(self, max_iterations=10):

    super().initialize_optimization()
    super().optimize(max_iterations)

def add_pose(self, pose_id, pose,fixed=False):

    translation = pose[:2, 2]
    rotation_matrix = pose[:2, :2]
    theta = np.arctan2(rotation_matrix[1, 0], rotation_matrix[0, 0])

    # 转化为SE2
    se2_pose = g2o.SE2(translation[0], translation[1], theta)

    v_se2 = g2o.VertexSE2()
    v_se2.set_id(pose_id)   # internal id
    v_se2.set_estimate(se2_pose)
    if pose_id == 0:
        v_se2.set_fixed(True)
        # print(f"Keyframe {vertex_id} set as fixed.")
    else:
        v_se2.set_fixed(False)
    super().add_vertex(v_se2)

def add_point(self, point_id, point, fixed=False, marginalized=True):

    keypoint = point
    x, y = keypoint.pt
    vertex_p = g2o.VertexPointXY()
    vertex_p.set_id(point_id)
    Point_estimate = np.array([x, y])
    vertex_p.set_estimate(Point_estimate)
    vertex_p.set_marginalized(True)
    vertex_p.set_fixed(False)
    super().add_vertex(vertex_p)

def add_edge(self, point_id, pose_id,measurement,information=np.identity(2),
        robust_kernel=g2o.RobustKernelHuber(np.sqrt(5.991))):   # 95% CI

    edge = g2o.EdgePointXY()
    edge.set_vertex(0, self.vertex(int(point_id)))
    edge.set_vertex(1, self.vertex(pose_id))

    measurement_edge=measurement.pt
    edge.set_measurement(measurement_edge)   # projection
    edge.set_information(information)

    if robust_kernel is not None:
        edge.set_robust_kernel(robust_kernel)
    # edge.set_parameter_id(0, 0)
    super().add_edge(edge)

def get_pose(self, pose_id):
    return self.vertex(pose_id).estimate()

def get_point(self, point_id):
    return self.vertex(point_id).estimate()

class MapMerge():
def init(self):
self.ba = BundleAdjustment()

I reinstalled g2opy with reference 1 and , but it still reports the same error
Any suggestions?

@233Xiaowu
Copy link
Author

if pose_id == 0:
v_se2.set_fixed(True)
# print(f"Keyframe {vertex_id} set as fixed.")
else:
v_se2.set_fixed(False)

I changed the above code to

v_se2.set_fixed(False)

I'm not sure why the program doesn't report errors this way, I haven't started looking at the results yet, but shouldn't the first few keyframes be fixed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant