* src/milena/doc/examples.dox,
* src/milena/doc/examples/cv_to_mln.cc,
* src/milena/doc/examples/ffmpeg_to_mln.cc,
* src/milena/doc/examples/mln_to_cv.cc,
* src/milena/doc/examples/mln_to_ffmpeg.cc: Here.
---
milena/doc/examples.dox | 12 ++++++++++-
milena/doc/examples/cv_to_mln.cc | 22 ++++++++++++++++++++
milena/doc/examples/ffmpeg_to_mln.cc | 28 +++++++++++++++++++++++++
milena/doc/examples/mln_to_cv.cc | 23 ++++++++++++++++++++
milena/doc/examples/mln_to_ffmpeg.cc | 38 ++++++++++++++++++++++++++++++++++
5 files changed, 122 insertions(+), 1 deletion(-)
create mode 100644 milena/doc/examples/cv_to_mln.cc
create mode 100644 milena/doc/examples/ffmpeg_to_mln.cc
create mode 100644 milena/doc/examples/mln_to_cv.cc
create mode 100644 milena/doc/examples/mln_to_ffmpeg.cc
diff --git a/milena/doc/examples.dox b/milena/doc/examples.dox
index ab18c38..69d6093 100644
--- a/milena/doc/examples.dox
+++ b/milena/doc/examples.dox
@@ -7,8 +7,18 @@
\li \link demos/genericity/neighborhood/permissive.cc Custom neighborhoods \endlink
\li \link demos/inter_pixel/inter_pixel.cc Inter-pixel processings \endlink
-
\section examplesgraph Graphs
\li \link demos/graph/region_adjacency_graph.cc Region Adjacency Graph \endlink
+
+\section examplesinterpixel Inter-pixel Processings
+\li \link demos/inter_pixel/inter_pixel.cc Watershed \endlink
+
+\section examplesconv Conversion of RGB Images
+\subsection Opencv
+\li \link doc/examples/mln_to_cv.cc Milena to Opencv. \endlink
+\li \link doc/examples/cv_to_mln.cc Opencv to Milena. \endlink
+\subsection FFmpeg
+\li \link doc/examples/mln_to_ffmpeg.cc Milena to FFmpeg. \endlink
+\li \link doc/examples/ffmpeg_to_mln.cc FFmpeg to Milena. \endlink
*/
diff --git a/milena/doc/examples/cv_to_mln.cc b/milena/doc/examples/cv_to_mln.cc
new file mode 100644
index 0000000..878e6e8
--- /dev/null
+++ b/milena/doc/examples/cv_to_mln.cc
@@ -0,0 +1,22 @@
+#include <mln/core/image/image2d.hh>
+#include <mln/value/rgb8.hh>
+#include "opencv/highgui.h"
+#include "opencv2/imgproc/imgproc.hpp"
+
+using namespace cv;
+using namespace mln;
+using value::rgb8;
+
+image2d<value::rgb8> opencv_to_milena(cv::Mat cv_img) {
+
+ image2d<value::rgb8> mln_img(cv_img.rows, cv_img.cols);
+
+ for (unsigned x = 0; x < mln_img.ncols(); ++x) {
+ for (unsigned y = 0; y < mln_img.nrows(); ++y) {
+ mln_img(mln::point2d(y, x)).red() = cv_img.at<Vec3b>(y, x).val[2];
+ mln_img(mln::point2d(y, x)).green() = cv_img.at<Vec3b>(y, x).val[1];
+ mln_img(mln::point2d(y, x)).blue() = cv_img.at<Vec3b>(y, x).val[0];
+ }
+ }
+ return mln_img;
+}
diff --git a/milena/doc/examples/ffmpeg_to_mln.cc b/milena/doc/examples/ffmpeg_to_mln.cc
new file mode 100644
index 0000000..eb86dd8
--- /dev/null
+++ b/milena/doc/examples/ffmpeg_to_mln.cc
@@ -0,0 +1,28 @@
+#include <mln/core/image/image2d.hh>
+#include <mln/value/rgb8.hh>
+extern "C" {
+
+#include <libavcodec/avcodec.h>
+#include <libavformat/avformat.h>
+#include <libavutil/avutil.h>
+#include <libavutil/imgutils.h>
+#include <libswscale/swscale.h>
+
+}
+
+image2d<value::rgb8> copy_AvFrame_to_image2d_rgb(AVFrame *ffmpeg_img) {
+
+ image2d<value::rgb8> mln_img(ffmpeg_img->height, ffmpeg_img->width);
+
+ value::rgb8 *img_mln_ptr = &mln_img(mln_img.domain().pmin());
+ unsigned img_mln_nextline = mln_img.delta_offset(dpoint2d(+1, 0));
+ unsigned nrows = geom::nrows(mln_img);
+ uint8_t *img_ffmpeg_ptr = ffmpeg_img->data[0];
+
+ for (unsigned int row = 0; row < nrows; ++row) {
+ std::memcpy(img_mln_ptr, img_ffmpeg_ptr, ffmpeg_img->width * 3);
+ img_mln_ptr += img_mln_nextline;
+ img_ffmpeg_ptr += ffmpeg_img->linesize[0];
+ }
+ return mln_img;
+}
diff --git a/milena/doc/examples/mln_to_cv.cc b/milena/doc/examples/mln_to_cv.cc
new file mode 100644
index 0000000..501de14
--- /dev/null
+++ b/milena/doc/examples/mln_to_cv.cc
@@ -0,0 +1,23 @@
+#include <mln/core/image/image2d.hh>
+#include <mln/value/rgb8.hh>
+#include "opencv/highgui.h"
+#include "opencv2/imgproc/imgproc.hpp"
+
+using namespace cv;
+using namespace mln;
+using value::rgb8;
+
+cv::Mat milena_to_opencv(image2d<value::rgb8> mln_img) {
+
+ cv::Mat cv_img(mln_img.nrows(), mln_img.ncols(), CV_8UC3);
+
+ for (unsigned x = 0; x < mln_img.ncols(); ++x) {
+ for (unsigned y = 0; y < mln_img.nrows(); ++y) {
+ Vec3b intensity(mln_img(mln::point2d(y, x)).blue(),
+ mln_img(mln::point2d(y, x)).green(),
+ mln_img(mln::point2d(y, x)).red());
+ cv_img.at<Vec3b>(y, x) = intensity;
+ }
+ }
+ return cv_img;
+}
diff --git a/milena/doc/examples/mln_to_ffmpeg.cc b/milena/doc/examples/mln_to_ffmpeg.cc
new file mode 100644
index 0000000..1187c69
--- /dev/null
+++ b/milena/doc/examples/mln_to_ffmpeg.cc
@@ -0,0 +1,38 @@
+#include <mln/core/image/image2d.hh>
+#include <mln/value/rgb8.hh>
+extern "C" {
+
+#include <libavcodec/avcodec.h>
+#include <libavformat/avformat.h>
+#include <libavutil/avutil.h>
+#include <libavutil/imgutils.h>
+#include <libswscale/swscale.h>
+
+}
+
+AVFrame* copy_image2d_rgb_to_AvFame(image2d<value::rgb8> mln_img) {
+
+ int w = mln_img.ncols();
+ int h = mln_img.nrows();
+
+ AVFrame *ffmpeg_img;
+ ffmpeg_img = avcodec_alloc_frame();
+
+ ffmpeg_img->linesize[0] = w * 3;
+ ffmpeg_img->width = w;
+ av_image_alloc(ffmpeg_img->data, ffmpeg_img->linesize, w, h, PIX_FMT_RGB24,
1);
+
+ uint8_t *img_ffmpeg_ptr = ffmpeg_img->data[0];
+
+ value::rgb8 *img_mln_ptr = &mln_img(mln_img.domain().pmin());
+ unsigned img_mln_nextline = mln_img.delta_offset(dpoint2d(+1, 0));
+ unsigned nrows = ffmpeg_img->height = h;
+
+ for (unsigned int row = 0; row < nrows; ++row) {
+ std::memcpy(img_ffmpeg_ptr, img_mln_ptr, w * 3);
+ img_mln_ptr += img_mln_nextline;
+ img_ffmpeg_ptr += ffmpeg_img->linesize[0];
+ }
+
+ return ffmpeg_img;
+}
--
1.7.10.4
Show replies by date