Skip to content

Commit

Permalink
Bumped to v2.1
Browse files Browse the repository at this point in the history
--help now shows default args
updated README.md
added --max_fill argument to adjust fill range
added .lower() to get_backend so that WlEd is valid <3
  • Loading branch information
TheMariday committed Dec 10, 2024
1 parent 9ff8a23 commit 59e0563
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 21 deletions.
33 changes: 26 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,19 @@ pipx install "git+https://github.com/themariday/marimapper"

If you have Python 3.12 installed, install 3.11 and add `--python /path/to/python3.11` to the above `pipx install` command

pipx not working? You can also download this repo and run `pip install .` from inside it
[PIPx not working](https://github.com/TheMariday/marimapper/issues/42)? You can also download this repo and run `pip install .` from inside it!

You can run the scripts anywhere by just typing them into a console, on windows append `.exe` to the script name.

You can append `--help` to any command to show you all argument options.

## Step 1: Test your camera

> [!TIP]
> use `--help` for any MariMapper command to show a full list of additional arguments!
>
> Some not even in this doc...
Run `marimapper_check_camera` to ensure your camera is compatible with MariMapper, or check the list below:

<details>
Expand All @@ -55,13 +60,16 @@ Test LED identification by turning down the lights and holding a torch or led up
This should start with few warnings, no errors and produce a **very** dark image
with a single crosshair on centered on your LED.

Wrong webcam? MariMapper tools use `--device 0` by default, use `--device 1` to switch to your second webcam.

![alt text](docs/images/camera_check.png "Camera Check window")


> [!TIP]
> If your camera doesn't support exposure adjustment, or the image is still too bright, try dimming the lights and playing around with the `--exposure` and `--threshold` arguments
> If your camera doesn't support exposure adjustment, or the image is still too bright, try dimming the lights and playing around with:
>
> - `--exposure` - The lower the darker, defaults to `-10`, my webcam only goes down to `-11`
> - `--threshold` - The lower the more detections, ranges between `0-255`, defaults to `128`
## Step 2: Choose your backend

For the Marimapper to communicate with your leds, it requires a backend.
Expand All @@ -74,6 +82,9 @@ The following backends are built-in:
To use the Fadecandy backend, please ensure that you are running the Fadecandy server
A fork of the Fadecandy repo can be found [here](https://github.com/TheMariday/fadecandy)

Use
`--backend fadecandy --server 127.0.0.1:7890` to enable this backend, adjusting the server IP and port where needed

</details>

<details>
Expand All @@ -96,9 +107,15 @@ Source code can be found [here](https://github.com/TheMariday/fcmega)

Using Pixelblaze as a backend requires you to upload the
[marimapper.epe](marimapper/backends/pixelblaze/marimapper.epe)
pattern to your pixelblaze using
into the PixelBlaze editor and upload it as a new pattern.

`--backend PixelBlaze --server 192.168.4.1` to enable this backend, adjusting the server IP where needed

It might also need a port like `:8000`, not sure... Someone help me out here!

There is also the
`marimapper_upload_to_pixelblaze`
before running Marimapper.
however this might not work due to [issue 41](https://github.com/TheMariday/marimapper/issues/41)

</details>

Expand Down Expand Up @@ -137,7 +154,7 @@ and `fadecandy` to whatever backend you're using and use `--help` to show more o

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]`

This will turn each LED on and off in turn, do not move the camera or leds during capture!
This will turn each LED on and off in turn, **do not move the camera or leds during capture!**

If you just want a 2D map, this is where you can stop!

Expand All @@ -147,7 +164,9 @@ Rotate your leds or move your webcam to a new position
> 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 at least 2 2d maps, a new window will appear showing the reconstructed 3D positions of your LEDs.
Once you have a few views and the reconstructor succeeds, a new window will appear showing the reconstructed 3D positions of your LEDs.

If the window doesn't appear after 4 scans, then something has gone horribly wrong. Delete the scan .csv files in the current working directory and try again.

If it doesn't look quite right, add some more scans!

Expand Down
3 changes: 2 additions & 1 deletion marimapper/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def __init__(
server: str,
led_start: int,
led_end: int,
max_fill: int,
):
logger.debug("initialising scanner")
self.output_dir = output_dir
Expand All @@ -39,7 +40,7 @@ def __init__(
server,
)

self.sfm = SFM()
self.sfm = SFM(max_fill)

self.file_writer = FileWriterProcess(self.output_dir)

Expand Down
3 changes: 2 additions & 1 deletion marimapper/scripts/check_backend_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
def main():

parser = argparse.ArgumentParser(
description="Tests a particular backend by making a reference led blink"
description="Tests a particular backend by making a reference led blink",
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
)

utils.add_backend_args(parser)
Expand Down
3 changes: 2 additions & 1 deletion marimapper/scripts/check_camera_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
def main():

parser = argparse.ArgumentParser(
description="Tests your webcam and LED detection algorithms"
description="Tests your webcam and LED detection algorithms",
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
)

add_camera_args(parser)
Expand Down
13 changes: 12 additions & 1 deletion marimapper/scripts/scanner_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
def main():
logger.info("Starting MariMapper")

parser = argparse.ArgumentParser(description="Captures LED flashes to file")
parser = argparse.ArgumentParser(
description="Captures LED flashes to file",
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
)

add_camera_args(parser)
add_backend_args(parser)
Expand All @@ -28,6 +31,13 @@ def main():
help="the location for your maps, defaults to the current working directory",
)

parser.add_argument(
"--max_fill",
type=int,
default=5,
help="The max number of consecutive LEDs that can be estimated based on adjacent LEDs",
)

args = parser.parse_args()

if not os.path.isdir(args.dir):
Expand All @@ -45,6 +55,7 @@ def main():
args.server,
args.start,
args.end,
args.max_fill,
)

scanner.mainloop()
Expand Down
5 changes: 4 additions & 1 deletion marimapper/scripts/upload_map_to_pixelblaze_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@


def main():
parser = argparse.ArgumentParser(description="Upload led_map_3d.csv to pixelblaze")
parser = argparse.ArgumentParser(
description="Upload led_map_3d.csv to pixelblaze",
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
)
parser.add_argument("--server", type=str, help="pixelblaze server ip")
parser.add_argument(
"--csv_file", type=str, help="The csv file to convert", required=True
Expand Down
5 changes: 3 additions & 2 deletions marimapper/sfm_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@ def add_normals(leds: list[LED3D]):

class SFM(Process):

def __init__(self):
def __init__(self, max_fill=5):
super().__init__()
self._input_queue = Queue()
self._input_queue.cancel_join_thread()
self._output_queues: list[Queue] = []
self._exit_event = Event()
self.max_fill = max_fill

def get_input_queue(self) -> Queue:
return self._input_queue
Expand Down Expand Up @@ -83,7 +84,7 @@ def run(self):

rescale(leds_3d)

fill_gaps(leds_3d)
fill_gaps(leds_3d, max_missing=self.max_fill)

recenter(leds_3d)

Expand Down
19 changes: 13 additions & 6 deletions marimapper/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ def add_camera_args(parser):
parser.add_argument(
"--threshold",
type=int,
choices=range(0, 255),
metavar="[0-100]",
help="LED detection threshold, reducing this number will reduce false positives",
default=128,
)
Expand All @@ -46,7 +48,11 @@ def add_backend_args(parser):
default=10000,
)

parser.add_argument("--server", type=str, help="Some backends require a server")
parser.add_argument(
"--server",
type=str,
help="Some backends require a server, for example 172.0.0.1:7890",
)


def get_user_confirmation(prompt): # pragma: no coverage
Expand Down Expand Up @@ -100,36 +106,37 @@ def check_backend(backend):


def get_backend(backend_name, server=""):
if backend_name == "fadecandy":

if backend_name.lower() == "fadecandy":
from marimapper.backends.fadecandy import fadecandy_backend

if server:
return fadecandy_backend.Backend(server)
else:
return fadecandy_backend.Backend()

if backend_name == "wled":
if backend_name.lower() == "wled":
from marimapper.backends.wled import wled_backend

if server:
return wled_backend.Backend(server)
else:
return wled_backend.Backend()

if backend_name == "fcmega":
if backend_name.lower() == "fcmega":
from marimapper.backends.fcmega import fcmega_backend

return fcmega_backend.Backend()

if backend_name == "pixelblaze":
if backend_name.lower() == "pixelblaze":
from marimapper.backends.pixelblaze import pixelblaze_backend

return pixelblaze_backend.Backend(server)

if os.path.isfile(backend_name) and backend_name.endswith(".py"):
return load_custom_backend(backend_name, server)

if backend_name == "dummy":
if backend_name.lower() == "dummy":
from marimapper.backends.dummy import dummy_backend

return dummy_backend.Backend()
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ build-backend = "hatchling.build"

[project]
name = "marimapper"
version = "V2.0"
version = "V2.1"

dependencies = [
"numpy<1.25.0,>=1.17.3",
Expand Down

0 comments on commit 59e0563

Please sign in to comment.