Skip to main content

g2o: A General Framework for Graph Optimization (Python bindings)

Project description

g2o - General Graph Optimization

Ubicoders g2opy edition

Static Badge Static Badge Static Badge Static Badge

Build and Publishing

For build instructions and maintainer guidelines, please refer to manual.md.

ubuntu install

sudo apt-get install -qq qtdeclarative5-dev qt5-qmake libqglviewer-dev-qt5 libsuitesparse-dev libeigen3-dev -y

For the new conda env

conda install -y -c conda-forge "libstdcxx-ng>=12" "libgcc-ng>=12" libgomp

Then, install this package

pip install ubicoders-g2opy

windows dependencies

just do

pip install ubicoders-g2opy

intro

This project is based on the original g2o maintainer as below.

This porject provide windows and linux off the shelf packge including the .dll and .so files as well as the types of the apis for intellisense.

Otherthan that, same as g2o's pymem branch

Latest Commit base:

  • 70f058fde4516505ecb3b392b25bd66b2f4fdf47 (Sep 21, 2025)

How it works

Built the .whl with the damn .dll and .so files for god xxxxing sake.

The pip packge name is pyg2o. But import with import g2opy as g2o

Intellisense Enhanced

sample1 sample2

Supported Python Versions

  • 3.10 ✅
  • 3.11 ✅
  • 3.12 ✅
  • 3.13 ✅

Supproted Numpy Version

  • numpy 1 ⬜
  • numpy 2 ✅

Tested OS and Python

  • Windows 11 ✅
  • Ubuntu 20 ⬜
  • Ubuntu 22 ⬜
  • Ubuntu 24 ✅
  • Ubuntu 25 ✅

Test the installaton

create below and run

python tester.py

tester.py

import numpy as np
import g2opy as g2o
np.set_printoptions(precision=3)
np.set_printoptions(suppress=True)
from collections import defaultdict

def showCameraPoses(optim, idx, N):
    for i in range(idx, idx + N):
        T = optim.vertex(i).estimate().matrix()
        trans = T[:3, 3]
        print('camera pose at ', i, ': ', trans)

def calcSSE(optim, idx, wPts):
    sse = 0
    N = wPts.shape[0]
    for i in range(idx, idx + N):
        guessedWpt = optim.vertex(i)
        error = guessedWpt.estimate() - wPts[i-idx]
        sse += np.sum(error ** 2)
    return sse

def showWpts(optim, idx, N):
    for i in range(idx, idx + N):
        T = optim.vertex(i).estimate()
        #T = np.round(T, 0)
        print('guessed wPt at ', i-idx, ': ', T)

def main():   
    optimizer = g2o.SparseOptimizer()
    solver = g2o.BlockSolverSE3(g2o.LinearSolverCSparseSE3())
    solver = g2o.OptimizationAlgorithmLevenberg(solver)
    optimizer.set_algorithm(solver)

    f, p = 200, 256
    baseline = 0.3
    K = np.array([[f, 0, p],
                  [0, f, p],
                  [0, 0, 1]])

    wPts = np.array([
        [0, 0, 10],
        [-1, 3, 30],
        [2, 2, 37.2],
    ])

    num_pose = 10
    for i in range(0, int(num_pose/2)):
        pose = g2o.Isometry3d(np.identity(3), [(i-2)*10, 0, 0])
        v_se3 = g2o.VertexSCam()
        v_se3.set_cam(f, f, p, p, baseline)
        v_se3.set_id(i)
        v_se3.set_estimate(pose)
        if i < 2:
            v_se3.set_fixed(True)
        v_se3.set_all() # sets transfrom, projection, dR (angle)
        optimizer.add_vertex(v_se3)

    for i in range(int(num_pose/2), num_pose):
        pose = g2o.Isometry3d(np.identity(3), [0, (i - int(num_pose/2)- 2) * 10, 0])
        v_se3 = g2o.VertexSCam()
        v_se3.set_cam(f, f, p, p, baseline)
        v_se3.set_id(i)
        v_se3.set_estimate(pose)
        v_se3.set_fixed(False)
        v_se3.set_all() # sets transfrom, projection, dR (angle)
        optimizer.add_vertex(v_se3)

    point_id = 0

    for i, wpt in enumerate(wPts):
        guessed_wPt = g2o.VertexPointXYZ()
        guessed_wPt.set_id(num_pose + point_id)
        guessed_wPt.set_marginalized(True)
        guessed_wPt.set_estimate(wpt + np.random.randn(3) )
        optimizer.add_vertex(guessed_wPt)

        for j in range(num_pose):
            z = optimizer.vertex(j).map_point(wpt)
            if i > 1:
                z +=  np.random.randn(3)
            edge = g2o.EdgeXyzVsc()
            edge.set_vertex(0, guessed_wPt)
            edge.set_vertex(1, optimizer.vertex(j))
            edge.set_measurement(z)
            edge.set_information(np.identity(3))
            optimizer.add_edge(edge)

        point_id += 1

    sse0 = calcSSE(optimizer, num_pose, wPts)
    print('\nRMSE (inliers only):')
    print('before optimization:', np.sqrt(sse0 / wPts.shape[0]))
    showCameraPoses(optimizer, 0, num_pose)
    showWpts(optimizer, num_pose, 3)


    print('Performing full BA:')
    optimizer.initialize_optimization()
    optimizer.set_verbose(False)
    optimizer.optimize(100)

    sse1 = calcSSE(optimizer, num_pose, wPts)

    print('\nRMSE (inliers only):')
    print('after  optimization:', np.sqrt(sse1 / wPts.shape[0]))
    showCameraPoses(optimizer, 0, num_pose)
    showWpts(optimizer, num_pose, 3)


if __name__ == '__main__':
    main()

see the orignal readme at https://github.com/RainerKuemmerle/g2o

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

ubicoders_g2opy-2.1.9-cp313-cp313-win_amd64.whl (19.3 MB view details)

Uploaded CPython 3.13Windows x86-64

ubicoders_g2opy-2.1.9-cp313-cp313-manylinux_2_38_x86_64.whl (2.3 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.38+ x86-64

ubicoders_g2opy-2.1.9-cp313-cp313-manylinux_2_34_x86_64.whl (2.3 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

ubicoders_g2opy-2.1.9-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

ubicoders_g2opy-2.1.9-cp312-cp312-win_amd64.whl (19.3 MB view details)

Uploaded CPython 3.12Windows x86-64

ubicoders_g2opy-2.1.9-cp312-cp312-manylinux_2_38_x86_64.whl (2.3 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.38+ x86-64

ubicoders_g2opy-2.1.9-cp312-cp312-manylinux_2_34_x86_64.whl (2.3 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

ubicoders_g2opy-2.1.9-cp311-cp311-win_amd64.whl (19.3 MB view details)

Uploaded CPython 3.11Windows x86-64

ubicoders_g2opy-2.1.9-cp311-cp311-manylinux_2_38_x86_64.whl (2.3 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.38+ x86-64

ubicoders_g2opy-2.1.9-cp311-cp311-manylinux_2_34_x86_64.whl (2.3 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

ubicoders_g2opy-2.1.9-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

ubicoders_g2opy-2.1.9-cp310-cp310-win_amd64.whl (19.3 MB view details)

Uploaded CPython 3.10Windows x86-64

ubicoders_g2opy-2.1.9-cp310-cp310-manylinux_2_38_x86_64.whl (2.3 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.38+ x86-64

ubicoders_g2opy-2.1.9-cp310-cp310-manylinux_2_34_x86_64.whl (2.3 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

ubicoders_g2opy-2.1.9-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

File details

Details for the file ubicoders_g2opy-2.1.9-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for ubicoders_g2opy-2.1.9-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 847c31bc57c29019b0fab4e976bb7920f61d743d35730fa4fffedd645cbac0d5
MD5 f89e3654231db102e42024b745cf2699
BLAKE2b-256 1c767c2d2107b5e753d8f0c1fbc6ce50d43399fe0516d2925a327f631e445d17

See more details on using hashes here.

File details

Details for the file ubicoders_g2opy-2.1.9-cp313-cp313-manylinux_2_38_x86_64.whl.

File metadata

File hashes

Hashes for ubicoders_g2opy-2.1.9-cp313-cp313-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 5da7cbd37d448688d29328d4a7e6c5dce5f2d0de04cf54fce24e3143744cd1f1
MD5 6e4d15cb48259c446d00a3386df40d95
BLAKE2b-256 aa560e73340d964545a9567444a81f4160b3691b2dec9c1e9c7ad05459e70045

See more details on using hashes here.

File details

Details for the file ubicoders_g2opy-2.1.9-cp313-cp313-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for ubicoders_g2opy-2.1.9-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 c92df1f8293e2b4a9e5f7f2e9d3231f2a6620393ddd4966f7ed5dccd6590168c
MD5 19df6f6b77e9840ad8279b9d26ee3ae8
BLAKE2b-256 00cb3b0eb0b5d0bbb46c48cfa5ec77d949227e6cd00ed8acc92024b71242572b

See more details on using hashes here.

File details

Details for the file ubicoders_g2opy-2.1.9-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for ubicoders_g2opy-2.1.9-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 1807c2851242c7cd5009d58954749da17b31ad9b1d6da32a402c6d50c11f62b0
MD5 67fda5527c5f7394f111eabaeb58c590
BLAKE2b-256 3f4fb44d456c44cd904174c28ac48f12675eacdb16b7c7197725c9213d96161d

See more details on using hashes here.

File details

Details for the file ubicoders_g2opy-2.1.9-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for ubicoders_g2opy-2.1.9-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 524abeb2611384bb8f1054ca728d278f52fef05deb104bf645b7d56072ee4256
MD5 9a12138ca0cbcc1f5d71930e430d287a
BLAKE2b-256 e3bafb5f29759b2f9500ccb906706db3aaeeb5e1b9fa31c58d261bc7e20c18dc

See more details on using hashes here.

File details

Details for the file ubicoders_g2opy-2.1.9-cp312-cp312-manylinux_2_38_x86_64.whl.

File metadata

File hashes

Hashes for ubicoders_g2opy-2.1.9-cp312-cp312-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 a27a14080c41c643a448cae3d224b655fca15a11d564349cf4f4903b3e0769ec
MD5 aa5085d4191671a0401187cbd22b19a2
BLAKE2b-256 bf9fccf0c63e68ae7eebe26499bed3bb17d44fd67e1993af94880194b1cc48d8

See more details on using hashes here.

File details

Details for the file ubicoders_g2opy-2.1.9-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for ubicoders_g2opy-2.1.9-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 d3fa8ec064030c45573e200a3bf57b1a29103d42734b78a6274ae773e480e86a
MD5 3b224f8dbc385336ee28db3f7f1ad48e
BLAKE2b-256 da4a78b957c8ea80780411548cbe46f59c0f29d4c03a1d8b5e851d71e913440c

See more details on using hashes here.

File details

Details for the file ubicoders_g2opy-2.1.9-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for ubicoders_g2opy-2.1.9-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 242bd60e7baa9af5e77583c37ba74d750a1c26576a1bdf6bde691232f90ded96
MD5 769a3ae8900772f5d5f5bc47dbff6a93
BLAKE2b-256 8756e540373c4721a7a9475fd5c219ed6e86d2d268a11b90e87c8b4bd72a5f5d

See more details on using hashes here.

File details

Details for the file ubicoders_g2opy-2.1.9-cp311-cp311-manylinux_2_38_x86_64.whl.

File metadata

File hashes

Hashes for ubicoders_g2opy-2.1.9-cp311-cp311-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 73b405a356d8e5c03c8a920ef8e4a32a53f849c7ae24f081d5b8162176cc9593
MD5 96c518a1356ac13ecd0e14cbf995d3a0
BLAKE2b-256 c14b1f89d88d196e852e5ba9e4dd055d83edbeb8606a6f756c6d3c755026da85

See more details on using hashes here.

File details

Details for the file ubicoders_g2opy-2.1.9-cp311-cp311-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for ubicoders_g2opy-2.1.9-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 3b18232a1efbadb2a46ccdd1a909a74de00804563d4f3c0c28ce0b40a7303017
MD5 d89178838c8cb1422dc20ff4b98879b9
BLAKE2b-256 573d2212110f250d12adcb6291a980712847635d304b5eb8da99052cb88ae345

See more details on using hashes here.

File details

Details for the file ubicoders_g2opy-2.1.9-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for ubicoders_g2opy-2.1.9-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 e8dcfaf86bce3f6adacba0207bb01df63a21a1db8ac583c9556443d65df3d847
MD5 5ab39844e0ca22d28efbe2bc41a36974
BLAKE2b-256 5bf1bdebe38a67c80d205870ad78e87cd45fea2440972ce3a90501a99a408b8b

See more details on using hashes here.

File details

Details for the file ubicoders_g2opy-2.1.9-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for ubicoders_g2opy-2.1.9-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 9ca4bdbffbf65526eaa45a5945e0703c8475f3d9464f1be2a4c32fce10ad5cb4
MD5 a1bd67d2bf117917b0264ddb0dc8feb1
BLAKE2b-256 66de61f42dca09edd0efd37ff4440bcbf075f54a4c1faf19c8faaa9b9161b2c2

See more details on using hashes here.

File details

Details for the file ubicoders_g2opy-2.1.9-cp310-cp310-manylinux_2_38_x86_64.whl.

File metadata

File hashes

Hashes for ubicoders_g2opy-2.1.9-cp310-cp310-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 7bb77ebb263060aece9e47dec407e1428ac606e104bbebeabbd4196ae461479e
MD5 8971fb6d64496b3e9db2f2e452e7550b
BLAKE2b-256 02b52c0e2eeefc13d8108cef82b555598de26c2e69a1c9f9e529d42812b45623

See more details on using hashes here.

File details

Details for the file ubicoders_g2opy-2.1.9-cp310-cp310-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for ubicoders_g2opy-2.1.9-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 a7eb56321f38bf50eafc024ed3e9193815c61e0305b9485839aed86d3701d413
MD5 2d22440e7931d2904fbb1391c0807606
BLAKE2b-256 02751e726f4908584b725a1b38f906bef285b0c51fa55bfeb450a70764f0f00a

See more details on using hashes here.

File details

Details for the file ubicoders_g2opy-2.1.9-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for ubicoders_g2opy-2.1.9-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 7cff241b16dc99bbc3005bb3154791f2017b2ed642fc3f0f7403ca494635d7e8
MD5 f7252d853ac67c8dd8ae75854e71c2a3
BLAKE2b-256 d0b67b902bd1e2675803c390a2c3d97a57759dcc8a586c6803eabcdcb6a00cd1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page