diff options
author | lluís gómez i bigordà <lluisbigorda@users.sourceforge.net> | 2009-09-24 22:08:54 +0000 |
---|---|---|
committer | lluís gómez i bigordà <lluisbigorda@users.sourceforge.net> | 2009-09-24 22:08:54 +0000 |
commit | 05b77eed721931281759bf222e319b05d81458c9 (patch) | |
tree | 59cdd6800060871317b88f4d2df3258e8e862e9e | |
parent | f3117bf10c367592e30a7b5559e30d7b75b494f3 (diff) |
The colorspace in Gem-MACOSX is GRAB instead of RGBA in Linux
so added -DDARWIN -DLINUX definitions in the Makefile
and custom code for each system on pix_opencv_contours_convexhull and pix_opencv_colorfilt
svn path=/trunk/externals/pix_opencv/; revision=12446
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | pix_opencv_colorfilt.cc | 38 | ||||
-rw-r--r-- | pix_opencv_contours_convexhull.cc | 10 |
3 files changed, 44 insertions, 6 deletions
@@ -13,12 +13,14 @@ CPPFLAGS = -fPIC -DPD -O2 -funroll-loops -fomit-frame-pointer -ffast-math \ UNAME := $(shell uname -s) ifeq ($(UNAME),Linux) + CPPFLAGS += -DLINUX INCLUDES += `pkg-config --cflags opencv` LDFLAGS = -export_dynamic -shared LIBS = `pkg-config --libs opencv` EXTENSION = pd_linux endif ifeq ($(UNAME),Darwin) + CPPFLAGS += -DDARWIN INCLUDES += -I/System/Library/Frameworks/OpenCV.framework/Headers/ LDFLAGS = -bundle -undefined dynamic_lookup LIBS = -lm -framework OpenCV diff --git a/pix_opencv_colorfilt.cc b/pix_opencv_colorfilt.cc index 483f0b1..7e038b8 100644 --- a/pix_opencv_colorfilt.cc +++ b/pix_opencv_colorfilt.cc @@ -55,7 +55,11 @@ pix_opencv_colorfilt :: pix_opencv_colorfilt() rgba = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 4); rgb = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 3); +#ifdef DARWIN + brgb = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 4); +#else brgb = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 3); +#endif } ///////////////////////////////////////////////////////// @@ -111,27 +115,39 @@ void pix_opencv_colorfilt :: processRGBAImage(imageStruct &image) //create the orig image with new size rgba = cvCreateImage(cvSize(image.xsize,image.ysize), IPL_DEPTH_8U, 4); rgb = cvCreateImage(cvSize(image.xsize,image.ysize), IPL_DEPTH_8U, 3); +#ifdef DARWIN + brgb = cvCreateImage(cvSize(image.xsize,image.ysize), IPL_DEPTH_8U, 4); +#else brgb = cvCreateImage(cvSize(image.xsize,image.ysize), IPL_DEPTH_8U, 3); +#endif } memcpy( rgba->imageData, image.data, image.xsize*image.ysize*4 ); - cvCvtColor(rgba, brgb, CV_BGRA2BGR); + cvCopy(rgba, brgb); for( py=0; py<rgba->height; py++ ) { for( px=0; px<rgba->width; px++ ) { - b = ((uchar*)(rgba->imageData + rgba->widthStep*(int)py))[(int)px*4]; +#ifdef DARWIN + g = ((uchar*)(rgba->imageData + rgba->widthStep*(int)py))[(int)px*4]; + r = ((uchar*)(rgba->imageData + rgba->widthStep*(int)py))[(int)px*4+1]; + b = ((uchar*)(rgba->imageData + rgba->widthStep*(int)py))[(int)px*4+3]; +#else + r = ((uchar*)(rgba->imageData + rgba->widthStep*(int)py))[(int)px*4]; g = ((uchar*)(rgba->imageData + rgba->widthStep*(int)py))[(int)px*4+1]; - r = ((uchar*)(rgba->imageData + rgba->widthStep*(int)py))[(int)px*4+2]; + b = ((uchar*)(rgba->imageData + rgba->widthStep*(int)py))[(int)px*4+2]; +#endif diff = 0; diff = abs(r-x_colorR ); diff += abs(g-x_colorG ); diff += abs(b-x_colorB ); + diff = diff/3; if ( diff > x_tolerance ) { (rgba->imageData + rgba->widthStep*(int)py)[(int)px*4] = 0x0; (rgba->imageData + rgba->widthStep*(int)py)[(int)px*4+1] = 0x0; (rgba->imageData + rgba->widthStep*(int)py)[(int)px*4+2] = 0x0; + (rgba->imageData + rgba->widthStep*(int)py)[(int)px*4+3] = 0x0; } } } @@ -162,7 +178,11 @@ void pix_opencv_colorfilt :: processRGBImage(imageStruct &image) //create the orig image with new size rgba = cvCreateImage(cvSize(image.xsize,image.ysize), IPL_DEPTH_8U, 4); rgb = cvCreateImage(cvSize(image.xsize,image.ysize), IPL_DEPTH_8U, 3); +#ifdef DARWIN + brgb = cvCreateImage(cvSize(rgb->width,rgb->height), IPL_DEPTH_8U, 4); +#else brgb = cvCreateImage(cvSize(rgb->width,rgb->height), IPL_DEPTH_8U, 3); +#endif } memcpy( rgb->imageData, image.data, image.xsize*image.ysize*3 ); @@ -229,10 +249,16 @@ void pix_opencv_colorfilt :: pickMess (float xcur, float ycur) if ( ( xcur >= 0. ) && ( xcur <= comp_xsize ) && ( ycur > 0. ) && ( ycur < comp_ysize ) ) { - x_colorB = ((uchar*)(brgb->imageData + brgb->widthStep*(int)ycur))[(int)xcur*3]; +#ifdef DARWIN + x_colorR = ((uchar*)(brgb->imageData + brgb->widthStep*(int)ycur))[(int)xcur*4+1]; + x_colorG = ((uchar*)(brgb->imageData + brgb->widthStep*(int)ycur))[(int)xcur*4+2]; + x_colorB = ((uchar*)(brgb->imageData + brgb->widthStep*(int)ycur))[(int)xcur*4+3]; +#else + ycur = brgb->height - ycur; + x_colorR = ((uchar*)(brgb->imageData + brgb->widthStep*(int)ycur))[(int)xcur*3]; x_colorG = ((uchar*)(brgb->imageData + brgb->widthStep*(int)ycur))[(int)xcur*3+1]; - x_colorR = ((uchar*)(brgb->imageData + brgb->widthStep*(int)ycur))[(int)xcur*3+2]; - + x_colorB = ((uchar*)(brgb->imageData + brgb->widthStep*(int)ycur))[(int)xcur*3+2]; +#endif outlet_float( x_R, x_colorR ); outlet_float( x_G, x_colorG ); outlet_float( x_B, x_colorB ); diff --git a/pix_opencv_contours_convexhull.cc b/pix_opencv_contours_convexhull.cc index ebd60a3..ae70e20 100644 --- a/pix_opencv_contours_convexhull.cc +++ b/pix_opencv_contours_convexhull.cc @@ -182,14 +182,24 @@ void pix_opencv_contours_convexhull :: processRGBAImage(imageStruct &image) // Draw convex hull for current contour. for(i=0; i<hullsize-1; i++) { +#ifdef DARWIN + cvLine(rgb, PointArray[hull[i]], + PointArray[hull[i+1]],CV_RGB(0,255,0),1, CV_AA, 0 ); +#else cvLine(rgb, PointArray[hull[i]], PointArray[hull[i+1]],CV_RGB(0,0,255),1, CV_AA, 0 ); +#endif SETFLOAT(&rlist[j], PointArray[hull[i]].x); SETFLOAT(&rlist[j+1], PointArray[hull[i]].y); j = j + 2; } +#ifdef DARWIN + cvLine(rgb, PointArray[hull[hullsize-1]], + PointArray[hull[0]],CV_RGB(0,255,0),1, CV_AA, 0 ); +#else cvLine(rgb, PointArray[hull[hullsize-1]], PointArray[hull[0]],CV_RGB(0,0,255),1, CV_AA, 0 ); +#endif SETFLOAT(&rlist[j], PointArray[hull[i]].x); SETFLOAT(&rlist[j+1], PointArray[hull[i]].y); |