Vladimir Vivien 018089c752 Merge pull request #40 from vladimirvivien/macos-cross-compile 2 jaren geleden
..
capture0 7ccb61c632 Update to documentation 2 jaren geleden
capture1 a93d5b26b7 Code and example updates (new examples, new features, ect) 2 jaren geleden
ccapture 7ccb61c632 Update to documentation 2 jaren geleden
cgo_types ebc77c6fbb Fix typo and grammar issues in comments 2 jaren geleden
device_info 0bd8cf2b31 User device control support 2 jaren geleden
ext_ctrls b1cd7da40b Additional documentation and corrections 2 jaren geleden
fileserv a93d5b26b7 Code and example updates (new examples, new features, ect) 2 jaren geleden
format 0bd8cf2b31 User device control support 2 jaren geleden
manual_types ebc77c6fbb Fix typo and grammar issues in comments 2 jaren geleden
simplecam 7ccb61c632 Update to documentation 2 jaren geleden
snapshot b1cd7da40b Additional documentation and corrections 2 jaren geleden
user_ctrl b1cd7da40b Additional documentation and corrections 2 jaren geleden
webcam 5f6dc724af Fix cross-build.sh, update documentation 2 jaren geleden
README.md b1cd7da40b Additional documentation and corrections 2 jaren geleden

README.md

Examples

  • snapshot - A simple example to capture a single frame and save it to a file.
  • capture0 - Shows how to capture multiple images and saves them to files.
  • capture1 - Shows how to capture multiple images using specified image format.
  • device_info - Uses go4vl to query and print device and format information.
  • format - Shows how to query and apply device and format information.
  • ext_ctrls Shows how to query and apply extended controls.
  • user_ctrl Shows how to query and apply user controls.
  • simplecam A functional webcam program that streams video to web page.
  • webcam - Builds on simplecam and adds image control, format control, and face detection.

Building the example code

There are three ways to build the code in the example directories.

On-device build

One of the easiest ways to get started is to setup your Linux workstation (with camera attached), or device (such as Raspberry Pi), with Go to build your source code directly there.

Install the build-essential package to install required C compilers:

sudo apt install build-essential

Also, upgrade your system to pull down the latest OS packages (follow directions for your system-specific steps):

sudo apt update
sudo apt full-upgrade

Cross-compile with Zig toolchain

If you would rather cross-compile the code from a different location (i.e. your MacOS laptop or x86 Linux machine), then you will need tooling to do the CGo-enabled cross-compilation of the C code generated for the code. One easy way to do this is with the Zig language toolchain.

Zig comes with a full C/C++ cross-compiler including flag compatibility with gcc and clang. It can be used as a drop-in replacement for those compilers allowing easy cross-compilation of C source code. Zig cross-compilers can be used for building CGo-enabled Go code with little fuss. Assuming you have the Zig build tools installed, you can easily cross-compile the code in this directory.

For instance, the following cross-compiles the ./simplecam example into a static binary:

CGO_ENABLED=1 GOOS=linux GOARCH=arm GOARM=7 CC="zig cc -target arm-linux-musleabihf" CXX="zig c++ -target arm-linux-musleabihf" go build -o simple-cam ./simplecam

The previous build command will create a static binary that can run on Linux/Arm/v7 architecture.

Cross-compile with Docker

Another way you can achieve cross compilation is with Docker. If you already have Docker as part of your workflow, you will find some images that you can use to cross-compile the code in this directory. For instance, the simplecam example includes a ./simplecam/Dockerfile that uses image crazymax/goxx to cross-compile the go4vl code.