Skip to content

Added trackers factory with pre-loaded dnn models#26875

Merged
asmorkalov merged 3 commits intoopencv:4.xfrom
asmorkalov:as/in_memory_models
Feb 14, 2025
Merged

Added trackers factory with pre-loaded dnn models#26875
asmorkalov merged 3 commits intoopencv:4.xfrom
asmorkalov:as/in_memory_models

Conversation

@asmorkalov
Copy link
Copy Markdown
Contributor

@asmorkalov asmorkalov commented Feb 4, 2025

Replaces #26295

Allows to substitute custom models or initialize tracker from in-memory model.

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

@asmorkalov asmorkalov added this to the 4.12.0 milestone Feb 4, 2025
@asmorkalov asmorkalov force-pushed the as/in_memory_models branch 2 times, most recently from 3d18122 to 8b5a1ac Compare February 4, 2025 15:50
@asmorkalov asmorkalov added the RFC label Feb 5, 2025
@asmorkalov asmorkalov force-pushed the as/in_memory_models branch 3 times, most recently from f49819d to ecbd247 Compare February 6, 2025 10:31
@asmorkalov asmorkalov removed the RFC label Feb 7, 2025
@asmorkalov asmorkalov requested a review from dkurt February 7, 2025 09:23
@asmorkalov
Copy link
Copy Markdown
Contributor Author

@mshabunin @dkurt please take a look.

@asmorkalov
Copy link
Copy Markdown
Contributor Author

@mshabunin Please take a look again.

@mshabunin
Copy link
Copy Markdown
Contributor

I tried build with -DBUILD_opencv_dnn=OFF.

Looks like there are not enough dnn guards.

/opencv/modules/video/src/tracking/tracker_goturn.cpp:147:48: error: ‘dnn’ does not name a type
  147 | Ptr<TrackerGOTURN> TrackerGOTURN::create(const dnn::Net& model)
      |                                                ^~~
/opencv/modules/video/src/tracking/tracker_goturn.cpp:147:56: error: expected unqualified-id before ‘&’ token
  147 | Ptr<TrackerGOTURN> TrackerGOTURN::create(const dnn::Net& model)
      |                                                        ^
/opencv/modules/video/src/tracking/tracker_goturn.cpp:147:56: error: expected ‘)’ before ‘&’ token
  147 | Ptr<TrackerGOTURN> TrackerGOTURN::create(const dnn::Net& model)
      |                                         ~              ^
      |                                                        )
/opencv/modules/video/src/tracking/tracker_goturn.cpp:147:58: error: expected initializer before ‘model’
  147 | Ptr<TrackerGOTURN> TrackerGOTURN::create(const dnn::Net& model)
      |                                                          ^~~~~

Similar issue in other affected algorithms.

Perhaps some issues with python as well, but I'm not sure.

@asmorkalov
Copy link
Copy Markdown
Contributor Author

I fixed the issue related to pure C++ part. Java and Python bindings generator ignores #if HAVE_OPENCV_DNN for now. No chance for it right now.

@mshabunin
Copy link
Copy Markdown
Contributor

Since dnn is now in public interface of the video module I propose making video->dnn dependency "required" and removing #if HAVE_OPENCV_DNN conditions. In future we might move related algorithms into separate dnn_video (?) module and split dependencies accordingly.

Alternatively we can try to move dnn::Net to the core module (if possible just partially), so that it would be available for all modules.

@asmorkalov
Copy link
Copy Markdown
Contributor Author

I dig a bit in header parser and looks like we can add proper OPENCV_HAVE_ macro handling there:

if state == SCAN and l.startswith("#"):
. The same issue is relevant to FLANN. I'll submit another PR with a solution.

@asmorkalov asmorkalov merged commit ae25c31 into opencv:4.x Feb 14, 2025
27 of 28 checks passed
@asmorkalov asmorkalov mentioned this pull request Feb 19, 2025
NanQin555 pushed a commit to NanQin555/opencv that referenced this pull request Feb 24, 2025
Added trackers factory with pre-loaded dnn models opencv#26875

Replaces opencv#26295

Allows to substitute custom models or initialize tracker from in-memory model.

### Pull Request Readiness Checklist

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

- [x] I agree to contribute to the project under Apache 2 License.
- [x] 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
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.

2 participants