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

Ported VAS OT into OpenCV G-API #24224

Merged

Conversation

AsyaPronina
Copy link
Contributor

@AsyaPronina AsyaPronina commented Sep 5, 2023

Merge with extra: opencv/opencv_extra#1123

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
  • The PR is proposed to the proper branch
  • There is a reference to the original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

! There is known flaw in the code: usage of KalmanFilterNoOpencv class. This should be reworked to use OpenCV version or just refactored. !

! Link to the original implementation is: ttps://github.com/dlstreamer/dlstreamer/tree/master/src/monolithic/gst/elements/gvatrack/vas

@asmorkalov
Copy link
Contributor

@AsyaPronina Thanks a lot for the patch. Couple of general notes:

  • There is conflict in the module CMake.
  • Please add referemce to original implementation.
  • There are no tests for both C++ and Python.

@asmorkalov asmorkalov added pr: needs test New functionality requires minimal tests set category: g-api / gapi labels Sep 5, 2023
@dmatveev dmatveev self-assigned this Sep 5, 2023
@dmatveev dmatveev added this to the 4.9.0 milestone Sep 5, 2023
@AsyaPronina
Copy link
Contributor Author

@AsyaPronina Thanks a lot for the patch. Couple of general notes:

  • There is conflict in the module CMake.
  • Please add referemce to original implementation.
  • There are no tests for both C++ and Python.

Hello! Thank you a lot for the comments!
Here is the reference to the original implementation: https://github.com/dlstreamer/dlstreamer/tree/master/gst/elements/gvatrack/vas

I will fix conflict and add tests!

Copy link
Contributor

@dmatveev dmatveev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it would make sense to move the entire VAS OT algorithm itself into ./3rdparty (as-is), and only keep G-API-related integration code within the modules/gapi.

@@ -65,6 +65,7 @@ file(GLOB gapi_ext_hdrs
"${CMAKE_CURRENT_LIST_DIR}/include/opencv2/${name}/streaming/gstreamer/*.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/opencv2/${name}/streaming/onevpl/*.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/opencv2/${name}/plaidml/*.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/opencv2/${name}/ported_algorithms/ot/*.hpp"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't name folders like that.

Note that public include headers is part of the public API. It is not user's concern if the OT algorithm is "ported" or not.

OT's domain is streaming, so I'd assume users to include opencv2/gapi/streaming/ot.hpp (or may be /ot/vasot.hpp, if multiple OT flavors are possible).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot, fixed!

@@ -190,6 +191,19 @@ set(gapi_srcs
src/backends/ov/bindings_ov.cpp
src/backends/python/gpythonbackend.cpp

# VAS Object Tracking ported algorithm:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't distinguish it as a "ported algorithm" please. src/streaming/ot would be enough.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot, fixed!

@AsyaPronina AsyaPronina force-pushed the asyadev/port_vas_ot_to_opencv branch 14 times, most recently from ca0930b to 0562e76 Compare September 11, 2023 14:16
@AsyaPronina
Copy link
Contributor Author

Hello Dear Alexander (@asmorkalov)!
We wanted to move internal VAS OT implementation into OpenCV 3rdparty, however, it turned out that VAS OT implementation depends on OpenCV itself: >5 algorithms work through cv::Mat.

Could we please ask for your advice on better place for VAS object tracking algorithm? Is it OpenCV video module or might be OpenCV g-api own 3rdparty component?

CC: Dmitry (@dmatveev).

@asmorkalov
Copy link
Contributor

Sounds interesting! Will take a look how can I help you.

@@ -0,0 +1,233 @@
// This file is part of OpenCV project.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This header must be moved. ported_algorithms shouldn't be there

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I have already got rid from "ported_algorithms"! However, refactored implementation isn't on review yet, as I am transferring from common 3rdparty to G-API as a draft version.

@AsyaPronina AsyaPronina force-pushed the asyadev/port_vas_ot_to_opencv branch 2 times, most recently from 82af648 to 53baf8f Compare November 16, 2023 12:37
Copy link
Contributor

@dmatveev dmatveev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 but with comments

@@ -383,10 +385,12 @@ if(HAVE_ONNX)
endif()
endif()

add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/3rdparty/vasot ${CMAKE_CURRENT_BINARY_DIR}/3rdparty/vasot)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why

${CMAKE_CURRENT_BINARY_DIR}/3rdparty/vasot

needs to be added?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One IOS build is failing: https://github.com/opencv/opencv/actions/runs/6937152923/job/18870654308?pr=24224#step:7:297

CMake Error at modules/gapi/CMakeLists.txt:388 (add_subdirectory):
  add_subdirectory not given a binary directory but the given source
  directory
  "/Users/opencv-cn/GHA-OCV-1/_work/opencv/opencv/opencv/modules/gapi/3rdparty/vasot"
  is not a subdirectory of
  "/Users/opencv-cn/GHA-OCV-1/_work/opencv/opencv/opencv/modules/world".
  When specifying an out-of-tree source a binary directory must be explicitly
  specified.
Call Stack (most recent call first):
  modules/world/CMakeLists.txt:13 (include)
  modules/world/CMakeLists.txt:32 (include_one_module)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically it means the static build may be broken because of that.. but what makes OT different from any other source-level subdirectory in this case?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if..

  1. You move gapi/3rdparty under gapi/src/3rdparty?
  2. You remove all the CMakeListst.txt from the VAS OT
  3. You just add gapi/src/3rdparty/include to the INCLUDE directories for the opencv_gapi target?

In this case the OT code will be indistinguishable from the rest adn wouldn't require any special handling. There's literally no point in having a separate build target for that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot, fixed!

@AsyaPronina AsyaPronina mentioned this pull request Nov 22, 2023
6 tasks
@AsyaPronina AsyaPronina force-pushed the asyadev/port_vas_ot_to_opencv branch 2 times, most recently from 6f85ec4 to 89c275b Compare November 22, 2023 16:35
@AsyaPronina
Copy link
Contributor Author

Hello Dear Maxim (@mshabunin), could you please help to understand what can be the issue here:

**> Task :face-detection:lintVitalAnalyzeRelease FAILED**
2023-11-22T18:12:13.7269628Z Transforming FakeDependency.jar with D8BackportedMethodsGenerator
2023-11-22T18:12:13.7270207Z Invalidating in-memory cache of /home/ci/.gradle/caches/journal-1/file-access.bin
2023-11-22T18:12:13.7270863Z Caching disabled for D8BackportedMethodsGenerator: /home/ci/.gradle/android/FakeDependency.jar because:
2023-11-22T18:12:13.7271072Z   Build cache is disabled
2023-11-22T18:12:13.7271882Z Skipping D8BackportedMethodsGenerator: /home/ci/.gradle/android/FakeDependency.jar as it is up-to-date.
2023-11-22T18:12:13.7271894Z 
2023-11-22T18:12:13.7272328Z > Transform classes.jar (project :opencv) with DexingWithClasspathTransform
2023-11-22T18:12:13.7272784Z Transforming classes.jar (project :opencv) with DexingWithClasspathTransform
2023-11-22T18:12:13.7273406Z Invalidating in-memory cache of /home/ci/.gradle/caches/7.6.3/fileHashes/fileHashes.bin
2023-11-22T18:12:13.7274111Z Invalidating in-memory cache of /home/ci/.gradle/caches/7.6.3/fileHashes/resourceHashesCache.bin
2023-11-22T18:12:13.7275312Z Caching disabled for DexingWithClasspathTransform: /home/ci/build/o4a/opencv_android/opencv/build/intermediates/runtime_library_classes_jar/release/classes.jar because:
2023-11-22T18:12:13.7275469Z   Build cache is disabled
2023-11-22T18:12:13.7276828Z DexingWithClasspathTransform: /home/ci/build/o4a/opencv_android/opencv/build/intermediates/runtime_library_classes_jar/release/classes.jar is not up-to-date because:
2023-11-22T18:12:13.7278182Z   Output property 'outputDirectory' file /home/ci/build/o4a/opencv_android/opencv/build/.transforms/00b108fd5e596271628ea4c14fa64f1f/transformed has been removed.
2023-11-22T18:12:13.7279522Z   Output property 'outputDirectory' file /home/ci/build/o4a/opencv_android/opencv/build/.transforms/00b108fd5e596271628ea4c14fa64f1f/transformed/classes has been removed.
2023-11-22T18:12:13.7281018Z   Output property 'outputDirectory' file /home/ci/build/o4a/opencv_android/opencv/build/.transforms/00b108fd5e596271628ea4c14fa64f1f/transformed/classes/classes.dex has been removed.
2023-11-22T18:12:13.7282313Z The input changes require a full rebuild for incremental DexingWithClasspathTransform: /home/ci/build/o4a/opencv_android/opencv/build/intermediates/runtime_library_classes_jar/release/classes.jar.
2023-11-22T18:12:13.7283116Z Invalidating in-memory cache of /home/ci/build/o4a/opencv_android/.gradle/7.6.3/fileHashes/fileHashes.bin
2023-11-22T18:12:13.7283945Z Invalidating in-memory cache of /home/ci/build/o4a/opencv_android/.gradle/7.6.3/fileHashes/resourceHashesCache.bin
2023-11-22T18:12:13.7284715Z Invalidating in-memory cache of /home/ci/build/o4a/opencv_android/.gradle/buildOutputCleanup/outputFiles.bin
2023-11-22T18:12:13.7285033Z AAPT2 aapt2-7.3.1-8691043-linux Daemon #0: shutdown
2023-11-22T18:12:13.7285041Z 
2023-11-22T18:12:13.7285219Z FAILURE: Build failed with an exception.
2023-11-22T18:12:13.7285227Z 
2023-11-22T18:12:13.7285352Z !!!!!!!! * What went wrong:
2023-11-22T18:12:13.7285813Z Execution failed for task ':face-detection:lintVitalAnalyzeRelease'.
2023-11-22T18:12:13.7286415Z > Could not resolve all files for configuration ':face-detection:releaseRuntimeClasspath'.
2023-11-22T18:12:13.7289327Z    > Failed to transform out.aar (project :opencv) to match attributes {artifactType=android-lint-exploded-aar, com.android.build.api.attributes.AgpVersionAttr=7.3.1, com.android.build.api.attributes.BuildTypeAttr=release, com.android.build.gradle.internal.attributes.VariantAttr=release, org.gradle.usage=java-runtime, org.jetbrains.kotlin.platform.type=androidJvm}.
2023-11-22T18:12:13.7289744Z       > Cannot snapshot output property 'outputDirectory'.
2023-11-22T18:12:13.7289753Z !!!!!!!!

@smirnov-alexey
Copy link
Contributor

@asmorkalov @mshabunin can we merge it? The issue with android build seems not related to this PR:

2023-11-22T18:05:00.1357764Z Compilation with Kotlin compile daemon was not successful
2023-11-22T18:05:00.1359297Z java.lang.RuntimeException: java.util.concurrent.ExecutionException: java.lang.NoClassDefFoundError: Could not initialize class org.jetbrains.kotlin.com.intellij.util.io.FileChannelUtil
...
2023-11-22T18:05:00.1641074Z Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.jetbrains.kotlin.com.intellij.util.io.FileChannelUtil
2023-11-22T18:05:00.1642110Z 	at org.jetbrains.kotlin.com.intellij.util.io.ReadWriteDirectBufferWrapper$FileContext$1.execute(ReadWriteDirectBufferWrapper.java:59)
2023-11-22T18:05:00.1643207Z 	at org.jetbrains.kotlin.com.intellij.util.io.ReadWriteDirectBufferWrapper$FileContext$1.execute(ReadWriteDirectBufferWrapper.java:49)
2023-11-22T18:05:00.1643999Z 	at org.jetbrains.kotlin.com.intellij.openapi.util.io.FileUtilRt.doIOOperation(FileUtilRt.java:957)
2023-11-22T18:05:00.1644997Z 	at org.jetbrains.kotlin.com.intellij.util.io.ReadWriteDirectBufferWrapper$FileContext.<init>(ReadWriteDirectBufferWrapper.java:49)
2023-11-22T18:05:00.1646008Z 	at org.jetbrains.kotlin.com.intellij.util.io.ReadWriteDirectBufferWrapper.create(ReadWriteDirectBufferWrapper.java:35)
2023-11-22T18:05:00.1646734Z 	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
2023-11-22T18:05:00.1647121Z 	... 3 more
2023-11-22T18:05:00.1651397Z Caused by: java.lang.ExceptionInInitializerError: Exception java.lang.AssertionError: symbolic reference class is not accessible: class sun.nio.ch.FileChannelImpl, from class org.jetbrains.kotlin.com.intellij.util.io.FileChannelUtil (unnamed module @5c130274) [in thread "DirectBufferWrapper allocation thread"]
2023-11-22T18:05:00.1652800Z 	at org.jetbrains.kotlin.com.intellij.openapi.diagnostic.DefaultLogger.error(DefaultLogger.java:53)
2023-11-22T18:05:00.1653790Z 	at org.jetbrains.kotlin.com.intellij.openapi.diagnostic.Logger.error(Logger.java:169)
2023-11-22T18:05:00.1655362Z 	at org.jetbrains.kotlin.com.intellij.util.io.FileChannelUtil.setupUnInterruptibleHandle(FileChannelUtil.java:43)
2023-11-22T18:05:00.1656475Z 	at org.jetbrains.kotlin.com.intellij.util.io.FileChannelUtil.<clinit>(FileChannelUtil.java:18)
2023-11-22T18:05:00.1656725Z 	... 9 more

@AsyaPronina
Copy link
Contributor Author

@asmorkalov @mshabunin can we merge it? The issue with android build seems not related to this PR:

2023-11-22T18:05:00.1357764Z Compilation with Kotlin compile daemon was not successful
2023-11-22T18:05:00.1359297Z java.lang.RuntimeException: java.util.concurrent.ExecutionException: java.lang.NoClassDefFoundError: Could not initialize class org.jetbrains.kotlin.com.intellij.util.io.FileChannelUtil
...
2023-11-22T18:05:00.1641074Z Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.jetbrains.kotlin.com.intellij.util.io.FileChannelUtil
2023-11-22T18:05:00.1642110Z 	at org.jetbrains.kotlin.com.intellij.util.io.ReadWriteDirectBufferWrapper$FileContext$1.execute(ReadWriteDirectBufferWrapper.java:59)
2023-11-22T18:05:00.1643207Z 	at org.jetbrains.kotlin.com.intellij.util.io.ReadWriteDirectBufferWrapper$FileContext$1.execute(ReadWriteDirectBufferWrapper.java:49)
2023-11-22T18:05:00.1643999Z 	at org.jetbrains.kotlin.com.intellij.openapi.util.io.FileUtilRt.doIOOperation(FileUtilRt.java:957)
2023-11-22T18:05:00.1644997Z 	at org.jetbrains.kotlin.com.intellij.util.io.ReadWriteDirectBufferWrapper$FileContext.<init>(ReadWriteDirectBufferWrapper.java:49)
2023-11-22T18:05:00.1646008Z 	at org.jetbrains.kotlin.com.intellij.util.io.ReadWriteDirectBufferWrapper.create(ReadWriteDirectBufferWrapper.java:35)
2023-11-22T18:05:00.1646734Z 	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
2023-11-22T18:05:00.1647121Z 	... 3 more
2023-11-22T18:05:00.1651397Z Caused by: java.lang.ExceptionInInitializerError: Exception java.lang.AssertionError: symbolic reference class is not accessible: class sun.nio.ch.FileChannelImpl, from class org.jetbrains.kotlin.com.intellij.util.io.FileChannelUtil (unnamed module @5c130274) [in thread "DirectBufferWrapper allocation thread"]
2023-11-22T18:05:00.1652800Z 	at org.jetbrains.kotlin.com.intellij.openapi.diagnostic.DefaultLogger.error(DefaultLogger.java:53)
2023-11-22T18:05:00.1653790Z 	at org.jetbrains.kotlin.com.intellij.openapi.diagnostic.Logger.error(Logger.java:169)
2023-11-22T18:05:00.1655362Z 	at org.jetbrains.kotlin.com.intellij.util.io.FileChannelUtil.setupUnInterruptibleHandle(FileChannelUtil.java:43)
2023-11-22T18:05:00.1656475Z 	at org.jetbrains.kotlin.com.intellij.util.io.FileChannelUtil.<clinit>(FileChannelUtil.java:18)
2023-11-22T18:05:00.1656725Z 	... 9 more

Dear Alexander (@asmorkalov), could you please take a look?

@dmatveev
Copy link
Contributor

Github actions are all passed, isnt it?

@AsyaPronina
Copy link
Contributor Author

Github actions are all passed, isnt it?

Hello Dear Dmitry! There was an issue with default build, but rebase fixed it!

@AsyaPronina AsyaPronina removed the pr: needs test New functionality requires minimal tests set label Dec 1, 2023
@AsyaPronina
Copy link
Contributor Author

Dear Alexander (@asmorkalov), all builds are green and test is added, could I please ask you to merge?

@mshabunin
Copy link
Contributor

We try to add licenses for all 3rdparty components to the install set. For this you need to add license text file somewhere and call ocv_install_3rdparty_licenses in related cmake script (https://github.com/search?q=repo%3Aopencv%2Fopencv+ocv_install_3rdparty_licenses&type=code).

@dmatveev
Copy link
Contributor

dmatveev commented Dec 1, 2023

@mshabunin I believe it is published here under the Apache 2 license, same as OpenCV. Do we need to do anything in this case?

@mshabunin
Copy link
Contributor

I mean code in 3rdparty/vasot. As I understand it has been ported mostly unchanged from DLStreamer (MIT license).

@AsyaPronina
Copy link
Contributor Author

I mean code in 3rdparty/vasot. As I understand it has been ported mostly unchanged from DLStreamer (MIT license).
Hello Dear Maxim (@mshabunin)! Could I please ask some questions about this activity?

If build this **3rdparty/vasot** as part of G-API module as part of G-API own sources, without any separate CMakeLists.txt or add_library call, what library should be used to install LICENSE? Should we install license in this case?

If yes, should we change 3rdparty/vasot to be built as separate target?
Should we also change files headers to use license header for MIT?

@mshabunin
Copy link
Contributor

If build this 3rdparty/vasot as part of G-API module as part of G-API own sources, without any separate CMakeLists.txt or add_library call, what library should be used to install LICENSE? Should we install license in this case?

This is not necessary, for example we have SoftFloat library included into core module:

If yes, should we change 3rdparty/vasot to be built as separate target?

No, AFAIK MIT license doesn't forbid current usage form.

Should we also change files headers to use license header for MIT?

I'm not sure. It might depend on specific license requirements. I'd recommend consulting with legal expert. The MIT license says: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 🤷

@AsyaPronina
Copy link
Contributor Author

If build this 3rdparty/vasot as part of G-API module as part of G-API own sources, without any separate CMakeLists.txt or add_library call, what library should be used to install LICENSE? Should we install license in this case?

This is not necessary, for example we have SoftFloat library included into core module:

If yes, should we change 3rdparty/vasot to be built as separate target?

No, AFAIK MIT license doesn't forbid current usage form.

Should we also change files headers to use license header for MIT?

I'm not sure. It might depend on specific license requirements. I'd recommend consulting with legal expert. The MIT license says: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 🤷

Thank you a lot!!

@dmatveev
Copy link
Contributor

dmatveev commented Dec 4, 2023

@asmorkalov @mshabunin it is ready for merge now, is there anything else required?

Copy link
Contributor

@mshabunin mshabunin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No objections from my side.

Just one note: resulting installed license file will be named vasot-vasot_LICENSE.txt because that cmake function prepends component name to the file name.

@AsyaPronina
Copy link
Contributor Author

No objections from my side.

Just one note: resulting installed license file will be named vasot-vasot_LICENSE.txt because that cmake function prepends component name to the file name.

Thank you a lot, fixed!

@AsyaPronina
Copy link
Contributor Author

Dear Alexander (@asmorkalov) and Alexander (@opencv-alalek), could you please merge?

@opencv-pushbot opencv-pushbot merged commit 850ebec into opencv:4.x Dec 8, 2023
26 checks passed
@asmorkalov asmorkalov mentioned this pull request Jan 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants