Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 4 additions & 37 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,37 +1,4 @@
zig-*
.zigmod
deps.zig
### Generated by gibo (https://github.com/simonwhitaker/gibo)
### https://raw.github.com/github/gitignore/d0b80a469983a7beece8fa1f5c48a8242318b531/Global/macOS.gitignore

# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

mnist_png/*

docs/
src/images
/zig-out
/.zig-cache
/gocv_build
/gocv*
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

1 change: 1 addition & 0 deletions .zigversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.14.0-dev.1911+3bf89f55c
106 changes: 67 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,82 +1,110 @@
# ZIGCV

[![ci](https://github.com/ryoppippi/zigcv/actions/workflows/ci.yml/badge.svg)](https://github.com/ryoppippi/zigcv/actions/workflows/ci.yml)
# ZigCV

<div align="center">
<img src="./logo/zigcv.png" width="50%" />
</div>

The ZIGCV library provides Zig language bindings for the [OpenCV 4](http://opencv.org/) computer vision library.
The ZigCV library provides Zig language bindings for the
[OpenCV 4](http://opencv.org/) computer vision library.

The ZigCV library supports the same nominated version of zig as
[Mach](https://machengine.org/) and the
[zig-gamedev](https://github.com/zig-gamedev/) libraries.

The ZIGCV library supports the head/master of zig and OpenCV (v4.6.0) on Linux, macOS, and Windows.
The ZigCV library currently supports
[OpenCV v4.11.0](https://github.com/opencv/opencv/tree/4.11.0).

## Caution
It uses [GoCV 0.40.0](https://github.com/hybridgroup/gocv/tree/v0.40.0) for its
C bindings to OpenCV.

Still under development, so the zig APIs will be dynamically changed.
**Caution**

You can use `const c_api = @import("zigcv").c_api;` to call c bindings directly.
This C-API is currently fixed.
Under development. The Zig APIs may be missing or change.

## How to execute
## Install

### Use your own package manager
At first, install openCV 4.6. (maybe you can read how to install from [here](https://github.com/hybridgroup/gocv#how-to-install)).
Then:
Add to your project's dependencies:

```sh
git clone --recursive https://github.com/ryoppippi/zigcv
cd zigcv
zig build
zig fetch --save 'git+https://codeberg.org/glitchcake/zigcv'
```

Currently this repo works with zig 0.11.0, so make sure you have it installed.
We are working on updating to zig 0.12.0.
Add to your `build.zig`:

```zig
const zigcv = b.dependency("zigcv", .{});
exe.root_module.addImport("zigcv", zigcv.module("root"));
exe.linkLibrary(zigcv.artifact("zigcv"));
```

### Use devbox
We also provide a devbox config to manage dependencies and build environments.
## Usage

```sh
git clone --recursive https://github.com/zigcv
cd zigcv
devbox init
Once added to your project, you may import and use.

```zig
const cv = @import("zigcv");
```

Checkout [devbox.json](./devbox.json) for more details.
You can also call C bindings directly via the `c` struct on the import.

## Demos
```zig
cv.c
```

you can build some demos.
For example:
### Example

```sh
zig build examples
./zig-out/bin/face_detection 0
Here is a minimal program:

```zig
const std = @import("std");
const cv = @import("zigcv");

pub fn main() !void {
std.debug.print("version via zig binding:\t{s}\n", .{cv.openCVVersion()});
std.debug.print("version via c api directly:\t{s}\n", .{cv.c.openCVVersion()});
}
```

Or you can run the demo with the following command:
## More Examples

There are a handful of sample programs in the `examples/` directory.

You can build them by running `zig build` there:

```sh
devbox run build examples
./zig-out/bin/face_detection 0
cd examples && zig build; popd; ./examples/zig-out/bin/hello
```

## Demo

```
./examples/zig-out/bin/face_detection 0
```

<div align="center">
<img width="400" alt="face detection" src="https://user-images.githubusercontent.com/1560508/188515175-4d344660-5680-43e7-9b74-3bad92507430.gif">
</div>

You can see the full demo list by `zig build --help`.

## Technical restrictions

Due to zig being a relatively new language it does [not have full C ABI support](https://github.com/ziglang/zig/issues/1481) at the moment.
For use that mainly means we can't use any functions that return structs that are less than 16 bytes large on x86, and passing structs to any functions may cause memory error on arm.
Due to zig being a relatively new language it does
[not have full C ABI support](https://github.com/ziglang/zig/issues/1481) at the
moment. For use that mainly means we can't use any functions that return structs
that are less than 16 bytes large on x86, and passing structs to any functions
may cause memory error on arm.

## Todo

- [ ] Get all examples working
- [ ] Fix all commented out tests
- [ ] Add cuda and openvino back

## License

MIT

## Author
## Authors

Ryotaro "Justin" Kimura (a.k.a. ryoppippi)

[glitchcake](https://codeberg.org/glitchcake/)
Loading