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 ++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 52 insertions(+), 4 deletions(-) (limited to 'opencv/cvimage.h') 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 "<