Skip to content

Commit

Permalink
Add opencv, works locally
Browse files Browse the repository at this point in the history
  • Loading branch information
awwaiid committed Dec 3, 2024
1 parent 7decbb0 commit ac75bc0
Show file tree
Hide file tree
Showing 11 changed files with 558 additions and 63 deletions.
20 changes: 10 additions & 10 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[target.armv7-unknown-linux-gnueabihf]
linker = "<toolchain_install_path>/sysroots/x86_64-codexsdk-linux/usr/bin/arm-remarkable-linux-gnueabi/arm-remarkable-linux-gnueabi-gcc"
rustflags = [
"-C", "link-arg=-march=armv7-a",
"-C", "link-arg=-marm",
"-C", "link-arg=-mfpu=neon",
"-C", "link-arg=-mfloat-abi=hard",
"-C", "link-arg=-mcpu=cortex-a9",
"-C", "link-arg=--sysroot=<toolchain_install_path>/sysroots/cortexa7hf-neon-remarkable-linux-gnueabi",
]
# [target.armv7-unknown-linux-gnueabihf]
# linker = "<toolchain_install_path>/sysroots/x86_64-codexsdk-linux/usr/bin/arm-remarkable-linux-gnueabi/arm-remarkable-linux-gnueabi-gcc"
# rustflags = [
# "-C", "link-arg=-march=armv7-a",
# "-C", "link-arg=-marm",
# "-C", "link-arg=-mfpu=neon",
# "-C", "link-arg=-mfloat-abi=hard",
# "-C", "link-arg=-mcpu=cortex-a9",
# "-C", "link-arg=--sysroot=<toolchain_install_path>/sysroots/cortexa7hf-neon-remarkable-linux-gnueabi",
# ]

199 changes: 199 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "ghostwriter"
version = "0.1.0"
edition = "2021"

[dependencies]
tokio = { version = "1.28", features = ["full"] }
ureq = { version = "2.6", features = ["json"] }
Expand All @@ -15,3 +16,5 @@ clap = { version = "4.0", features = ["derive"] }
evdev = "0.12.0"
resvg = "0.44.0"
dotenv = "0.15"
opencv = "0.93.4"

11 changes: 11 additions & 0 deletions Cross.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# [build]

# additional commands to run prior to building the package
# pre-build = [
# "dpkg --add-architecture $CROSS_DEB_ARCH",
# # "apt-get update && apt-get --assume-yes install libopencv-dev:$CROSS_DEB_ARCH libclang-dev:$CROSS_DEB_ARCH clang:$CROSS_DEB_ARCH"
# "apt-get update && apt-get --assume-yes install libopencv-dev:$CROSS_DEB_ARCH"
# ]

[target.armv7-unknown-linux-gnueabihf]
pre-build = "./cross-deps.sh"
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,20 +151,28 @@ scp target/armv7-unknown-linux-gnueabihf/release/ghostwriter remarkable:
## Scratch

```
# Record an evaluation on the device
./ghostwriter --output-file tmp/result.out --model-output-file tmp/result.json --save-screenshot tmp/input.png --no-draw-progress --save-bitmap tmp/result.png claude-assist
# On local, copy the evaluation to local and then put it into a folder
export evaluation_name=tic_tac_toe_1
rm tmp/*
scp -r remarkable:tmp/ ./
mkdir evaluations/tic_tac_toe_1
mv tmp/* evaluations/tic_tac_toe_1
mkdir -p evaluations/$evaluation_name
mv tmp/* evaluations/$evaluation_name
# Run an evaluation
./target/release/ghostwriter --input-png evaluations/x_in_box/input.png --output-file tmp/result.out --model-output-file tmp/result.json --save-bitmap tmp/result.png --no-draw --no-draw-progress --no-loop claude-assist
./target/release/ghostwriter --input-png evaluations/$evaluation_name/input.png --output-file tmp/result.out --model-output-file tmp/result.json --save-bitmap tmp/result.png --no-draw --no-draw-progress --no-loop claude-assist
# Layer the input and output
magick \( evaluations/x_in_box/input.png -colorspace RGB \) \( tmp/result.png -type truecolormatte -transparent white -fill red -colorize 100 \) -compose Over -composite tmp/merged-output.png
magick \( evaluations/$evaluation_name/input.png -colorspace RGB \) \( tmp/result.png -type truecolormatte -transparent white -fill red -colorize 100 \) -compose Over -composite tmp/merged-output.png
```

Resize from 1872x1404 to 1268x951 px (I think claude does it for us already)
OR maybe 768x1024 is better. Same ratio, but "standard" XGA

Now I've added opencv-rust as a dependency to pre-segment images. To get this in ubuntu I had to do `sudo apt install libopencv-dev libclang-dev clang`.

comment on https://www.lukasmoro.com/paper

3 changes: 3 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ remarkable="${1:-remarkable}"
if [ "$1" == "local" ]; then
cargo build --release
else
# export PKG_CONFIG_SYSROOT_DIR="<toolchain_install_path>/sysroots/cortexa7hf-neon-remarkable-linux-gnueabi"
# export PKG_CONFIG_PATH="<toolchain_install_path>/sysroots/cortexa7hf-neon-remarkable-linux-gnueabi/usr/lib/pkgconfig"
# export PKG_CONFIG_ALLOW_CROSS=1
cross build --release --target=armv7-unknown-linux-gnueabihf && scp target/armv7-unknown-linux-gnueabihf/release/ghostwriter root@$remarkable:
fi

8 changes: 8 additions & 0 deletions cross-deps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

apt-get install -y \
libssl-dev \
libopencv-dev \
clang \
libclang-dev

Loading

0 comments on commit ac75bc0

Please sign in to comment.