summaryrefslogtreecommitdiff
path: root/opencv/cvimage.h
diff options
context:
space:
mode:
Diffstat (limited to 'opencv/cvimage.h')
-rw-r--r--opencv/cvimage.h56
1 files changed, 52 insertions, 4 deletions
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 <math.h>
+#include <cv.h>
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;i<w*h*3;i++) {
t->RGBdata[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 "<<w<<"x"<<h<<", got "<<other.w<<"x"<<other.h<<")"<<endl;
@@ -126,8 +174,6 @@ namespace Rotor {
else {
for (int i=0;i<w*h*3;i++){
//calculate with tables
- uint8_t p1=RGBdata[i];
- uint8_t p2=other.RGBdata[i];
RGBdata[i]=pixels.multiply[RGBdata[i]][other.RGBdata[i]];
}
}
@@ -213,5 +259,7 @@ namespace Rotor {
uint16_t *Zdata;
int h,w;
bool ownsRGBdata,ownsAdata,ownsZdata; //better done through auto_ptr?
+
+ cv::Mat rgb;
};
} \ No newline at end of file