Skip to content

Commit

Permalink
Moved capture_sequence.py to marimapper.py
Browse files Browse the repository at this point in the history
removed reconstructor entirely
fixed remesher, this needs to be moved into marimapper
fixed view_2d_map
  • Loading branch information
TheMariday committed Jun 13, 2024
1 parent d8a9fc5 commit 82ce3b7
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 111 deletions.
46 changes: 14 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@

This is a selection of tools to map LEDs into 2D and 3D space using only your webcam!

> [!CAUTION]
> This tool is currently undergoing a rework (10/06/2024) and therefore some features such as rendering strips and cameras may not be available

> [!TIP]
> All scripts can be run with the `--help` argument to list optional parameters such as resolution and exposure.
Expand Down Expand Up @@ -75,8 +71,8 @@ class Backend:
pass

```

You can test your backend with `python scripts/check_backend.py`
> [!TIP]
> You can test your backend with `python scripts/check_backend.py`
MariMapper also support the following pre-made backends. This can be selected in the following steps using the `--backend`
argument.
Expand All @@ -87,32 +83,29 @@ argument.
- [ ] [LCM](https://lcm-proj.github.io/lcm/)


## Step 3: Capture a 2D map
## Step 3: Start scanning!

Set up your LEDs in front of your camera and
run `python scripts/capture_sequence.py my_scan --backend fadecandy`

Change `--backend` to whatever backend you're using
[It's time to thunderize!](https://youtu.be/-5KJiHc3Nuc?t=121)

This will produce a timestamped CSV file in the `my_scan` folder with led index, u and v values.
run `python marimapper.py my_scan --backend fadecandy`
Change `fadecandy` to whatever backend you're using and `my_scan` to whatever you want to call your scan

Run `python scripts/visualise.py <filename>` to visualise 2D or 3D map files.
Set up your LEDs so most of them are in view and when you're ready, type `y` when prompted with `Start scan? [y/n]`

## Step 4: Construct a 3D map
This will turn each LED on and off in turn, do not move the camera or leds during capture!

[It's time to thunderize!](https://youtu.be/-5KJiHc3Nuc?t=121)
If you just want a 2D map, this is where you can stop!
Run `python scripts/view_2d_map.py my_scan/...` to visualise your map replacing `...` with the map name.

To create a 3D map, run `capture_sequence` multiple times from different views of your LEDs,
this can either be done by moving your webcam around your LEDs or rotating your LEDs.
To capture a 3D map, rotate your leds or move your webcam to a new position

> [!TIP]
> You can move your webcam to wherever you like as long as some of your leds are mostly in view
> As long as some of your leds are mostly in view, you can move your webcam to wherever you like!
> Try and get at least 3 views between 6° - 20° apart
Once you have a selection of 2D maps captured with the `capture_sequence.py` script,
run `python scripts/reconstruct.py my_scan`
Once you have at least 2 2d maps, a new window will appear showing the reconstructed 3D positions of your LEDs.

This may take a while, however once complete will generate `reconstruction.csv` in the `my_scan` folder.
If it doesn't look quite right, add some more scans!

Here is an example reconstruction of Highbeam's body LEDs

Expand All @@ -129,17 +122,6 @@ Here is an example reconstruction of Highbeam's body LEDs
- Use `1`, `2` & `3` keys to change colour scheme
</details>


## Step 5: Construct a mesh (optional)

If you have a high enough density 3d map, you can use the remesh tool to create a 3D mesh based on your leds!

Run `python scripts/remesh.py reconstruction.csv my_mesh.ply`

This will generate a ply file which you can open and look at with your eyes

![alt text](docs/images/remesh_with_normals.png "Highbeam LED mesh reconstruction")

# Feedback

I would really love to hear what you think and if you have any bugs or improvements, please raise them here or drop me a
Expand Down
16 changes: 10 additions & 6 deletions lib/remesher.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,16 @@ def remesh(led_map, mesh_detail=8):

pcd = open3d.geometry.PointCloud()

pcd.points = open3d.utility.Vector3dVector(
[led_map[led_id]["pos"] for led_id in led_map.data]
)
pcd.normals = open3d.utility.Vector3dVector(
[led_map[led_id]["normal"] for led_id in led_map.data]
)
xyz = []
normals = []
for led_id in led_map.keys():
xyz.append(led_map[led_id]["pos"])
normals.append(
led_map[led_id]["normal"] / np.linalg.norm(led_map[led_id]["normal"])
)

pcd.points = open3d.utility.Vector3dVector(xyz)
pcd.normals = open3d.utility.Vector3dVector(normals)

with open3d.utility.VerbosityContextManager(
open3d.utility.VerbosityLevel.Debug
Expand Down
3 changes: 0 additions & 3 deletions scripts/capture_sequence.py → marimapper.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import argparse
import os
import sys
import time
from tqdm import tqdm
from pathlib import Path

sys.path.append("./")

from lib.reconstructor import Reconstructor
from lib import utils
from lib.utils import cprint, Col, get_user_confirmation
Expand Down
65 changes: 0 additions & 65 deletions scripts/reconstruct.py

This file was deleted.

6 changes: 2 additions & 4 deletions scripts/remesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
sys.path.append("./")

from lib.remesher import remesh, save_mesh
from lib.visualize_model import render_3d_model
from lib.utils import cprint, Col
from lib.led_map_3d import LEDMap3D

Expand All @@ -15,7 +14,7 @@
parser.add_argument(
"map_filename",
type=str,
help="The CSV 3D map file generated by reconstruct.py",
help="The CSV 3D map file generated by marimapper.py",
)

parser.add_argument(
Expand All @@ -34,11 +33,10 @@

led_map = LEDMap3D(args.map_filename)

if led_map is None:
if not led_map.valid:
quit()

mesh = remesh(led_map, args.detail)

if not save_mesh(mesh, args.mesh_filename):
cprint(f"Failed to save mesh to {args.mesh_filename}", format=Col.FAIL)
render_3d_model(led_map, mesh=mesh)
4 changes: 3 additions & 1 deletion scripts/view_2d_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ def render_2d_model(led_map):

for led_id in led_map.get_detections():
col = colorsys.hsv_to_rgb(led_id / max_id, 0.5, 1)
pos = np.array((led_map.get_detection(led_id).u, led_map.get_detection(led_id).v))
pos = np.array(
(led_map.get_detection(led_id).u, led_map.get_detection(led_id).v)
)
image_point = (pos * 640).astype(int)
cv2.drawMarker(display, image_point, color=col)
cv2.putText(
Expand Down

0 comments on commit 82ce3b7

Please sign in to comment.