Skip to content

Commit

Permalink
update to OpenCV 4.8.0 (#213)
Browse files Browse the repository at this point in the history
* Use opencv 4.8.0

* updated tests for OpenCV 4.8.0

* fixed base class for BarCodeDetector, QRCodeDetector and QRCodeDetectorAruco

* v0.1.32
  • Loading branch information
cocoa-xu committed Jul 31, 2023
1 parent dc69694 commit 3f04a87
Show file tree
Hide file tree
Showing 25 changed files with 94 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/linux-cuda-gnu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ jobs:
DEBIAN_FRONTEND: noninteractive
# evision related env vars
MIX_ENV: test
OPENCV_VER: "4.7.0"
OPENCV_VER: "4.8.0"
OTP_VERSION: "25.2"
ELIXIR_VERSION: "1.14.3"
EVISION_PREFER_PRECOMPILED: "false"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/linux-precompile-cuda-gnu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
DEBIAN_FRONTEND: noninteractive
# evision related env vars
MIX_ENV: test
OPENCV_VER: "4.7.0"
OPENCV_VER: "4.8.0"
ELIXIR_VERSION: "1.15.2"
EVISION_PREFER_PRECOMPILED: "false"
EVISION_GENERATE_LANG: "erlang,elixir"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/linux-precompile-gnu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
mix_compile:
runs-on: ubuntu-20.04
env:
OPENCV_VER: "4.7.0"
OPENCV_VER: "4.8.0"
MIX_ENV: prod
ELIXIR_VERSION: "1.15.2"
EVISION_PREFER_PRECOMPILED: "false"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/linux-precompile-musl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
container: alpine:latest
env:
MIX_ENV: prod
OPENCV_VER: "4.7.0"
OPENCV_VER: "4.8.0"
EVISION_PREFER_PRECOMPILED: "false"
EVISION_GENERATE_LANG: "erlang,elixir"
strategy:
Expand Down Expand Up @@ -165,7 +165,7 @@ jobs:
zig_build:
runs-on: ubuntu-20.04
env:
OPENCV_VER: "4.7.0"
OPENCV_VER: "4.8.0"
MIX_ENV: prod
ZIG_VERSION: "0.8.0"
EVISION_PREFER_PRECOMPILED: "false"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/linux-x86_64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:
container: alpine:latest
env:
MIX_ENV: test
OPENCV_VER: "4.7.0"
OPENCV_VER: "4.8.0"
OTP_VERSION: "25.2"
ELIXIR_VERSION: "1.14.3"
EVISION_PREFER_PRECOMPILED: "false"
Expand Down Expand Up @@ -154,7 +154,7 @@ jobs:
runs-on: ubuntu-20.04
env:
MIX_ENV: test
OPENCV_VER: "4.7.0"
OPENCV_VER: "4.8.0"
OTP_VERSION: "25.2"
ELIXIR_VERSION: "1.14.3"
EVISION_PREFER_PRECOMPILED: "false"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/macos-precompile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: macos-11
env:
MIX_ENV: prod
OPENCV_VER: "4.7.0"
OPENCV_VER: "4.8.0"
EVISION_PREFER_PRECOMPILED: "false"
EVISION_GENERATE_LANG: "erlang,elixir"
strategy:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/macos-x86_64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
mix_test:
runs-on: macos-12
env:
OPENCV_VER: "4.7.0"
OPENCV_VER: "4.8.0"
MIX_ENV: "test"
EVISION_PREFER_PRECOMPILED: "false"
FFMPEG_VER: "5"
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/nerves-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,8 @@ jobs:
env:
MIX_ENV: prod
NERVES_PROJ_NAME: nerves_evision
OPENCV_VER: "4.7.0"
OPENCV_VER: "4.8.0"
NERVES_LIVEBOOK_VER: "v0.10.1"

ELIXIR_VERSION: "1.15.4"
EVISION_PREFER_PRECOMPILED: "false"

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-python-compatibility.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
runs-on: ubuntu-20.04
env:
MIX_ENV: test
OPENCV_VER: "4.7.0"
OPENCV_VER: "4.8.0"
EVISION_PREFER_PRECOMPILED: "false"

strategy:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/windows-precompile-cuda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: windows-2019
env:
MIX_ENV: prod
OPENCV_VER: "4.7.0"
OPENCV_VER: "4.8.0"
ELIXIR_VERSION: "1.14.3"
EVISION_PREFER_PRECOMPILED: "false"
EVISION_GENERATE_LANG: "erlang,elixir"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/windows-precompile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ jobs:
runs-on: windows-latest
env:
MIX_ENV: prod
OPENCV_VER: "4.7.0"
ELIXIR_VERSION: "1.15.2"
OPENCV_VER: "4.8.0"
ELIXIR_VERSION: "1.15.4"
EVISION_PREFER_PRECOMPILED: "false"
EVISION_GENERATE_LANG: "erlang,elixir"
MAKE: "nmake"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/windows-x86_64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
runs-on: windows-latest
env:
MIX_ENV: test
OPENCV_VER: "4.7.0"
OPENCV_VER: "4.8.0"
OTP_VERSION: "25.2"
ELIXIR_VERSION: "1.14.3"
EVISION_PREFER_PRECOMPILED: "false"
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## v0.1.32 (2023-07-31)
[Browse the Repository](https://github.com/cocoa-xu/evision/tree/v0.1.32) | [Released Assets](https://github.com/cocoa-xu/evision/releases/tag/v0.1.32)

### Changed
- Updated to OpenCV 4.8.0. Some APIs have changed, please see OpenCV's release note for more information.

## v0.1.31 (2023-04-17)
[Browse the Repository](https://github.com/cocoa-xu/evision/tree/v0.1.31) | [Released Assets](https://github.com/cocoa-xu/evision/releases/tag/v0.1.31)

Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ CMAKE_BUILD_TYPE ?= Release
# OpenCV
OPENCV_USE_GIT_HEAD ?= false
OPENCV_GIT_REPO ?= "https://github.com/opencv/opencv.git"
OPENCV_VER ?= 4.7.0
OPENCV_VER ?= 4.8.0
ifneq ($(OPENCV_USE_GIT_HEAD), false)
OPENCV_VER=$(OPENCV_USE_GIT_BRANCH)
endif
OPENCV_CONTRIB_USE_GIT_HEAD ?= false
OPENCV_GIT_REPO ?= "https://github.com/opencv/opencv_contrib.git"
OPENCV_CONTRIB_VER ?= 4.7.0
OPENCV_CONTRIB_VER ?= 4.8.0
ifneq ($(OPENCV_CONTRIB_USE_GIT_HEAD), false)
OPENCV_CONTRIB_VER=$(OPENCV_CONTRIB_USE_GIT_BRANCH)
endif
Expand Down
4 changes: 2 additions & 2 deletions Makefile.win
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ OPENCV_USE_GIT_HEAD=false
OPENCV_GIT_REPO="https://github.com/opencv/opencv.git"
!ENDIF
!IFNDEF OPENCV_VER
OPENCV_VER=4.7.0
OPENCV_VER=4.8.0
!ENDIF
!IFNDEF OPENCV_CONTRIB_VER
OPENCV_CONTRIB_VER=4.7.0
OPENCV_CONTRIB_VER=4.8.0
!ENDIF
!IF "$(OPENCV_USE_GIT_HEAD)" == "true"
OPENCV_VER=$(OPENCV_USE_GIT_BRANCH)
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ iex> mat = Evision.Mat.from_nx(t)

#### Unsupported Type Map

As OpenCV does not support the following types (yet, as of OpenCV 4.7.0)
As OpenCV does not support the following types (yet, as of OpenCV 4.8.0)

- `{:s, 64}`
- `{:u, 32}`
Expand Down Expand Up @@ -319,6 +319,7 @@ Compatible OpenCV versions:
- 4.5.5
- 4.6.0
- 4.7.0
- 4.8.0

by compatible, it means these versions can compile successfully, and I tested a small range of functions. Tons of tests
should be written, and then we can have a list for tested OpenCV versions.
Expand Down Expand Up @@ -518,7 +519,7 @@ To obtain and compile OpenCV's source code from official releases, the following
# optional
## set OpenCV version
## the corresponding license file should be available at https://github.com/opencv/opencv/blob/${OPENCV_VER}/LICENSE
export OPENCV_VER="4.7.0"
export OPENCV_VER="4.8.0"

# optional
## Use Debug build
Expand Down Expand Up @@ -704,7 +705,7 @@ Say you have the following MIX environment variables:
# set by MIX
MIX_ENV=dev
# set by evision or you
OPENCV_VER=4.7.0
OPENCV_VER=4.8.0
# set by yourself if you're compiling evision to a nerves firmware
MIX_TARGET=rpi4
```
Expand Down
6 changes: 3 additions & 3 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ defmodule Evision.MixProject.Metadata do
@moduledoc false

def app, do: :evision
def version, do: "0.1.31"
def version, do: "0.1.32"
def github_url, do: "https://github.com/cocoa-xu/evision"
def opencv_version, do: "4.7.0"
def opencv_version, do: "4.8.0"
# only means compatible. need to write more tests
def compatible_opencv_versions, do: ["4.5.3", "4.5.4", "4.5.5", "4.6.0", "4.7.0"]
def compatible_opencv_versions, do: ["4.5.3", "4.5.4", "4.5.5", "4.6.0", "4.7.0", "4.8.0"]
def default_cuda_version, do: "118"
def all_cuda_version, do: ["111", "114", "118"]
end
Expand Down
2 changes: 1 addition & 1 deletion patches/apply_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


def patch_fix_getLayerShapes(opencv_version: str, opencv_src_root: str):
if opencv_version not in ['4.5.4', '4.5.5', '4.6.0', '4.7.0']:
if opencv_version not in ['4.5.4', '4.5.5', '4.6.0', '4.7.0', '4.8.0']:
print(f"warning: applying `patch_fix_getLayerShapes` to opencv version `{opencv_version}`")

# modules/dnn/include/opencv2/dnn/dnn.hpp
Expand Down
11 changes: 7 additions & 4 deletions py_src/class_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,16 @@ def gen_erl_func_list(self, codegen):
while base_class is not None:
if base_class \
and (
current_class.cname.startswith("cv::ml")
base_class == "GraphicalCodeDetector"
or current_class.cname.startswith("cv::ml")
or "Calibrate" in current_class.cname
or "Calibrate" in current_class.cname
or (current_class.base is not None and "Feature2D" in current_class.base)
or (current_class.base is not None and "Matcher" in current_class.base)
or (current_class.base is not None and "Algorithm" in current_class.base)
or (current_class.base is not None and current_class.cname.startswith("cv::dnn"))
):
if base_class in codegen.classes:
if base_class in codegen.classes and current_class.base is not None:
base_class = codegen.classes[current_class.base]
for base_method_name in base_class.methods:
if base_method_name not in methods:
Expand Down Expand Up @@ -240,14 +242,15 @@ def gen_code(self, codegen):
while base_class is not None:
if base_class \
and (
current_class.cname.startswith("cv::ml")
base_class == "GraphicalCodeDetector"
or current_class.cname.startswith("cv::ml")
or "Calibrate" in current_class.cname
or (current_class.base is not None and "Feature2D" in current_class.base)
or (current_class.base is not None and "Matcher" in current_class.base)
or (current_class.base is not None and "Algorithm" in current_class.base)
or (current_class.base is not None and current_class.cname.startswith("cv::dnn"))
):
if base_class in codegen.classes:
if base_class in codegen.classes and current_class.base is not None:
base_class = codegen.classes[current_class.base]
for base_method_name in base_class.methods:
if base_method_name not in methods:
Expand Down
8 changes: 8 additions & 0 deletions py_src/func_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,10 @@ def gen_code(self, codegen):
if defval and len(defval) > 0:
if arg_type_info.atype == "QRCodeEncoder_Params":
code_decl += " QRCodeEncoder::Params %s=%s;\n" % (a.name, defval)
elif arg_type_info.atype == "QRCodeDetectorAruco_Params":
code_decl += " QRCodeDetectorAruco::Params %s=%s;\n" % (a.name, defval)
elif arg_type_info.atype == "aruco_DetectorParameters":
code_decl += " aruco::DetectorParameters %s=%s;\n" % (a.name, defval)
else:
if arg_type_info.atype == "FileStorage" or (underscore_type in all_classes and all_classes[underscore_type].issimple is False):
code_decl += " Ptr<%s> ptr_%s;\n" % (arg_type_info.atype, a.name,)
Expand All @@ -342,6 +346,10 @@ def gen_code(self, codegen):
if arg_type_info.atype == "FileStorage" or (underscore_type in all_classes and all_classes[underscore_type].issimple is False):
code_decl += " Ptr<%s> ptr_%s;\n" % (arg_type_info.atype, a.name)
code_from_ptr += " %s %s; if (ptr_%s.get()) { %s = *ptr_%s.get(); }\n " % (arg_type_info.atype, a.name, a.name, a.name, a.name)
elif arg_type_info.atype == "QRCodeDetectorAruco_Params":
code_decl += " QRCodeDetectorAruco::Params %s;\n" % (a.name,)
elif arg_type_info.atype == "aruco_DetectorParameters":
code_decl += " aruco::DetectorParameters %s;\n" % (a.name,)
else:
code_decl += " %s %s;\n" % (arg_type_info.atype, a.name)

Expand Down
20 changes: 19 additions & 1 deletion py_src/hdr_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@ def parse_class_decl(self, decl_str):
if "CV_EXPORTS_W_SIMPLE" in l:
l = l.replace("CV_EXPORTS_W_SIMPLE", "")
modlist.append("/Simple")
if "CV_EXPORTS_W_PARAMS" in l:
l = l.replace("CV_EXPORTS_W_PARAMS", "")
modlist.append("/Map")
modlist.append("/Params")
npos = l.find("CV_EXPORTS_AS")
if npos < 0:
npos = l.find('CV_WRAP_AS')
Expand Down Expand Up @@ -393,6 +397,7 @@ def parse_func_decl(self, decl_str, mat="Mat", docstring=""):
[~]<function_name>
(<arg_type1> <arg_name1>[=<default_value1>] [, <arg_type2> <arg_name2>[=<default_value2>] ...])
[const] {; | <function_body>}
Returns the function declaration entry:
[<func name>, <return value C-type>, <list of modifiers>, <list of arguments>, <original return type>, <docstring>] (see above)
"""
Expand Down Expand Up @@ -611,6 +616,8 @@ def parse_func_decl(self, decl_str, mat="Mat", docstring=""):
("InputOutputArray", mat),
("OutputArray", mat),
("noArray", arg_type)]).strip()
if '/IO' in modlist and '/O' in modlist:
modlist.remove('/O')
args.append([arg_type, arg_name, defval, modlist])
npos = arg_start-1

Expand All @@ -628,12 +635,14 @@ def parse_func_decl(self, decl_str, mat="Mat", docstring=""):
def get_dotted_name(self, name):
"""
adds the dot-separated container class/namespace names to the bare function/class name, e.g. when we have
namespace cv {
class A {
public:
f(int);
};
}
the function will convert "A" to "cv.A" and "f" to "cv.A.f".
"""
if not self.block_stack:
Expand Down Expand Up @@ -661,6 +670,7 @@ class A {
def parse_stmt(self, stmt, end_token, mat="Mat", docstring=""):
"""
parses the statement (ending with ';' or '}') or a block head (ending with '{')
The function calls parse_class_decl or parse_func_decl when necessary. It returns
<block_type>, <block_name>, <parse_flag>, <declaration>
where the first 3 values only make sense for blocks (i.e. code blocks, namespaces, classes, enums and such)
Expand Down Expand Up @@ -772,7 +782,15 @@ def parse_stmt(self, stmt, end_token, mat="Mat", docstring=""):
var_list = [var_name1] + [i.strip() for i in var_list[1:]]

for v in var_list:
class_decl[3].append([var_type, v, "", var_modlist])
prop_definition = v.split('=')
prop_name = prop_definition[0].strip()
if len(prop_definition) == 1:
# default value is not provided
prop_default_value = ''
else:
prop_default_value = prop_definition[-1]
class_decl[3].append([var_type, prop_name, prop_default_value,
var_modlist])
return stmt_type, "", False, None

# something unknown
Expand Down
Loading

0 comments on commit 3f04a87

Please sign in to comment.