How to contribute an optimised LineSegmentDetector Algorithm? [closed]

asked 2015-09-01 10:07:43 -0500

_Christian_ gravatar image

updated 2015-09-02 01:59:06 -0500


colleagues of mine implemented this optimised LSD in a seperate project and we want to contribute an this version of the LineSegmentDetector algorithm back to the community. I'm in charge to bring this version of the Algorithm back into the OpenCV Repository via a PullRequest. I started with and cloned the repository in order to add the hopefully optimised Algorithm.

But i ran into Problems while trying to add the "new" LSD-Algorithm into the module "imgproc" where the "old" one resides. The new Algorithm needs to be compiled with "-std=c++11", but the OpenCV project isn't. That's because i'm running into errors.

In my Sandbox the files containing the optimised Algorithm are compiled as follows:

project( lsd_back_newImpl CXX )
cmake_minimum_required(VERSION 2.8)
set( CMAKE_CXX_FLAGS "-std=c++11 -Wall -pthread -Os -s" )

add_library( lsd_back_newImpl SHARED lsd_back_newImpl )
set_target_properties( lsd_back_newImpl PROPERTIES LINKER_LANGUAGE CXX )

This way i get a shared library that i could probably use from the opencv library compiled without -std=C++11.

In first place, i put the lsd_new.cpp into the modules/imgproc/src directory. If i put the lsd_back_newImpl.cpp to modules/imgproc/src it will be automatically compiled, but without the compile flag "-std=C++11".

The CMakeLists.txt of modules/imgproc "only" contains

set(the_description "Image Processing")
ocv_define_module(imgproc opencv_core WRAP java python)

How would i accomplish to compile all files in imgproc/* like before, except the lsd_new.cpp file and instead compiling this file with the different Compiler_Flags in order to add a shared library that is compiled with the required flags?

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by sturkmen
close date 2020-09-27 11:48:30.103634



oh, nice, new contributions ;)

(i'm not one of the devs there, but let me tell, what i've seen)

  • new functionality in 3.0 usually goes into the opencv_contrib repo, so you should try either to add it to ximgproc, or
  • maybe, if the c++11 dependant parts need seperation , even put it in an independant module.

(in general, the devs there seem to be quite hesitant to accept c++11 code at all. are there ways to avoid it ?)

berak gravatar imageberak ( 2015-09-02 00:21:19 -0500 )edit

Oh, didn't know about the OpenCV_contrib Repo. Thanks for that Info. I'll look there of course then.

in general, the devs there seem to be quite hesitant to accept c++11 code at all. are there ways to avoid it ? I doubt, that we can avoid it, because we made use of std::unique_ptr which requires C++11. As me colleagues told me, they've choosen it in order to stint the reference counter in order to speed up the algorithm. If nothing helps, we could still wait for OpenCV accepting C++11.

I'll examine this Repo and try to add it there. Thanks again.

_Christian_ gravatar image_Christian_ ( 2015-09-02 02:40:34 -0500 )edit

Hello @_Christian_ I am not sure how, but a couple of months ago I saw someone adding the possibility to enable C++11 standard in OpenCV in some PR. So if you create a seperate module, it might be possible to select the C++11 standard as a prerequisite for the model. @mshabunin do you maybe have any insights on this matter? ALSO big thumbs up for you guys contributing updated versions of algorithms!

StevenPuttemans gravatar imageStevenPuttemans ( 2015-09-02 08:29:53 -0500 )edit

I've discovered that cvv module is compiled with C++11 enabled but it also depends on Qt5 and is quite rarely used.

Please note that it is not a good idea to vary library interface depending on compiler flags. Probably you can add new algorithm to ximgproc module in opencv_contrib repository with fallback to current implementation in case when C++11 was not enabled, but this way might need new option to be added to cmake scripts. We will discuss this question in nearest future.

mshabunin gravatar imagemshabunin ( 2015-09-08 09:35:24 -0500 )edit

Hello _Christian_, I was wondering if by any chance you adapted your solution for the LineSegmentDetector in Python. Thank u !

ilas gravatar imageilas ( 2019-07-23 08:50:25 -0500 )edit