Skip to content
Snippets Groups Projects

Compile opencv modules in C++ mode, detect OpenCV4 pkgconfig

Open StefanBruens requested to merge StefanBruens/vlc:opencv4 into master

OpenCV has not supported compiling in C mode for quite some time, and even the remaining C API calls should be compiled in C++ mode. With OpenCV 4, compiling in C mode is no longer possible.

Compile the wrapper in C++ mode, and port the face detection example from the removed C API to its C++ equivalent.

Detect OpenCV 4 pkgconfig, and try fall back to OpenCV 3 when not found.

Tested with OpenCV 4.5.2 and 3.4.10.

This MR updates the code two work with current OpenCV versions. It does not change the behavior or the design of this module.

See #22016

Edited by StefanBruens

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
161 161 * We don't need to set up video formats for this filter as it not
162 162 * actually using a picture_t.
163 163 */
164 p_sys->p_opencv = vlc_object_create( p_filter, sizeof(filter_t) );
164 p_sys->p_opencv = static_cast<filter_t*>( vlc_object_create( p_filter, sizeof(filter_t) ) );
  • This should most likely use a dedicated type rather than filter_t.

    This leads to a rather questionable code, not to say invalid cast, in the Filter() function.

  • This part of the code is essentially unchanged.

    Which cast in the Filter() function is invalid in your opinion?

  • @Courmisch - please clarify.

  • I don't understand what you want clarified. There is literally only one cast in Filter().

  • There are two Filter functions in this MR. Is it really so much work to highlight the relevant code?

    Changing the signature would be an API/ABI break, and is not the scope of this MR.

  • I am referring to the same file. And in any case, both Filter() functions have the problem in symmetry anyhow.

  • So you wan't a different API/ABI between the wrapper and the actual filter, fine.

    But how is this related to porting the module to C++ for fixing compatibility with OpenCV 4?

    This is not about changing design, API/ABI or behavior.

  • There are no reasons to use filter_t here. The original developer was ostensibly just being lazy. Now this results what is at best a pair of very ugly casts.

    The thing is, this MR provides for C++ on both sides. Then, there not even reasons to use VLC C callbacks. You can just use a virtual class.

  • IMO it's out of the scope of this MR to change the ABI of opencv filters. It's debatable whether it should be changed and changed to what. But this is not what this MR is about and doesn't need to be changed in this MR.

  • Well if you've another decent way to fix the cast, I admit that you won't have to change the interface.

    However I am circumspect about the feasibility and the efficacy of such an hypothetical effort.

  • Please register or sign in to reply
  • Rémi Denis-Courmont
  • StefanBruens added 17 commits

    added 17 commits

    Compare with previous version

  • StefanBruens added 3 commits

    added 3 commits

    • e75f3dd3 - Compile opencv modules in C++ mode
    • 09b49c41 - Port OpenCV facedetect example to C++ API
    • 4df72637 - Also detect OpenCV 4 via pkgconfig

    Compare with previous version

  • Steve Lhomme
  • Steve Lhomme
  • Steve Lhomme
  • Steve Lhomme
  • Steve Lhomme
  • Steve Lhomme
  • Steve Lhomme
  • Thomas Guillem
  • Thomas Guillem
  • StefanBruens added 3 commits

    added 3 commits

    • 890b8a15 - opencv: Compile opencv modules in C++ mode
    • 6180d687 - opencv: Port OpenCV facedetect example to C++ API
    • d29b4c14 - opencv: Also detect OpenCV 4 via pkgconfig

    Compare with previous version

  • StefanBruens changed the description

    changed the description

    • Since you use an std::vector, you either need to define a custom allocator that will track memory allocation failures or use try/catch on every function manipulating the vector size. Otherwise the C++ exception will unwind in the C code. I don't know OpenCV well and I don't know if it applies there too or if you can pass your custom allocator to OpenCV, but I guess the same applies here unfortunately. :/

    • sidenote: if you go for the exception variant, writing extern "C" type function() try { } catch(std::bad_alloc){} function wrappers might be enough to solve the issue.

    • Please register or sign in to reply
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Please register or sign in to reply
    Loading