GithubHelp home page GithubHelp logo

lambdaloop / aniposelib Goto Github PK

View Code? Open in Web Editor NEW
67.0 67.0 33.0 155 KB

๐Ÿ“ท ๐ŸŠ An easy-to-use library for calibrating cameras in python

Home Page: https://anipose.readthedocs.io

License: BSD 2-Clause "Simplified" License

Python 99.89% Shell 0.11%

aniposelib's People

Contributors

abitrolly avatar jonmatthis avatar julianpitney avatar lambdaloop avatar philipqueen avatar sjoerdbruijn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

aniposelib's Issues

Numba decorator error

I have numba 0.52.0 installed, python3.7.

  File "/home/cosc/guest/owb14/sync/aniposelib/aniposelib/cameras.py", line 616, in CameraGroup
    @jit(nopython=True, parallel=True, forceobj=True)
  File "/home/cosc/guest/owb14/miniconda3/lib/python3.7/site-packages/numba/core/decorators.py", line 150, in jit
    raise ValueError("Only one of 'nopython' or 'forceobj' can be True.")

win10 -- ctrl-c causes error "forrtl: error (200): program aborting due to control-C event"

Task: I am trying to open the camera, detect the charuco points, and display it using opencv. In a simple main loop.

When I press the stop button in pycharm (which i assume is ctrl-c), I ran into this error message --

forrtl: error (200): program aborting due to control-C event
Image              PC                Routine            Line        Source             
libifcoremd.dll    00007FF8BE5D3B58  Unknown               Unknown  Unknown
KERNELBASE.dll     00007FF91B3B4F93  Unknown               Unknown  Unknown
KERNEL32.DLL       00007FF91C337974  Unknown               Unknown  Unknown
ntdll.dll          00007FF91E3FA2F1  Unknown               Unknown  Unknown

-- at this point, pycharm is unable to kill the application. The only way to proceed is to kill and restart pycharm.

The culprit is narrowed down to the import of CharucoBoard class:

import time

from aniposelib.boards import CharucoBoard  # <-- this import, even if the code does not use it, causes the error message.
from bin.api.SynchronisedCameraCapture import SynchronisedCameraCapture
import cv2

opencv-python dependency issues

Hey, thanks for this package! I think there's a problem in the way opencv-python dependencies are listed though?

My understanding is that one is only supposed to have a single opencv installation in an environment, but you have both opencv-python and opencv-contrib-python. See here for the error I was getting and resolution: https://stackoverflow.com/questions/45972357/python-opencv-aruco-no-module-named-cv2-aruco

Basically, shouldn't the dependency for the package just be opencv-contrib-python~=3.4, so that you don't have conflicting namespaces for cv2 and cause issues importing aruco?

Calibration on Colab takes 30+ minutes instead of 15 as in docs

image

I can also see this warning.

/usr/local/lib/python3.7/dist-packages/numba/np/ufunc/parallel.py:355: NumbaWarning: The TBB threading layer requires TBB version 2019.5 or later i.e., TBB_INTERFACE_VERSION >= 11005. Found TBB_INTERFACE_VERSION = 9107. The TBB threading layer is disabled.
warnings.warn(problem)

I will try to install this tbb and see if anything improves.

The notebook link is https://colab.research.google.com/drive/1N53E-qFSkOBcjB8IvXhBCmJPcisQmuxV?usp=sharing but its contents will most likely change.

Calibration error, replication instability

When I run the example data from the tutorial multiple times, I get extremely varied results in the pixel reprojection error -- from 1 to 10000. I ran the calibration 6 times (restarting the kernel in between each) and only got a good result 1 time; I got an error of 125, then 1.8, then 20084, then 1064...

I created a fresh installation of aniposelib inside its own conda environment, hoping to fix this problem but that didn't help.

I did not have this issue when I first tried using aniposelib back in May, although I wasn't intentionally trying to replicate results at that point. The only thing that has changed since then is some Windows updates; could that cause this problem? I'm running Windows 10 1909 18363.959

Is anyone else having this problem?

"Residuals are not finite" error with anipose triangulate

Good afternoon,

I'm working with a 4 camera setup to record mouse movements in relation to a neurological disorder.

I'm at the triangulation step of the anipose workflow, after getting through the others steps without errors.

The error is as follows:

/home/minassian/Documents/glove-anipose/2023-07-16/pose-3d/2023-07-16-vid1.csv
100%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ| 6888/6888 [00:01<00:00, 5993.77it/s]
/home/minassian/miniconda3/envs/glove-anipose/lib/python3.7/site-packages/aniposelib/cameras.py:1023: RuntimeWarning: divide by zero encountered in double_scalars
default_smooth = 1.0/np.mean(np.abs(np.diff(p3ds_med, axis=0)))
/home/minassian/miniconda3/envs/glove-anipose/lib/python3.7/site-packages/scipy/optimize/_lsq/least_squares.py:815: RuntimeWarning: invalid value encountered in multiply
return np.atleast_1d(fun(x, *args, **kwargs))
Traceback (most recent call last):
File "/home/minassian/miniconda3/envs/glove-anipose/lib/python3.7/site-packages/anipose/triangulate.py", line 346, in process_session
fname_dict, output_fname)
File "/home/minassian/miniconda3/envs/glove-anipose/lib/python3.7/site-packages/anipose/triangulate.py", line 222, in triangulate
verbose=True)
File "/home/minassian/miniconda3/envs/glove-anipose/lib/python3.7/site-packages/aniposelib/cameras.py", line 1050, in optim_points
n_deriv_smooth))
File "/home/minassian/miniconda3/envs/glove-anipose/lib/python3.7/site-packages/scipy/optimize/_lsq/least_squares.py", line 827, in least_squares
raise ValueError("Residuals are not finite in the initial point.")
ValueError: Residuals are not finite in the initial point.

From what I can find, the "residuals are not finite" error has to do with taking square roots of negative numbers.

I can't tell where this is coming from and how best to fix it.

I'm working on Ubuntu 22.04 LTS, Python 3.7.16, numba 0.54.1

Thanks for any help!

Calibration detects 0 boards

Hi,

I have a 5-camera DLC project with a separate network trained for each camera so I came here to calibrate and triangulate them. I am running aniposelib 0.3.9 on Windows 10 as shown in the Aniposelib Tutorial:

`vidnames = [['cam1-14-59-59-calibration.avi'],
['cam2-14-59-59-calibration.avi'],
['cam3-14-59-59-calibration.avi'],
['cam4-14-59-59-calibration.avi'],
['cam5-14-59-59-calibration.avi']]

cam_names = ['1', '2', '3', '4', '5']

n_cams = 5

board = Checkerboard(7, 9, square_length = 1)

cgroup = CameraGroup.from_names(cam_names)

cgroup.calibrate_videos(vidnames, board)

cgroup.dump('calibration.toml')`

Each video appears to be fully processed, but the output is "0 boards detected" for each video. This is not a very helpful error... Am I calling the function incorrectly? Are my videos bad? (I've tried .mp4's as well with the same result). Is there a way that I can provide some intermediate supervision? The DLC 3D calibration process, for instance, seems much more involved, but only supports 2 cameras. Attached are a few of the calibration videos.

Thanks!
Maria

cam3-calibration.zip

cam2-calibration.zip

cam1-calibration.zip

charuco board 0boards detected

Hi, thanks for your great job. I followed the steps in aniposelib tutorial but got error: 0 boards detected. Could help me with that? Thanks!

My code:

from aniposelib.cameras import CameraGroup


vidnames = [['output0.avi'],
            ['output1.avi'],
            ['output2.avi']]

cam_names = ['A', 'B', 'C']

n_cams = len(vidnames)

board = CharucoBoard(7, 10,
                     square_length=25, # here, in mm but any unit works
                     marker_length=18.75,
                     marker_bits=4, dict_size=50)

cgroup = CameraGroup.from_names(cam_names, fisheye=False)
cgroup.calibrate_videos(vidnames, board)
cgroup.dump('calibration.toml')

Generate board and print it in A4 format:

from aniposelib.boards import CharucoBoard

board1 = CharucoBoard(7, 10,
                     square_length=25, # here, in mm but any unit works
                     marker_length=18.75,
                     marker_bits=4, dict_size=50)

img = board1.draw((2550,3300))
cv2.imwrite("img.jpg", img)

image

Sincerely

cv2.initCameraMatrix2D initialisation

Something seems to be wrong with the parameters passed into cv2.initCameraMatrix2D... I suspect something not right with board.get_all_calibration_points

This is the output of cv2.calibrateCamera (focal length ~2250)

 [[2.24678790e+03 0.00000000e+00 1.02546166e+03]
 [0.00000000e+00 2.24602727e+03 7.64098182e+02]
 [0.00000000e+00 0.00000000e+00 1.00000000e+00]]

Own implementation passing the same raw points into cv2.initCameraMatrix2D (focal length ~2250):

[[2.24765913e+03 0.00000000e+00 9.99500000e+02]
 [0.00000000e+00 2.24765913e+03 7.49500000e+02]
 [0.00000000e+00 0.00000000e+00 1.00000000e+00]]

aniposelib initialisation from cv2.initCameraMatrix2D after board.get_all_calibration_points(rows)
(focal length ~121!!!)

[[121.30633838   0.         999.5       ]
 [  0.         121.30633838 749.5       ]
 [  0.           0.           1.        ]]

relative 3D coordinates

Hi,

In the "Visualization" part of aniposelib tutorial, it says "The code shown below extracts and plots the x, y, and z positions of joint 0, which corresponds to the base of the hand (see Figure 1)." I wonder what the "base of the hand" here refers to?

Thanks

setting `verbose=True` in `cgroup.calibrate_videos` spawns a Thread in `boards.detect_video` that doesn't terminate properly

This caused an issue for me when I was trying to put cgroup.calibrate_videos in a try: except: block to try to iteratively re-run Anipose with different sections of input videos whenever Anipose failed to produce a calibration.

As far as I can tell, this un-closed thread would sometimes cause one iteration to to jump out of the try-except block with another iteration was still trying to run.

The thread seems to be spawned at line 319 of boards.py (it = trange(length, ncols=70))

Triangulation slower with jit decorator

I noticed that commenting out the "jit" decorator that applies to the "triangulate_simple" function (decorator on line 20, function definition on line 21 of cameras.py) substantially improves the runtime of the code.
For 12 tracked features in a 5 minute video sampled at 100Hz, the runtime was ~6 minutes with the code as is and only ~10s with the decorator commented out.

It might be worth your exploring whether my experience is generalizable, in which case maybe it's better to skip the jit decorators or at least make it clear in what cases the decorator helps vs. hurts!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.