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

Lazy multiprocess target extraction #730

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

davidtvs
Copy link

@davidtvs davidtvs commented Feb 4, 2025

When using longer datasets or larger image resolutions, kalibr uses a large amount of memory during corner extraction.

That's because all inputs needed for the corner extraction (including all images in the dataset) are duplicated numProcesses times when each process forks.

This PR simplifies the code and uses lazy multiprocessing to feed inputs to the process pool only when needed (one-by-one).
See a comparison below of the memory consumption before and after this PR with a dataset of 1920x1080 images:

ram

Peak memory usage is reduced by more than 50%.

CPU usage is more or less the same - seems less "spiky" now:

cpu

I've also ran the code in the PR on the sample dataset to make sure there's no unintended degradation:

Command:

rosrun kalibr kalibr_calibrate_cameras \
 	--target april_6x6.yaml \
 	--models pinhole-radtan pinhole-radtan \
 	--topics /cam0/image_raw /cam1/image_raw \
 	--bag cam_april.bag \
 	--bag-freq 10.0

Camera chain before this PR:

cam0:
  cam_overlaps: [1]
  camera_model: pinhole
  distortion_coeffs: [-0.2894411946323578, 0.07962117717814395, 0.00019362566733012107, 2.0633489114325153e-05]
  distortion_model: radtan
  intrinsics: [459.16620162518655, 457.8283425910929, 366.56421591367956, 248.93486745674633]
  resolution: [752, 480]
  rostopic: /cam0/image_raw
cam1:
  T_cn_cnm1:
  - [0.9999975833780851, 0.0021876991183658436, 0.00021727987704355133, -0.10996992818618531]
  - [-0.0021905046383791527, 0.9999012408498518, 0.01388201124994388, 0.0003967599845687264]
  - [-0.0001868887548949044, -0.013882453654949846, 0.9999036166316727, -0.0006390066744876479]
  - [0.0, 0.0, 0.0, 1.0]
  cam_overlaps: [0]
  camera_model: pinhole
  distortion_coeffs: [-0.28702698964616846, 0.0774641314753513, -9.0868908124502e-05, 1.191942692999466e-05]
  distortion_model: radtan
  intrinsics: [457.8635851933246, 456.4589896582416, 379.35599660413214, 255.87526793697964]
  resolution: [752, 480]
  rostopic: /cam1/image_raw

Camera chain after this PR:

cam0:
  cam_overlaps: [1]
  camera_model: pinhole
  distortion_coeffs: [-0.28646742048247464, 0.07664440221166424, 0.00037989530732547436, -4.092622872711382e-06]
  distortion_model: radtan
  intrinsics: [459.2480732747205, 457.9630133876875, 366.85529050387214, 248.14762195518594]
  resolution: [752, 480]
  rostopic: /cam0/image_raw
cam1:
  T_cn_cnm1:
  - [0.9999972253522178, 0.0022194793620354293, 0.0007894296777357621, -0.10995275408589618]
  - [-0.002230016923524006, 0.9999049229804217, 0.013607792768362957, 0.0004232690628729674]
  - [-0.0007591524059026039, -0.01360951545307229, 0.999907098072989, -0.0005893580755146163]
  - [0.0, 0.0, 0.0, 1.0]
  cam_overlaps: [0]
  camera_model: pinhole
  distortion_coeffs: [-0.2861004711786593, 0.07657158365440236, 5.9945048063776784e-05, -7.586504253593691e-06]
  distortion_model: radtan
  intrinsics: [458.1502957674771, 456.7543594159104, 379.3836585373581, 255.19745143306127]
  resolution: [752, 480]
  rostopic: /cam1/image_raw

There's small difference but I think that's just the run-to-run variance.

Maybe this addresses #22, hard to say since that issue is very old.

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

Successfully merging this pull request may close these issues.

1 participant