<commit_before># cv-rs

[![Build Status][travis-image]][travis-url]
[![Build status][appveyor-image]][appveyor-url]
[![standard-readme compliant][standard-readme-image]][standard-readme-url]

> This library primarily provides bindings (somewhat idiomatic) and APIs for
> OpenCV 3.x.

[Documentation](https://nebgnahz.github.io/cv-rs/cv/)

## Table of Contents

- [Background](#background)
- [Install](#install)
- [Usage](#usage)
- [Contribute](#contribute)
- [License](#license)

## Background

OpenCV (Open Source Computer Vision Library: http://opencv.org) is an
open-source BSD-licensed library that includes several hundreds of computer
vision algorithms. It's mainly developed in C++. This library provides Rust
bindings to access OpenCV functionalities. First, C bindings are created
(in [native](native) folder); then [Rust APIs](src/lib.rs) are constructed
atop. Although this manual process seems an inefficient process, it has served
me well as a learning experience to both OpenCV and Rust. In terms of OpenCV API
coverage, modules and functions are implemented as needed.

Please check out the [documentation](https://nebgnahz.github.io/cv-rs/cv/) to
see what has been ported. If you have demand for porting specific features,
please open an issue, or better create a PR.

Attempts to use [rust-bindgen](https://github.com/servo/rust-bindgen)
or [cpp_to_rust](https://github.com/rust-qt/cpp_to_rust) haven't been very
successful (I probably haven't tried hard enough). There is another
port [opencv-rust](https://github.com/kali/opencv-rust/) which generates OpenCV
bindings using a Python script (more automated).

## Install

Before anything, make sure you have OpenCV 3 installed. Read this
[Introduction to OpenCV][opencv-intro] to get started.

Then in any Rust project, add this to your `Cargo.toml`:

```
[dependencies]
cv = { git = "https://github.com/nebgnahz/cv-rs.git" }
```

And add this to your crate:

```
extern crate cv;
use cv::*;
```

And then, enjoy the power of OpenCV.

If you'd like to use OpenCV GPU functions, it's inside `cv::cuda`. Enable it
with the following code in `Cargo.toml`:

```
[dependencies.cv]
git = "https://github.com/nebgnahz/cv-rs"
features = [ "gpu" ]
```

### Windows


Depending on your install, you have to set `%OPENCV_DIR%` environment variable in such a way that `%OPENCV_DIR%\include` points to the OpenCV includes diretory (for example, it could be `C:\opencv\build`).

##### If you are using MSVC toolchain:
- Set  environment variable `%OPENCV_LIB%` to `%OPENCV_DIR%\x64\<vc14 or vc15>\lib`. Check that this directory has `opencv_world<version_number>.lib`
- Add `%OPENCV_DIR%\x64\<vc14 or vc15>\bin` to the `%PATH%`. Check that this directory has `opencv_world<version_number>.dll`

##### If you are using GNU toolchain:

In this case, configuration process is a bit more complicated, because you have to build OpenCV from sources. Follow these steps:
- Add `MinGW` to the `PATH`. This path could look like `C:\Program Files\mingw-w64\x86_64-7.2.0-posix-seh-rt_v5-rev1\mingw64\bin`. If you haven't installed it yet, download it from [here](https://sourceforge.net/projects/mingw-w64/files/latest/download). Choose architecture `x86_64` during installation.
- Download and install [CMake](https://cmake.org/download/). Caution, don't download the source code, you need the binary.
- Run ‘cmake-gui’ in `<cmake-binary>\bin`. For example, `C:\Program Files\CMake\bin\cmake-gui.exe`
- Enter `%OPENCV_DIR%\..\sources` path in the Windows Explorer and copy result in ‘Where is the source code:’ text box (_CMake doesn't understand path traversal syntax while explorer does_). For example, it could be `C:\opencv\sources`.
- Do the same thing with `%OPENCV_DIR%\x64\mingw` and paste it in ‘Where to build the binaries:’ text box. For example, it could be `C:\opencv\build\x64\mingw`.
- Click ‘Configure’. In the popping window, select MinGW option under ‘Specify the generator for this project’ and click ‘Finish’.
- Search for `WITH_IPP` and **disable** it (otherwise ‘cannot find -lRunTmChk’ error is expected when building OpenCV).
- Search for `BUILD_opencv_world` and **enable** it (otherwise `cv-rs` won't compile).
- Click ‘Generate’. Select 'MinGW makefiles' from the dropdown and click ok. Now you have properly configured OpenCV.
- Open bash shell in `OPENCV_DIR%\x64\mingw` directory and run `mingw32-make`. You should get following result:
![MinGW make](https://preview.ibb.co/fuTz1b/2018_01_07.png)
- Set environment variable `%OPENCV_LIB%` to `%OPENCV_DIR%\x64\mingw\lib`. Check that this directory has `libopencv_world<version_number>.dll.a`.
- Add `%OPENCV_DIR%\x64\mingw\bin` to the `%PATH%`. Check that this directory has  `libopencv_world<version_number>.dll`


## Usage

See available examples on how this library might be used.

- [Display Image](examples/display_image.rs)<commit_msg>Update screenshot link (host on Github)<commit_after># cv-rs

[![Build Status][travis-image]][travis-url]
[![Build status][appveyor-image]][appveyor-url]
[![standard-readme compliant][standard-readme-image]][standard-readme-url]

> This library primarily provides bindings (somewhat idiomatic) and APIs for
> OpenCV 3.x.

[Documentation](https://nebgnahz.github.io/cv-rs/cv/)

## Table of Contents

- [Background](#background)
- [Install](#install)
- [Usage](#usage)
- [Contribute](#contribute)
- [License](#license)

## Background

OpenCV (Open Source Computer Vision Library: http://opencv.org) is an
open-source BSD-licensed library that includes several hundreds of computer
vision algorithms. It's mainly developed in C++. This library provides Rust
bindings to access OpenCV functionalities. First, C bindings are created
(in [native](native) folder); then [Rust APIs](src/lib.rs) are constructed
atop. Although this manual process seems an inefficient process, it has served
me well as a learning experience to both OpenCV and Rust. In terms of OpenCV API
coverage, modules and functions are implemented as needed.

Please check out the [documentation](https://nebgnahz.github.io/cv-rs/cv/) to
see what has been ported. If you have demand for porting specific features,
please open an issue, or better create a PR.

Attempts to use [rust-bindgen](https://github.com/servo/rust-bindgen)
or [cpp_to_rust](https://github.com/rust-qt/cpp_to_rust) haven't been very
successful (I probably haven't tried hard enough). There is another
port [opencv-rust](https://github.com/kali/opencv-rust/) which generates OpenCV
bindings using a Python script (more automated).

## Install

Before anything, make sure you have OpenCV 3 installed. Read this
[Introduction to OpenCV][opencv-intro] to get started.

Then in any Rust project, add this to your `Cargo.toml`:

```
[dependencies]
cv = { git = "https://github.com/nebgnahz/cv-rs.git" }
```

And add this to your crate:

```
extern crate cv;
use cv::*;
```

And then, enjoy the power of OpenCV.

If you'd like to use OpenCV GPU functions, it's inside `cv::cuda`. Enable it
with the following code in `Cargo.toml`:

```
[dependencies.cv]
git = "https://github.com/nebgnahz/cv-rs"
features = [ "gpu" ]
```

### Windows


Depending on your install, you have to set `%OPENCV_DIR%` environment variable in such a way that `%OPENCV_DIR%\include` points to the OpenCV includes diretory (for example, it could be `C:\opencv\build`).

##### If you are using MSVC toolchain:
- Set  environment variable `%OPENCV_LIB%` to `%OPENCV_DIR%\x64\<vc14 or vc15>\lib`. Check that this directory has `opencv_world<version_number>.lib`
- Add `%OPENCV_DIR%\x64\<vc14 or vc15>\bin` to the `%PATH%`. Check that this directory has `opencv_world<version_number>.dll`

##### If you are using GNU toolchain:

In this case, configuration process is a bit more complicated, because you have to build OpenCV from sources. Follow these steps:
- Add `MinGW` to the `PATH`. This path could look like `C:\Program Files\mingw-w64\x86_64-7.2.0-posix-seh-rt_v5-rev1\mingw64\bin`. If you haven't installed it yet, download it from [here](https://sourceforge.net/projects/mingw-w64/files/latest/download). Choose architecture `x86_64` during installation.
- Download and install [CMake](https://cmake.org/download/). Caution, don't download the source code, you need the binary.
- Run ‘cmake-gui’ in `<cmake-binary>\bin`. For example, `C:\Program Files\CMake\bin\cmake-gui.exe`
- Enter `%OPENCV_DIR%\..\sources` path in the Windows Explorer and copy result in ‘Where is the source code:’ text box (_CMake doesn't understand path traversal syntax while explorer does_). For example, it could be `C:\opencv\sources`.
- Do the same thing with `%OPENCV_DIR%\x64\mingw` and paste it in ‘Where to build the binaries:’ text box. For example, it could be `C:\opencv\build\x64\mingw`.
- Click ‘Configure’. In the popping window, select MinGW option under ‘Specify the generator for this project’ and click ‘Finish’.
- Search for `WITH_IPP` and **disable** it (otherwise ‘cannot find -lRunTmChk’ error is expected when building OpenCV).
- Search for `BUILD_opencv_world` and **enable** it (otherwise `cv-rs` won't compile).
- Click ‘Generate’. Select 'MinGW makefiles' from the dropdown and click ok. Now you have properly configured OpenCV.
- Open bash shell in `OPENCV_DIR%\x64\mingw` directory and run `mingw32-make`. You should get following result:
![MinGW make](https://user-images.githubusercontent.com/941519/34654809-836fe56c-f3b5-11e7-87b3-46bb7667bf34.png)
- Set environment variable `%OPENCV_LIB%` to `%OPENCV_DIR%\x64\mingw\lib`. Check that this directory has `libopencv_world<version_number>.dll.a`.
- Add `%OPENCV_DIR%\x64\mingw\bin` to the `%PATH%`. Check that this directory has  `libopencv_world<version_number>.dll`


## Usage

See available examples on how this library might be used.

- [Display Image](examples/display_image.rs)
{'fraction_non_alphanumeric': 0.12191641182466871, 'fraction_numerical': 0.01365953109072375, 'mean_word_length': 4.7779740871613665, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 21, 'https://': 20, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1901466', 'n_tokens_mistral': 3264, 'n_tokens_neox': 3044, 'n_words': 1116}