Giter Site home page Giter Site logo

sz3 / libcimbar Goto Github PK

View Code? Open in Web Editor NEW
296.0 3.0 14.0 11.33 MB

Optimized implementation for color-icon-matrix barcodes

Home Page: https://cimbar.org

License: Mozilla Public License 2.0

CMake 0.55% C++ 60.86% C 37.56% Batchfile 0.04% Python 0.21% HTML 0.23% JavaScript 0.21% Shell 0.04% Assembly 0.31%
opencv barcode fountain-codes proof-of-concept image-hash cpp17

libcimbar's Introduction

INTRODUCTION | ABOUT | CFC | LIBCIMBAR

libcimbar: Color Icon Matrix Barcodes

Behold: an experimental barcode format for air-gapped data transfer.

It can sustain speeds of 850 kilobits/s (~106 KB/s) using just a computer monitor and a smartphone camera!

Explain?

The encoder outputs an animated barcode to a computer or smartphone screen:

While the decoder is a cell phone app that uses the phone camera to read the animated barcode:

No internet/bluetooth/NFC/etc is used. All data is transmitted through the camera lens. You can try it out yourself, or take my word that it works. :)

How does it work?

cimbar is a high-density 2D barcode format. Data is stored in a grid of colored tiles -- bits are encoded based on which tile is chosen, and which color is chosen to draw the tile. Reed Solomon error correction is applied on the data, to account for the lossy nature of the video -> digital decoding. Sub-1% error rates are expected, and corrected.

libcimbar, this optimized implementation, includes a simple protocol for file encoding built on fountain codes (wirehair) and zstd compression. Files of up to 33MB (after compression!) are encoded in a series of cimbar codes, which can be output as images or a live video feed. Once enough distinct image frames have been decoded successfully, the file will be reconstructed and decompressed successfully. This is true even if the images are received out of order, or if some have been corrupted or are missing.

Platforms

The code is written in C++, and developed/tested on amd64+linux, arm64+android (decoder only), and emscripten+WASM (encoder only). It probably works, or can be made to work, on other platforms.

Crucially, because the encoder compiles to asmjs and wasm, it can run on anything with a modern web browser. For offline use, you can either install cimbar.org as a progressive web app, or download the latest release of cimbar_js.html, save it locally, and open it in your web browser.

Library dependencies

OpenCV and GLFW (+ OpenGL ES headers) must be installed before building. All other dependencies are included in the source tree.

Build

  1. install opencv and GLFW. On ubuntu/debian, this looks like:
sudo apt install libopencv-dev libglfw3-dev libgles2-mesa-dev
  1. run the cmake + make incantation
cmake .
make -j7
make install

By default, libcimbar will try to install build products under ./dist/bin/.

To build cimbar.js (what cimbar.org uses), see WASM.

Usage

Encode:

  • large input files may fill up your disk with pngs!
./cimbar --encode -i inputfile.txt -o outputprefix

Decode (extracts file into output directory):

./cimbar outputprefix*.png -o /tmp

Decode a series of encoded images from stdin:

echo outputprefix*.png | ./cimbar -o /tmp

Encode and animate to window:

./cimbar_send inputfile.pdf

You can also encode a file using cimbar.org, or the latest release.

Performance numbers

PERFORMANCE

Implementation details

DETAILS

Room for improvement/next steps

TODO

Inspiration

Would you like to know more?

libcimbar's People

Contributors

headedbranch225 avatar notune avatar sz3 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  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

libcimbar's Issues

On files bigger then 33MBs

First, the problem would be telling if a group of cimbars are linked that could be done by having the first byte be the control byte
this could look something like this 10000000 and have a second byte for a index number if the indexed bit is one this model assumes that each cimbar is not mixed with each other, so cimbar 1 can't have images from cimbar 2.
Second, using a file container. The most popular is zip which just so happens to have a split function
zip in.zip --out new.zip -s 33m this will output a zip file with a bunch of z01 z02... files so having a index number is nessisery. (note to resembel run zip -F new.zip --out out)
Note there should be a mode where you can make a cimbar as long as you want, but you have to order them your self.
The index number plus zip would set the max size to, 8448MB with muiltable files with names and the ability to encrypt the files.

QR code codec library

Hello, the QR code codec library you use? I'm learning about it. Can you provide your implementation plan?

camera model

Hi,
Could you tell me the camera model you used to test the decoding under Ubuntu?
Thanks!

cimbar_recv cannot extract pic from cimbar_send

cf3b15b929fdfcdee39d0c6c035ba3c am i doing something wrong? ![0395956D](https://github.com/sz3/libcimbar/assets/111284535/31ebe65b-4a11-44dd-b8ce-e25d70356663) I use one of the outputfigs for recv test, but cimbar_recv extract nothing. 8c644d3258f3a5195e7de111e409d71 int bytes = dec.decode_fountain(img, sink, shouldPreprocess); bytes is always 0.

WebGL issue

My GPU is old and doesn't much support GL related things. so the website doesn't show the barcode and this error appears in the console:

Failed to create WebGL context: WebGL creation failed: 
* tryNativeGL (FEATURE_FAILURE_EGL_NO_CONFIG)
* Exhausted GL driver options. (FEATURE_FAILURE_WEBGL_EXHAUSTED_DRIVERS)

My browser is firefox and the issue may solve by:

  • Enabling hardware acceleration
  • Toggling webgl.out-of-process in about:config (worked for me)
  • Toggling webgl.force-enabled in about:config

It's good idea to handle the error and suggest to user to try above suggestions.

Building Static/Portable

If I run sudo ./package-portable-linux.sh, it gives me this error:

Expand Block [Click]
./package-portable-linux.sh: line 5: cd: /usr/src/app: No such file or directory
Hit:1 cdrom://Trisquel 11.0 _aramo_ - Release amd64 (20230315) aramo InRelease
Hit:2 http://archive.trisquel.org/trisquel aramo InRelease
Hit:3 http://archive.trisquel.org/trisquel aramo-updates InRelease
Hit:4 http://archive.trisquel.org/trisquel aramo-security InRelease
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
325 packages can be upgraded. Run 'apt list --upgradable' to see them.
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  python3-software-properties software-properties-qt
The following packages will be upgraded:
  python3-software-properties software-properties-common software-properties-qt
3 upgraded, 0 newly installed, 0 to remove and 322 not upgraded.
Need to get 119 kB of archives.
After this operation, 0 B of additional disk space will be used.
Get:1 http://archive.trisquel.org/trisquel aramo-updates/main amd64 software-properties-common all 0.99.22.8+11.0trisquel13 [64.2 kB]
Get:2 http://archive.trisquel.org/trisquel aramo-updates/main amd64 software-properties-qt all 0.99.22.8+11.0trisquel13 [25.7 kB]
Get:3 http://archive.trisquel.org/trisquel aramo-updates/main amd64 python3-software-properties all 0.99.22.8+11.0trisquel13 [29.3 kB]
Fetched 119 kB in 0s (288 kB/s)                       
(Reading database ... 228949 files and directories currently installed.)
Preparing to unpack .../software-properties-common_0.99.22.8+11.0trisquel13_all.deb ...
Unpacking software-properties-common (0.99.22.8+11.0trisquel13) over (0.99.22.6+11.0trisquel12) ...
Preparing to unpack .../software-properties-qt_0.99.22.8+11.0trisquel13_all.deb ...
Unpacking software-properties-qt (0.99.22.8+11.0trisquel13) over (0.99.22.6+11.0trisquel12) ...
Preparing to unpack .../python3-software-properties_0.99.22.8+11.0trisquel13_all.deb ...
Unpacking python3-software-properties (0.99.22.8+11.0trisquel13) over (0.99.22.6+11.0trisquel12) ...
Setting up python3-software-properties (0.99.22.8+11.0trisquel13) ...
Setting up software-properties-common (0.99.22.8+11.0trisquel13) ...
Setting up software-properties-qt (0.99.22.8+11.0trisquel13) ...
Processing triggers for man-db (2.10.2-1) ...
Processing triggers for dbus (1.12.20-2ubuntu4.1) ...
Processing triggers for mailcap (3.70+nmu1ubuntu1) ...
Processing triggers for desktop-file-utils (0.26-1ubuntu3+11.0trisquel2) ...
PPA publishes dbgsym, you may need to include 'main/debug' component
Repository: 'deb https://ppa.launchpadcontent.net/ubuntu-toolchain-r/test/ubuntu/ jammy main'
Description:
Toolchain test builds; see https://wiki.ubuntu.com/ToolChain

More info: https://launchpad.net/~ubuntu-toolchain-r/+archive/ubuntu/test
Adding repository.
Adding deb entry to /etc/apt/sources.list.d/ubuntu-toolchain-r-ubuntu-test-aramo.list
Adding disabled deb-src entry to /etc/apt/sources.list.d/ubuntu-toolchain-r-ubuntu-test-aramo.list
Adding key to /etc/apt/trusted.gpg.d/ubuntu-toolchain-r-ubuntu-test.gpg with fingerprint 60C317803A41BA51845E371A1E9377A2BA9EF27F
Hit:1 cdrom://Trisquel 11.0 aramo - Release amd64 (20230315) aramo InRelease
Hit:2 http://archive.trisquel.org/trisquel aramo InRelease
Hit:3 http://archive.trisquel.org/trisquel aramo-updates InRelease
Hit:4 http://archive.trisquel.org/trisquel aramo-security InRelease
Get:5 https://ppa.launchpadcontent.net/ubuntu-toolchain-r/test/ubuntu jammy InRelease [23.8 kB]
Get:6 https://ppa.launchpadcontent.net/ubuntu-toolchain-r/test/ubuntu jammy/main amd64 Packages [15.5 kB]
Get:7 https://ppa.launchpadcontent.net/ubuntu-toolchain-r/test/ubuntu jammy/main Translation-en [7808 B]
Fetched 47.1 kB in 2s (29.5 kB/s)
Reading package lists... Done
Hit:1 cdrom://Trisquel 11.0 aramo - Release amd64 (20230315) aramo InRelease
Hit:2 http://archive.trisquel.org/trisquel aramo InRelease
Hit:3 http://archive.trisquel.org/trisquel aramo-updates InRelease
Hit:4 http://archive.trisquel.org/trisquel aramo-security InRelease
Hit:5 https://ppa.launchpadcontent.net/ubuntu-toolchain-r/test/ubuntu jammy InRelease
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
333 packages can be upgraded. Run 'apt list --upgradable' to see them.
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package g++-7
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
libglfw3-dev is already the newest version (3.3.6-1).
libgles2-mesa-dev is already the newest version (23.0.4-0ubuntu1~22.04.1).
0 upgraded, 0 newly installed, 0 to remove and 333 not upgraded.
./package-portable-linux.sh: line 17: python: command not found
update-alternatives: error: alternative path /usr/bin/gcc-7 doesn't exist
update-alternatives: error: alternative path /usr/bin/g++-7 doesn't exist
./package-portable-linux.sh: line 23: cd: opencv4/: No such file or directory
mkdir: cannot create directory ‘build-portable/’: File exists
./package-portable-linux.sh: line 25: /usr/local/bin/cmake: No such file or directory
make: *** No rule to make target 'install'. Stop.
./package-portable-linux.sh: line 28: cd: /usr/src/app: No such file or directory
mkdir: cannot create directory ‘build-portable/’: File exists
./package-portable-linux.sh: line 30: /usr/local/bin/cmake: No such file or directory
make: *** No rule to make target 'install'. Stop.


Is it not meant to make a static/portable executable?
Please tell me if there's a way, because I've been needing to rely on a livecd for a while and installing the dependencies repeatedly is getting very annoying.

Aborted(OOM) error

Trying to load a ~90 MB file and I'm getting this error.
More specifically these 2.

17:13:38.013 file input: [object HTMLInputElement] main.js:126:13
17:13:39.065 Aborted(OOM) cimbar_js.js:1:5472
    abort https://cimbar.org/cimbar_js.js:1
    abortOnCannotGrowMemory https://cimbar.org/cimbar_js.js:1
    _emscripten_resize_heap https://cimbar.org/cimbar_js.js:1
    <anonymous> https://cimbar.org/cimbar_js.wasm:64936
    <anonymous> https://cimbar.org/cimbar_js.wasm:12358
    onload https://cimbar.org/main.js:25
    (Async: EventHandlerNonNull)
    importFile https://cimbar.org/main.js:22
    fileInput https://cimbar.org/main.js:129
    onchange https://cimbar.org/:1
17:13:39.067 Uncaught RuntimeError: Aborted(OOM). Build with -sASSERTIONS for more info. cimbar_js.js:1:5558
    abort https://cimbar.org/cimbar_js.js:1
    abortOnCannotGrowMemory https://cimbar.org/cimbar_js.js:1
    _emscripten_resize_heap https://cimbar.org/cimbar_js.js:1
    onload https://cimbar.org/main.js:25
    importFile https://cimbar.org/main.js:22
    fileInput https://cimbar.org/main.js:129
    onchange https://cimbar.org/:1

Windows binary

Is there any way to build an executable of encoder for Windows 7?
What tools are needed and is there any instruction?

Towards 6-bit tiles?

Hi,

Awesome stuff!

In your TODOs, you mention it would probably be possible to go from 4-bit tiles to 5-bit ones (32 title hashes).

Since color seems to have a sweet-spot at around 2 bits, do you think 6-bit (64 value) tiles are possible?

It would mean additional effort in designing the tiles to avoid hash collisions, while still maintaining at least 16 bits Hamming distances.

answer

Hi! Is the role of 112112 grid used to form the mat size of 10241024? Is there any connection between data blocks and grid

Decoder Binary

I came across https://github.com/dzhang314/YouTubeDrive and recalled downloading and playing around with your Camera File Copy application. It's a wonderful idea but I also really like the idea and I see a couple of potential use cases.

  • Being able to upload a file to a video hosting service (while not abusing the privilege) and then using a downloader to recover that file
  • Sending that video via some sort of filesharing service from computer to computer (not super useful but interesting from the point of view of steganography)
  • The ability to transfer a file to/from an airgapped machine using a webcam

Do you by chance have a decoder binary able to be built for a computer already in the repo and I've missed it or would it be possible to request such a binary be added so that recovery isn't limited to an Android device?

send file name

I think it would be a great feature to include the file name as well. (or maybe just the file extension). This would only require a few additional bytes to be sent.

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.