From edd05e4ad726c5aec6807a30dc9ff7de8f97b28b Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Wed, 10 Jul 2013 16:38:13 +0100 Subject: cv::Mat use for images --- opencv/cvimage.h | 56 +++++++++++++++++++++++++++++++++++++++++++++---- opencv/hello-opencv.cpp | 1 - opencv/hello-opencv.d | 16 +++++++------- 3 files changed, 60 insertions(+), 13 deletions(-) (limited to 'opencv') diff --git a/opencv/cvimage.h b/opencv/cvimage.h index b96f704..7588673 100644 --- a/opencv/cvimage.h +++ b/opencv/cvimage.h @@ -1,8 +1,21 @@ #include +#include using namespace std; //converting to use a cv image... +//cv::Mat supports most of what we want here +//need to think +//http://answers.opencv.org/question/8202/using-external-image-data-in-a-cvmat/ + +//all access to the image is presently through a pointer to the data +//cv::Mat supports this + +//how will copying work? +//Rotor::Image will contain a cv::Mat object which may own its data or inherit it +//cv::Mat should take care of reference counting + +//can cv::Mat namespace Rotor { class pixeltables{ @@ -74,6 +87,13 @@ namespace Rotor { ownsRGBdata=ownsAdata=ownsZdata=false; } bool setup(int _w,int _h){ //set up with internal data + rgb.create(_w,_h,CV_8UC3); + RGBdata=rgb.data; //can move to use the bare pointer eventually + ownsRGBdata=false; //will not be necessary + w=_w; + h=_h; + return true; + /* if (w!=_w||h!=_h||!ownsRGBdata||!ownsAdata||!ownsZdata){ free(); w=_w; @@ -85,8 +105,18 @@ namespace Rotor { return true; } else return false; + */ } - bool setup_fromRGB(int _w,int _h,uint8_t *pRGBdata){ //possibility of just resetting pointer? + bool setup_fromRGB(int _w,int _h,uint8_t *pRGBdata){ + //here the data belongs to libavcodec or other + //could move to using cv::Mat there also and just passing cv:Mat over + rgb=cv::Mat(_w,_h,CV_8UC3,pRGBdata); + RGBdata=rgb.data; //can move to use the bare pointer eventually + ownsRGBdata=false; //will not be necessary + w=_w; + h=_h; + return true; + /* if (w!=_w||h!=_h||ownsRGBdata||!ownsAdata||!ownsZdata){ free(); w=_w; @@ -99,14 +129,32 @@ namespace Rotor { return true; } return false; + */ + } + bool setup_fromMat(cv::Mat& othermat){ + //here the mat belongs to another Image object + rgb=cv::Mat(othermat); + RGBdata=rgb.data; //can move to use the bare pointer eventually + ownsRGBdata=false; //will not be necessary + w=rgb.rows; + h=rgb.cols; + return true; } Image* clone(){ - Image *t=new Image(w,h); + Image *t=new Image(); + t->rgb=rgb.clone(); + t->w=w; + t->h=h; + t->RGBdata=t->rgb.data; //can move to use the bare pointer eventually + t->ownsRGBdata=false; //will not be necessary + /* for (int i=0;iRGBdata[i]=RGBdata[i]; } + */ return t; } + //believe these still work, don't know if these optimisations are better than opencvs.. Image & operator+=(const Image &other) { if (other.w!=w||other.h!=h) { cerr<<"Rotor: cannot add images with different sizes! (wanted "< #include #include -#include #include #include "cvimage.h" diff --git a/opencv/hello-opencv.d b/opencv/hello-opencv.d index eebafe9..c7b95b9 100644 --- a/opencv/hello-opencv.d +++ b/opencv/hello-opencv.d @@ -33,10 +33,10 @@ /usr/include/i386-linux-gnu/bits/nan.h \ /usr/include/i386-linux-gnu/bits/mathdef.h \ /usr/include/i386-linux-gnu/bits/mathcalls.h \ - /usr/include/i386-linux-gnu/bits/mathinline.h /usr/include/opencv/cv.h \ - /usr/include/opencv2/core/core_c.h /usr/include/opencv2/core/types_c.h \ - /usr/include/assert.h /usr/include/string.h \ - /usr/include/i386-linux-gnu/bits/string3.h \ + /usr/include/i386-linux-gnu/bits/mathinline.h \ + /usr/include/opencv/highgui.h /usr/include/opencv2/core/core_c.h \ + /usr/include/opencv2/core/types_c.h /usr/include/assert.h \ + /usr/include/string.h /usr/include/i386-linux-gnu/bits/string3.h \ /usr/lib/gcc/i686-linux-gnu/4.7/include/float.h \ /usr/lib/gcc/i686-linux-gnu/4.7/include/stdint.h /usr/include/stdint.h \ /usr/include/i386-linux-gnu/bits/wchar.h \ @@ -141,7 +141,9 @@ /usr/include/c++/4.7/bits/stl_multimap.h \ /usr/include/opencv2/core/operations.hpp \ /usr/include/opencv2/core/mat.hpp \ - /usr/include/opencv2/imgproc/imgproc_c.h \ + /usr/include/opencv2/highgui/highgui_c.h \ + /usr/include/opencv2/highgui/highgui.hpp cvimage.h \ + /usr/include/opencv/cv.h /usr/include/opencv2/imgproc/imgproc_c.h \ /usr/include/opencv2/imgproc/types_c.h \ /usr/include/opencv2/imgproc/imgproc.hpp \ /usr/include/opencv2/video/tracking.hpp \ @@ -191,6 +193,4 @@ /usr/include/opencv2/legacy/compat.hpp \ /usr/include/opencv2/core/internal.hpp \ /usr/include/i386-linux-gnu/sys/mman.h \ - /usr/include/i386-linux-gnu/bits/mman.h /usr/include/opencv/highgui.h \ - /usr/include/opencv2/highgui/highgui_c.h \ - /usr/include/opencv2/highgui/highgui.hpp cvimage.h + /usr/include/i386-linux-gnu/bits/mman.h -- cgit v1.2.3