olena-2.0-53-gfcb3403 New app: camera stream processing (using OpenCV for capture).

* milena/apps/camera-process/camprocess.cc, * milena/apps/camera-process/process.hh, * milena/apps/camera-process/process.cc, * milena/apps/camera-process/Makefile.am: New. * milena/apps/Makefile.am (SUBDIRS): Add camera-process. --- milena/ChangeLog | 11 ++ milena/apps/Makefile.am | 5 +- .../Makefile.am | 29 ++++-- .../camera-process/camprocess.cc} | 109 ++++++++------------ milena/apps/camera-process/process.cc | 71 +++++++++++++ .../camera-process/process.hh} | 14 ++-- 6 files changed, 157 insertions(+), 82 deletions(-) copy milena/apps/{constrained-connectivity => camera-process}/Makefile.am (50%) copy milena/{sandbox/theo/mln/walue/rgb_3xn.hh => apps/camera-process/camprocess.cc} (50%) create mode 100644 milena/apps/camera-process/process.cc copy milena/{mln/extract/essential.hh => apps/camera-process/process.hh} (80%) diff --git a/milena/ChangeLog b/milena/ChangeLog index c1289de..77113b3 100644 --- a/milena/ChangeLog +++ b/milena/ChangeLog @@ -1,5 +1,16 @@ 2012-09-25 Roland Levillain <roland@lrde.epita.fr> + New app: camera stream processing (using OpenCV for capture). + + * milena/apps/camera-process/camprocess.cc, + * milena/apps/camera-process/process.hh, + * milena/apps/camera-process/process.cc, + * milena/apps/camera-process/Makefile.am: + New. + * milena/apps/Makefile.am (SUBDIRS): Add camera-process. + +2012-09-25 Roland Levillain <roland@lrde.epita.fr> + Fix file names in apps/morphers/recorder-bft. * apps/morphers/recorder-bft.cc, diff --git a/milena/apps/Makefile.am b/milena/apps/Makefile.am index 465f1db..30e5575 100644 --- a/milena/apps/Makefile.am +++ b/milena/apps/Makefile.am @@ -1,4 +1,4 @@ -# Copyright (C) 2008, 2009, 2011 EPITA Research and Development +# Copyright (C) 2008, 2009, 2011, 2012 EPITA Research and Development # Laboratory (LRDE). # # This file is part of Olena. @@ -19,5 +19,8 @@ # Applied examples of Milena. SUBDIRS = mesh-segm-skel graph-morpho constrained-connectivity morphers +# Video stream processing (using OpenCV for capture). +SUBDIRS += camera-process + # Examples from papers. SUBDIRS += papers diff --git a/milena/apps/constrained-connectivity/Makefile.am b/milena/apps/camera-process/Makefile.am similarity index 50% copy from milena/apps/constrained-connectivity/Makefile.am copy to milena/apps/camera-process/Makefile.am index c0dfb0d..7b05864 100644 --- a/milena/apps/constrained-connectivity/Makefile.am +++ b/milena/apps/camera-process/Makefile.am @@ -1,4 +1,4 @@ -# Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE). +# Copyright (C) 2012 EPITA Research and Development Laboratory (LRDE). # # This file is part of Olena. # @@ -14,17 +14,30 @@ # You should have received a copy of the GNU General Public License # along with Olena. If not, see <http://www.gnu.org/licenses/>. +# Camera stream processing. + # Find Milena headers. AM_CPPFLAGS = -I$(top_srcdir)/milena -I$(top_builddir)/milena -# Produce fast code. +# Produce fast code (by default). APPS_CXXFLAGS = @APPS_CXXFLAGS@ AM_CXXFLAGS = $(APPS_CXXFLAGS) -noinst_PROGRAMS = constrained-connectivity -constrained_connectivity_SOURCES = constrained-connectivity.cc -constrained_connectivity_CXXFLAGS = $(AM_CXXFLAGS) $(STRICT_ALIASING_CXXFLAGS) -TESTS = test-constrained-connectivity +if HAVE_OPENCV + +noinst_PROGRAMS = camprocess +camprocess_SOURCES = camprocess.cc +# Do not use optimization, as it does not seem to please OpenCV. +camprocess_CPPFLAGS = $(AM_CPPFLAGS) $(OPENCV_CPPFLAGS) +camprocess_CXXFLAGS = -O0 +camprocess_LDADD = libprocess.la +camprocess_LDFLAGS = $(AM_LDFLAGS) $(OPENCV_LDFLAGS) + +# Convenience library to compile process.cc with optimizations turned on. +noinst_LTLIBRARIES = libprocess.la +libprocess_la_SOURCES = process.hh process.cc +libprocess_la_CPPFLAGS = $(AM_CPPFLAGS) $(OPENCV_CPPFLAGS) +# Force static linking. +libprocess_la_LDFLAGS = -static -# The sample image form Pierre Soille's PAMI 2008 article. -EXTRA_DIST = soille.pgm +endif HAVE_OPENCV diff --git a/milena/sandbox/theo/mln/walue/rgb_3xn.hh b/milena/apps/camera-process/camprocess.cc similarity index 50% copy from milena/sandbox/theo/mln/walue/rgb_3xn.hh copy to milena/apps/camera-process/camprocess.cc index 62487ad..2a10fa6 100644 --- a/milena/sandbox/theo/mln/walue/rgb_3xn.hh +++ b/milena/apps/camera-process/camprocess.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE) +// Copyright (C) 2012 EPITA Research and Development Laboratory (LRDE) // // This file is part of Olena. // @@ -23,76 +23,53 @@ // exception does not however invalidate any other reasons why the // executable file might be covered by the GNU General Public License. -#ifndef MLN_WALUE_RGB_3XN_HH -# define MLN_WALUE_RGB_3XN_HH - /// \file -/// \brief FIXME - -# include <mln/walue/internal/rgb_base.hh> -# include <mln/walue/gl.hh> - - -namespace mln +/// \brief Frame-by-frame processing of a camera stream. +/// +/// Inspired by: +/// http://www.geckogeek.fr/lire-le-flux-dune-webcam-camera-video-avec-opencv.ht... +/// +/// Iplimage format description: +/// http://opencv.willowgarage.com/documentation/basic_structures.html#iplimage +/// +/// Hints on manipulating OpenCV: +/// http://www.cs.iit.edu/~agam/cs512/lect-notes/opencv-intro/opencv-intro.html +/// + +#include <opencv/highgui.h> +#include <opencv/cv.h> + +#include "process.hh" + +int main() { - - namespace walue - { - - // Forward declaration. - template <unsigned n> class rgb_3xn; - - - // FIXME... - - - /// \brief FIXME - // - template <unsigned n> - class rgb_3xn : public internal::rgb_base< gl<n>, gl<n>, gl<n>, - rgb_3xn<n> > - { - typedef internal::rgb_base< gl<n>, gl<n>, gl<n>, - rgb_3xn<n> > super_; - public: - - // Constructor without argument. - rgb_3xn(); - - rgb_3xn(float r, float g, float b); - - template <typename T> - rgb_3xn(const internal::encoding<T,T,T>& e) - : super_(set_encoding(e.t0), - set_encoding(e.t1), - set_encoding(e.t2)) - { - } - - }; - - - -# ifndef MLN_INCLUDE_ONLY - - template <unsigned n> - inline - rgb_3xn<n>::rgb_3xn() + // Capture camera stream. + CvCapture* capture = cvCreateCameraCapture(CV_CAP_ANY); + if (!capture) { + std::cerr << "Cannot open camera stream." << std::endl; + exit(1); } - template <unsigned n> - inline - rgb_3xn<n>::rgb_3xn(float r, float g, float b) - : super_(r, g, b) + // Create a GUI window. + cvNamedWindow("Window", CV_WINDOW_AUTOSIZE); + + // Loop until `q' or `Q' is pressed. + char key; + while(key != 'q' && key != 'Q') { + // Grab a frame from the stream... + IplImage* image = cvQueryFrame(capture); + // ...process it with Milena... + process(image); + // ...and display it. + cvShowImage("Window", image); + + // Wait for the user to press a key for 10 ms. + key = cvWaitKey(10); } -# endif // ! MLN_INCLUDE_ONLY - - } // end of namespace mln::walue - -} // end of namespace mln - - -#endif // ! MLN_WALUE_RGB_3XN_HH + // Release ressources. + cvReleaseCapture(&capture); + cvDestroyWindow("Window"); +} diff --git a/milena/apps/camera-process/process.cc b/milena/apps/camera-process/process.cc new file mode 100644 index 0000000..8cf2446 --- /dev/null +++ b/milena/apps/camera-process/process.cc @@ -0,0 +1,71 @@ +// Copyright (C) 2012 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see <http://www.gnu.org/licenses/>. +// +// As a special exception, you may use this file as part of a free +// software project without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to produce +// an executable, this file does not by itself cause the resulting +// executable to be covered by the GNU General Public License. This +// exception does not however invalidate any other reasons why the +// executable file might be covered by the GNU General Public License. + +#include <mln/core/image/image2d.hh> +#include <mln/opt/at.hh> + +#include <mln/value/int_u8.hh> +#include <mln/value/rgb8.hh> +#include <mln/fun/v2v/rgb_to_int_u.hh> + +#include "process.hh" + + +/* FIXME: Hide OpenCV-Milena conversion operations; or better, wrap + the `Iplimage' data structure in a Milena image so that it can be + processed directly. */ + +void process(IplImage* cv_ima) +{ + using namespace mln; + + // Convert `cv_ima' into a Milena image... + image2d<value::rgb8> mln_ima(cv_ima->height, cv_ima->width); + for (int row = 0; row < cv_ima->height; ++row) + for (int col = 0; col < cv_ima->width; ++col) + for (int chan = 0; chan < cv_ima->nChannels; ++chan) + { + opt::at(mln_ima, row, col).comp(chan) = + (unsigned char) cv_ima->imageData[row * cv_ima->widthStep + + col * cv_ima->nChannels + + chan]; + } + + // ...do something with it... + mln_piter_(image2d<value::rgb8>) p(mln_ima.domain()); + for_all(p) + convert::from_to(fun::v2v::rgb_to_int_u<8>()(mln_ima(p)), mln_ima(p)); + + // ...and paste `mln_ima' back into the OpenCV image `cv_ima'. + for (int row = 0; row < cv_ima->height; ++row) + for (int col = 0; col < cv_ima->width; ++col) + for (int chan = 0; chan < cv_ima->nChannels; ++chan) + { + cv_ima->imageData[row * cv_ima->widthStep + + col * cv_ima->nChannels + + chan] = + (char) opt::at(mln_ima, row, col).comp(chan); + } +} diff --git a/milena/mln/extract/essential.hh b/milena/apps/camera-process/process.hh similarity index 80% copy from milena/mln/extract/essential.hh copy to milena/apps/camera-process/process.hh index 3a3c8d0..d0eebff 100644 --- a/milena/mln/extract/essential.hh +++ b/milena/apps/camera-process/process.hh @@ -1,4 +1,4 @@ -// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE) +// Copyright (C) 2012 EPITA Research and Development Laboratory (LRDE) // // This file is part of Olena. // @@ -23,14 +23,14 @@ // exception does not however invalidate any other reasons why the // executable file might be covered by the GNU General Public License. -#ifndef MLN_EXTRACT_ESSENTIAL_HH -# define MLN_EXTRACT_ESSENTIAL_HH +#ifndef APPS_CAMERA_PROCESS_PROCESS_HH +# define APPS_CAMERA_PROCESS_PROCESS_HH /// \file -/// -/// File that includes all sub-data extraction related routines. +/// \brief Process an OpenCV image with Milena. -# include <mln/extract/all.hh> +#include <opencv/cv.h> +void process(IplImage* image); -#endif // ! MLN_EXTRACT_ESSENTIAL_HH +#endif // ! APPS_CAMERA_PROCESS_PROCESS_HH -- 1.7.2.5
participants (1)
-
Roland Levillain