Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test OpenCV pre 4.9.0 #225

Merged
merged 5 commits into from
Dec 28, 2023
Merged
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
4 changes: 2 additions & 2 deletions .github/workflows/linux-x86_64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ jobs:
- uses: actions/checkout@v3
- name: Install system dependencies
run: |
apk add cmake make python3 bash curl unzip gcc g++ ncurses-dev openssl-dev linux-headers perl git dpkg
curl -fSL "https://repo.uwucocoa.moe/pool/main/erlang_${OTP_VERSION}_musl-linux-amd64.deb" -o "erlang_${OTP_VERSION}_musl-linux-amd64.deb"
apk add cmake make python3 bash curl unzip gcc g++ ncurses-dev openssl-dev linux-headers perl git dpkg ca-certificates
curl -fSL -k "https://repo.uwucocoa.moe/pool/main/erlang_${OTP_VERSION}_musl-linux-amd64.deb" -o "erlang_${OTP_VERSION}_musl-linux-amd64.deb"
dpkg -i "erlang_${OTP_VERSION}_musl-linux-amd64.deb"

- name: Install elixir
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ 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_GIT_REPO ?= "https://github.com/opencv/opencv_contrib.git"
OPENCV_CONTRIB_VER ?= 4.8.0
ifneq ($(OPENCV_CONTRIB_USE_GIT_HEAD), false)
OPENCV_CONTRIB_VER=$(OPENCV_CONTRIB_USE_GIT_BRANCH)
Expand Down
92 changes: 92 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,98 @@ config :evision, enabled_img_codecs: [
export OPENCV_GIT_REPO="https://github.com/username/opencv.git"
```

- How do I test for a new pre-release of OpenCV?

Suppose that OpenCV has a new pre-release (usually a new tagged version), 4.9.0, then you need
to do the following to test and maybe also add/change some lines so that the new version is
usable.

First of all, disable using precompiled binaries.

```shell
export EVISION_PREFER_PRECOMPILED=false
```

Then set to use source code from GitHub.

```shell
export OPENCV_USE_GIT_HEAD=true
export OPENCV_USE_GIT_BRANCH=4.9.0

export OPENCV_CONTRIB_USE_GIT_HEAD=true
export OPENCV_CONTRIB_USE_GIT_BRANCH=4.9.0
```

After that, we can try to build it. Usually, this is likely to fail without any changes to the source code
in the evision library. I'll mention possible fixes for that in a minute.

```shell
rm -rf _build/test/lib/evision
export MIX_ENV=test
iex -S mix
```

- Troubleshooting pre-release versions of OpenCV

1. unknown type name 'XXXXXXXX_Params'

When you see error messages like:

```
In file included from /home/runner/evision/c_src/evision.cpp:2373:
/home/runner/evision/c_src/evision_generated_funcs.h:3685:5: error: unknown type name 'TrackerVit_Params'
TrackerVit_Params parameters=TrackerVit::Params();
```

That usually means we need to copy some headers from OpenCV's source code for compatibilties. You can find
them in

```
3rd_party/opencv/opencv-${OPENCV_VER}/modules/${MODULE_NAME}/misc/python/
```

where `${OPENCV_VER}` is the version name and `${MODULE_NAME}` is the corresponding module of that `XXXXX_Params`.
To find the corresponding module of `XXXXX_Params`, one good way is to search the OpenCV source code. In this example, `TrackerVit` is in the `video` module:

```shell
$ cd 3rd_party/opencv/opencv-4.9.0/modules/
$ rg --no-ignore 'TrackerVit::Params'
video/src/tracking/tracker_vit.cpp
24:TrackerVit::Params::Params()
43: TrackerVitImpl(const TrackerVit::Params& parameters)
60: TrackerVit::Params params;
210:Ptr<TrackerVit> TrackerVit::create(const TrackerVit::Params& parameters)
216:Ptr<TrackerVit> TrackerVit::create(const TrackerVit::Params& parameters)

video/include/opencv2/video/tracking.hpp
914: @param parameters vit tracker parameters TrackerVit::Params
917: Ptr<TrackerVit> create(const TrackerVit::Params& parameters = TrackerVit::Params());

video/test/test_trackers.cpp
166: cv::TrackerVit::Params params;
```

However, as the time of writing, OpenCV's official source didn't add `TrackerVit::Params` to

```shell
3rd_party/opencv/opencv-4.9.0/modules/video/misc/python/pyopencv_video.hpp
```

So we can either say this pre-release version is not ready for evision, or we can simply add
some lines in evision's codebase to fix it. For this particular issue, we can edit this file:

```
c_src/evision_custom_headers/evision_video.hpp
```

and add the following lines to it.

```shell
#if (CV_VERSION_MAJOR >= 4 && CV_VERSION_MINOR >= 9)
typedef TrackerVit::Params TrackerVit_Params;
#endif
```

- How do I set the number of jobs for compiling?

```shell
Expand Down
4 changes: 4 additions & 0 deletions c_src/evision_custom_headers/evision_video.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@ typedef TrackerDaSiamRPN::Params TrackerDaSiamRPN_Params;
typedef TrackerNano::Params TrackerNano_Params;
#endif

#if (CV_VERSION_MAJOR >= 4 && CV_VERSION_MINOR >= 9)
typedef TrackerVit::Params TrackerVit_Params;
#endif

#endif
2 changes: 1 addition & 1 deletion py_src/func_variant.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ def generate_spec_elixir(self, module_func_name: str, is_instance_method: bool,
_, struct_name = is_struct(self.spec_self, also_get='struct_name', classname=self.classname)
self.spec_self = f'{struct_name}.t()'
else:
print(f'warning: {self.spec_self} should be a struct. classname={self.classname}')
print(f'warning: {self.spec_self} should be a struct. classname={self.classname}. possible fix: change function is_struct accordingly in helper.py.')
self.spec_self = f'Evision.{self.spec_self}.t()'
in_args_spec.insert(0, self.spec_self)

Expand Down
6 changes: 6 additions & 0 deletions py_src/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,8 @@ def is_struct(argtype: str, also_get: Optional[str] = None, classname: Optional[
"mcc_CChecker": "Evision.MCC.CCheckerDetector",
"dnn_Net": "Evision.DNN.Net",

"TrackerVit": "Evision.TrackerVit",

"BinaryDescriptor": "Evision.LineDescriptor.BinaryDescriptor",
"KeyLine": "Evision.LineDescriptor.BinaryDescriptor.KeyLine",
"BinaryDescriptorMatcher": "Evision.LineDescriptor.BinaryDescriptorMatcher",
Expand Down Expand Up @@ -1202,6 +1204,8 @@ def map_argtype_in_spec_erlang(classname: str, argtype: str, is_in: bool, decl:
return '#evision_ocl_device{}'
elif argtype == 'Index' and classname == 'flann_Index':
return '#evision_flann_index{}'
elif argtype == 'TrackerVit':
return '#evision_tracker_vit'
elif argtype == 'QRCodeDetectorAruco':
return '#evision_qrcode_detector_aruco{}'
elif argtype == 'QRCodeDetectorAruco_Params':
Expand Down Expand Up @@ -1302,6 +1306,8 @@ def map_argtype_in_spec_elixir(classname: str, argtype: str, is_in: bool, decl:
return 'Evision.OCL.Device.t()'
elif argtype == 'Index' and classname == 'flann_Index':
return 'Evision.Flann.Index.t()'
elif argtype == 'TrackerVit':
return 'Evision.TrackerVit'
elif argtype == 'QRCodeDetectorAruco':
return 'Evision.QRCodeDetectorAruco'
elif argtype in ['QRCodeDetectorAruco_Params', 'QRCodeDetectorAruco::Params']:
Expand Down
Loading