experiments/opencv_trail_effect.git
13 months agoopencv_trail_effect.cpp: set window size and title master
Antonio Ospite [Sat, 10 Oct 2020 20:10:39 +0000 (22:10 +0200)]
opencv_trail_effect.cpp: set window size and title

Set window size and title to make the interaction a little nicer.

13 months agoopencv_trail_effect.cpp: hardcode V4L2 VideoCapture backend on linux
Antonio Ospite [Sat, 10 Oct 2020 19:57:45 +0000 (21:57 +0200)]
opencv_trail_effect.cpp: hardcode V4L2 VideoCapture backend on linux

Hardcode the V4L2 backend on linux for now because the GStreamer one
lacks some functionality, see:
https://github.com/opencv/opencv/issues/18562

13 months agoopencv_trail_effect.cpp: fix potential leak when exiting during option parsing
Antonio Ospite [Sat, 10 Oct 2020 17:38:10 +0000 (19:38 +0200)]
opencv_trail_effect.cpp: fix potential leak when exiting during option parsing

When bailing out during option parsingi, for example when '-h' or an
invalid option is passed, some pointer to strings were not cleaned up,
leading to a potential leak, as reported by scan-build:

-----------------------------------------------------------------------
opencv_trail_effect.cpp:120:4: warning: Potential leak of memory pointed to by 'drawing_method'
                        usage(argv[0]);
                        ^~~~~
opencv_trail_effect.cpp:120:4: warning: Potential leak of memory pointed to by 'input_file'
                        usage(argv[0]);
                        ^~~~~
opencv_trail_effect.cpp:120:4: warning: Potential leak of memory pointed to by 'output_file'
                        usage(argv[0]);
                        ^~~~~
opencv_trail_effect.cpp:120:4: warning: Potential leak of memory pointed to by 'segmentation_method'
                        usage(argv[0]);
                        ^~~~~
opencv_trail_effect.cpp:123:4: warning: Potential leak of memory pointed to by 'drawing_method'
                        usage(argv[0]);
                        ^~~~~
opencv_trail_effect.cpp:123:4: warning: Potential leak of memory pointed to by 'segmentation_method'
                        usage(argv[0]);
                        ^~~~~
-----------------------------------------------------------------------

Stop using pointers to strings which really give no benefits in this
case and avoid the issue altogether.

13 months agoMakefile: add a target for an "accumulate" effect
Antonio Ospite [Sat, 10 Oct 2020 17:08:57 +0000 (19:08 +0200)]
Makefile: add a target for an "accumulate" effect

Add a Makefile target for an "accumulate" effect based on threshold, it
can be handy for light painting with LEDs.

13 months agoMakefile: ignore warnings in OpenCV headers
Antonio Ospite [Sat, 10 Oct 2020 17:01:56 +0000 (19:01 +0200)]
Makefile: ignore warnings in OpenCV headers

OpenCV header files were triggering a lot of warnings because of the
strict compiler flags set for the project.

Instead of disabling the warnings treat the OpenCV headers as system
dependencies, this way the compiler will ignore warnings on them but
will still apply the warnings to the project code.

13 months agoPort to OpenCV4 and use the C++ API for everything
Antonio Ospite [Sat, 10 Oct 2020 16:47:04 +0000 (18:47 +0200)]
Port to OpenCV4 and use the C++ API for everything

3 years agoopencv_trail_effect.cpp: make the window resizeable
Antonio Ospite [Fri, 23 Feb 2018 09:43:25 +0000 (10:43 +0100)]
opencv_trail_effect.cpp: make the window resizeable

3 years agoREADME: mention some more video where the effect is used
Antonio Ospite [Thu, 22 Feb 2018 10:30:27 +0000 (11:30 +0100)]
README: mention some more video where the effect is used

3 years agoTODO: mention that there are new background subtraction methods available
Antonio Ospite [Thu, 22 Feb 2018 12:07:39 +0000 (13:07 +0100)]
TODO: mention that there are new background subtraction methods available

3 years agoopencv_trail_effect.cpp: fix showing the background
Antonio Ospite [Thu, 22 Feb 2018 12:12:04 +0000 (13:12 +0100)]
opencv_trail_effect.cpp: fix showing the background

When showing the background OpenCV would fail with this message:

  OpenCV Error: Assertion failed (channels() == CV_MAT_CN(dtype)) in copyTo, file /build/opencv-lY8WRY/opencv-3.2.0+dfsg/modules/core/src/copy.cpp, line 259
  terminate called after throwing an instance of 'cv::Exception'
    what():  /build/opencv-lY8WRY/opencv-3.2.0+dfsg/modules/core/src/copy.cpp:259: error: (-215) channels() == CV_MAT_CN(dtype) in function copyTo

Initializing the background to the same format of the input frame seems
to fix this.

3 years agoopencv_trail_effect.cpp: use cv::waitKeyEx() instead of cv::waitKey()
Antonio Ospite [Thu, 22 Feb 2018 11:56:50 +0000 (12:56 +0100)]
opencv_trail_effect.cpp: use cv::waitKeyEx() instead of cv::waitKey()

In some OpenCV 3 version there was a change of behavior of cv::waitKey()
in case the delay expired with no key presses, use cv::waitKeyEx() to
rely on the old behavior.

For details see
https://github.com/opencv/opencv/pull/7866#issuecomment-269322846

3 years agoSegmentation.hpp: adapt the code to OpenCV 3
Antonio Ospite [Thu, 22 Feb 2018 14:15:48 +0000 (15:15 +0100)]
Segmentation.hpp: adapt the code to OpenCV 3

In OpenCV 3 the public cv::BackgroundSubtractorMOG2() is now abstract so
we cannot inherit directly from it.

The concrete class would be BackgroundSubtractorMOG2Imp from
modules/video/src/bgfg_gaussmix2.cpp but it is private so we cannot
inherit from it either.

Use the factory method as documented to get a cv::BackgroundSubtractor
instance of the desired type and use is as a property in the
MOG2Segmentation class.

3 years agoMakefile: fix detecting the compiler
Antonio Ospite [Thu, 22 Feb 2018 10:27:53 +0000 (11:27 +0100)]
Makefile: fix detecting the compiler

Rely on the compiler version, to behave "more correctly" in case CXX is
just c++.

6 years agoMakefile: fix warnings when linking with clang++
Antonio Ospite [Thu, 22 Oct 2015 09:33:30 +0000 (11:33 +0200)]
Makefile: fix warnings when linking with clang++

Clang ignores some options during linkage and warns about it:

  clang: warning: argument unused during compilation: '-ansi'
  clang: warning: argument unused during compilation: '-Wp,-D_FORTIFY_SOURCE=2'

Add -Qunused-arguments to LDFLAGS to suppress the warnings.

6 years agoFix a compilation error when using clang++
Antonio Ospite [Thu, 22 Oct 2015 09:11:37 +0000 (11:11 +0200)]
Fix a compilation error when using clang++

Clang gives this error:

  In file included from opencv_trail_effect.cpp:25:
  ./Trail.hpp:13:22: error: in-class initialization of non-static data member is a C++11 extension [-Werror,-Wc++11-extensions]
          cv::Mat *background = NULL;
                              ^
  1 error generated.
  <builtin>: recipe for target 'opencv_trail_effect.o' failed
  make: *** [opencv_trail_effect.o] Error 1

Fix it to make compilation succeed.

6 years agoMakefile: fix warnings when compiling with clang++
Antonio Ospite [Thu, 22 Oct 2015 09:06:31 +0000 (11:06 +0200)]
Makefile: fix warnings when compiling with clang++

Clang does not support some options and gives warnings:

  warning: unknown warning option '-Wunsafe-loop-optimizations';
  warning: unknown warning option '-Wunused-but-set-variable';

So add them only when the compiler is not clang.

6 years agoMakefile: split compilation and linkage
Antonio Ospite [Thu, 22 Oct 2015 08:42:01 +0000 (10:42 +0200)]
Makefile: split compilation and linkage

This fixes an error when compiling with clang++:

  clang: error: cannot specify -o when generating multiple output files
  <builtin>: recipe for target 'opencv_trail_effect' failed
  make: *** [opencv_trail_effect] Error 1

The error happens because in this Makefile header files are in the
target dependencies, so they are added to the compilation command, but
clang does not support that when compiling and linking in the same
command.

Also take care of using LIKN.cpp to link the program, as it is a C++
program.

6 years agoREADME: fix a typo s/has showed/has shown/
Antonio Ospite [Thu, 1 Oct 2015 10:37:57 +0000 (12:37 +0200)]
README: fix a typo s/has showed/has shown/

6 years agoREADME: make the sentence about segmentation methods more specific
Antonio Ospite [Thu, 1 Oct 2015 10:36:47 +0000 (12:36 +0200)]
README: make the sentence about segmentation methods more specific

6 years agoREADME: add a link to the video showing the example trails
Antonio Ospite [Thu, 1 Oct 2015 08:04:44 +0000 (10:04 +0200)]
README: add a link to the video showing the example trails

6 years agoREADME: improve the description of requirements for a decent effect
Antonio Ospite [Thu, 1 Oct 2015 08:03:54 +0000 (10:03 +0200)]
README: improve the description of requirements for a decent effect

6 years agoREADME: improve wording about segmentation
Antonio Ospite [Thu, 1 Oct 2015 08:02:37 +0000 (10:02 +0200)]
README: improve wording about segmentation

6 years agoInitial import
Antonio Ospite [Mon, 28 Sep 2015 21:21:46 +0000 (23:21 +0200)]
Initial import