[PD-cvs] SF.net SVN: pure-data: [9916] trunk/externals/pix_opencv
lluisbigorda at users.sourceforge.net
lluisbigorda at users.sourceforge.net
Mon May 26 01:07:29 CEST 2008
Revision: 9916
http://pure-data.svn.sourceforge.net/pure-data/?rev=9916&view=rev
Author: lluisbigorda
Date: 2008-05-25 16:07:29 -0700 (Sun, 25 May 2008)
Log Message:
-----------
changed extensions cpp to cc for autobuilds
Added Paths:
-----------
trunk/externals/pix_opencv/pix_opencv_bgsubstract.cc
trunk/externals/pix_opencv/pix_opencv_contours_boundingrect.cc
trunk/externals/pix_opencv/pix_opencv_contours_convexity.cc
trunk/externals/pix_opencv/pix_opencv_distrans.cc
trunk/externals/pix_opencv/pix_opencv_edge.cc
trunk/externals/pix_opencv/pix_opencv_haarcascade.cc
trunk/externals/pix_opencv/pix_opencv_laplace.cc
trunk/externals/pix_opencv/pix_opencv_morphology.cc
trunk/externals/pix_opencv/pix_opencv_motempl.cc
Removed Paths:
-------------
trunk/externals/pix_opencv/pix_opencv_bgsubstract.cpp
trunk/externals/pix_opencv/pix_opencv_contours_boundingrect.cpp
trunk/externals/pix_opencv/pix_opencv_contours_convexity.cpp
trunk/externals/pix_opencv/pix_opencv_distrans.cpp
trunk/externals/pix_opencv/pix_opencv_edge.cpp
trunk/externals/pix_opencv/pix_opencv_haarcascade.cpp
trunk/externals/pix_opencv/pix_opencv_laplace.cpp
trunk/externals/pix_opencv/pix_opencv_morphology.cpp
trunk/externals/pix_opencv/pix_opencv_motempl.cpp
trunk/externals/pix_opencv/pix_opencv_threshold.cpp
trunk/externals/pix_opencv/pix_opencv_threshold.h
Added: trunk/externals/pix_opencv/pix_opencv_bgsubstract.cc
===================================================================
--- trunk/externals/pix_opencv/pix_opencv_bgsubstract.cc (rev 0)
+++ trunk/externals/pix_opencv/pix_opencv_bgsubstract.cc 2008-05-25 23:07:29 UTC (rev 9916)
@@ -0,0 +1,257 @@
+////////////////////////////////////////////////////////
+//
+// GEM - Graphics Environment for Multimedia
+//
+// zmoelnig at iem.kug.ac.at
+//
+// Implementation file
+//
+// Copyright (c) 1997-2000 Mark Danks.
+// Copyright (c) G\xFCnther Geiger.
+// Copyright (c) 2001-2002 IOhannes m zmoelnig. forum::f\xFCr::uml\xE4ute. IEM
+// Copyright (c) 2002 James Tittle & Chris Clepper
+// For information on usage and redistribution, and for a DISCLAIMER OF ALL
+// WARRANTIES, see the file, "GEM.LICENSE.TERMS" in this distribution.
+//
+/////////////////////////////////////////////////////////
+
+#include "pix_opencv_bgsubstract.h"
+
+CPPEXTERN_NEW(pix_opencv_bgsubstract)
+
+/////////////////////////////////////////////////////////
+//
+// pix_opencv_bgsubstract
+//
+/////////////////////////////////////////////////////////
+// Constructor
+//
+/////////////////////////////////////////////////////////
+pix_opencv_bgsubstract :: pix_opencv_bgsubstract()
+{
+ inlet_new(this->x_obj, &this->x_obj->ob_pd, gensym("float"), gensym("ft1"));
+ x_threshold = 13;
+ x_set = 1;
+ comp_xsize = 0;
+ comp_ysize = 0;
+ orig = NULL;
+ gray = NULL;
+ rgb = NULL;
+ grayLow = NULL;
+ grayUp = NULL;
+ prev_gray = NULL;
+ diff_8U = NULL;
+}
+
+/////////////////////////////////////////////////////////
+// Destructor
+//
+/////////////////////////////////////////////////////////
+pix_opencv_bgsubstract :: ~pix_opencv_bgsubstract()
+{
+ //Destroy cv_images to clean memory
+ cvReleaseImage(&orig);
+ cvReleaseImage(&gray);
+ cvReleaseImage(&rgb);
+ cvReleaseImage(&prev_gray);
+ cvReleaseImage(&grayLow);
+ cvReleaseImage(&grayUp);
+ cvReleaseImage(&diff_8U);
+}
+
+/////////////////////////////////////////////////////////
+// processImage
+//
+/////////////////////////////////////////////////////////
+void pix_opencv_bgsubstract :: processRGBAImage(imageStruct &image)
+{
+
+ if ((this->comp_xsize!=image.xsize)||(this->comp_ysize!=image.ysize)||(!orig)) {
+
+ this->comp_xsize = image.xsize;
+ this->comp_ysize = image.ysize;
+
+ //Destroy cv_images to clean memory
+ cvReleaseImage(&orig);
+ cvReleaseImage(&gray);
+ cvReleaseImage(&rgb);
+ cvReleaseImage(&prev_gray);
+ cvReleaseImage(&grayLow);
+ cvReleaseImage(&grayUp);
+ cvReleaseImage(&diff_8U);
+
+ //create the orig image with new size
+ orig = cvCreateImage(cvSize(image.xsize,image.ysize), IPL_DEPTH_8U, 4);
+ rgb = cvCreateImage(cvSize(image.xsize,image.ysize), IPL_DEPTH_8U, 3);
+
+ // Create the output images with new sizes
+ gray = cvCreateImage(cvSize(orig->width,orig->height), IPL_DEPTH_8U, 1);
+ grayLow = cvCreateImage(cvSize(orig->width,orig->height), IPL_DEPTH_8U, 1);
+ grayUp = cvCreateImage(cvSize(orig->width,orig->height), IPL_DEPTH_8U, 1);
+ prev_gray = cvCreateImage(cvSize(orig->width,orig->height), 8, 1);
+ diff_8U = cvCreateImage(cvSize(orig->width,orig->height), 8, 1);
+ }
+ // Here we make a copy of the pixel data from image to orig->imageData
+ // orig is a IplImage struct, the default image type in openCV, take a look on the IplImage data structure here
+ // http://www.cs.iit.edu/~agam/cs512/lect-notes/opencv-intro/opencv-intro.html
+ memcpy( orig->imageData, image.data, image.xsize*image.ysize*4 );
+
+ // Convert to grayscale
+ cvCvtColor(orig, gray, CV_BGRA2GRAY);
+
+ if (x_set) {
+ memcpy( prev_gray->imageData, gray->imageData, image.xsize*image.ysize );
+ x_set=0;
+ }
+
+ cvSubS (prev_gray,cvScalar(x_threshold,x_threshold,x_threshold,x_threshold),grayLow,NULL);
+ cvAddS (prev_gray,cvScalar(x_threshold,x_threshold,x_threshold,x_threshold),grayUp,NULL);
+ cvInRange (gray, grayLow, grayUp, diff_8U);
+
+ cvNot (diff_8U,diff_8U);
+
+ cvCvtColor(diff_8U, orig, CV_GRAY2BGRA);
+
+ //copy back the processed frame to image
+ memcpy( image.data, orig->imageData, image.xsize*image.ysize*4 );
+}
+
+void pix_opencv_bgsubstract :: processRGBImage(imageStruct &image)
+{
+
+ if ((this->comp_xsize!=image.xsize)||(this->comp_ysize!=image.ysize)||(!orig)) {
+
+ this->comp_xsize = image.xsize;
+ this->comp_ysize = image.ysize;
+
+ //Destroy cv_images to clean memory
+ cvReleaseImage(&orig);
+ cvReleaseImage(&gray);
+ cvReleaseImage(&rgb);
+ cvReleaseImage(&prev_gray);
+ cvReleaseImage(&grayLow);
+ cvReleaseImage(&grayUp);
+ cvReleaseImage(&diff_8U);
+
+ //create the orig image with new size
+ orig = cvCreateImage(cvSize(image.xsize,image.ysize), IPL_DEPTH_8U, 4);
+ rgb = cvCreateImage(cvSize(image.xsize,image.ysize), IPL_DEPTH_8U, 3);
+
+ // Create the output images with new sizes
+ gray = cvCreateImage(cvSize(orig->width,orig->height), IPL_DEPTH_8U, 1);
+ grayLow = cvCreateImage(cvSize(orig->width,orig->height), IPL_DEPTH_8U, 1);
+ grayUp = cvCreateImage(cvSize(orig->width,orig->height), IPL_DEPTH_8U, 1);
+ prev_gray = cvCreateImage(cvSize(orig->width,orig->height), 8, 1);
+ diff_8U = cvCreateImage(cvSize(orig->width,orig->height), 8, 1);
+ }
+ // Here we make a copy of the pixel data from image to orig->imageData
+ // orig is a IplImage struct, the default image type in openCV, take a look on the IplImage data structure here
+ // http://www.cs.iit.edu/~agam/cs512/lect-notes/opencv-intro/opencv-intro.html
+ memcpy( rgb->imageData, image.data, image.xsize*image.ysize*3 );
+
+ // Convert to grayscale
+ cvCvtColor(rgb, gray, CV_BGRA2GRAY);
+
+ if (x_set) {
+ memcpy( prev_gray->imageData, gray->imageData, image.xsize*image.ysize );
+ x_set=0;
+ }
+
+ cvSubS (prev_gray,cvScalar(x_threshold,x_threshold,x_threshold,x_threshold),grayLow,NULL);
+ cvAddS (prev_gray,cvScalar(x_threshold,x_threshold,x_threshold,x_threshold),grayUp,NULL);
+ cvInRange (gray, grayLow, grayUp, diff_8U);
+
+ cvNot (diff_8U,diff_8U);
+
+ cvCvtColor(diff_8U, rgb, CV_GRAY2BGR);
+
+ //copy back the processed frame to image
+ memcpy( image.data, rgb->imageData, image.xsize*image.ysize*3 );
+
+}
+
+void pix_opencv_bgsubstract :: processYUVImage(imageStruct &image)
+{
+}
+
+void pix_opencv_bgsubstract :: processGrayImage(imageStruct &image)
+{
+
+ if ((this->comp_xsize!=image.xsize)||(this->comp_ysize!=image.ysize)||(!orig)) {
+
+ this->comp_xsize = image.xsize;
+ this->comp_ysize = image.ysize;
+
+ //Destroy cv_images to clean memory
+ cvReleaseImage(&orig);
+ cvReleaseImage(&gray);
+ cvReleaseImage(&rgb);
+ cvReleaseImage(&prev_gray);
+ cvReleaseImage(&grayLow);
+ cvReleaseImage(&grayUp);
+ cvReleaseImage(&diff_8U);
+
+ //create the orig image with new size
+ orig = cvCreateImage(cvSize(image.xsize,image.ysize), IPL_DEPTH_8U, 4);
+ rgb = cvCreateImage(cvSize(image.xsize,image.ysize), IPL_DEPTH_8U, 3);
+
+ // Create the output images with new sizes
+ gray = cvCreateImage(cvSize(orig->width,orig->height), IPL_DEPTH_8U, 1);
+ grayLow = cvCreateImage(cvSize(orig->width,orig->height), IPL_DEPTH_8U, 1);
+ grayUp = cvCreateImage(cvSize(orig->width,orig->height), IPL_DEPTH_8U, 1);
+ prev_gray = cvCreateImage(cvSize(orig->width,orig->height), 8, 1);
+ diff_8U = cvCreateImage(cvSize(orig->width,orig->height), 8, 1);
+ }
+ // Here we make a copy of the pixel data from image to orig->imageData
+ // orig is a IplImage struct, the default image type in openCV, take a look on the IplImage data structure here
+ // http://www.cs.iit.edu/~agam/cs512/lect-notes/opencv-intro/opencv-intro.html
+ memcpy( gray->imageData, image.data, image.xsize*image.ysize );
+
+
+ if (x_set) {
+ memcpy( prev_gray->imageData, gray->imageData, image.xsize*image.ysize );
+ x_set=0;
+ }
+
+ cvSubS (prev_gray,cvScalar(x_threshold,x_threshold,x_threshold,x_threshold),grayLow,NULL);
+ cvAddS (prev_gray,cvScalar(x_threshold,x_threshold,x_threshold,x_threshold),grayUp,NULL);
+ cvInRange (gray, grayLow, grayUp, diff_8U);
+
+ cvNot (diff_8U,diff_8U);
+
+ //copy back the processed frame to image
+ memcpy( image.data, diff_8U->imageData, image.xsize*image.ysize );
+}
+
+/////////////////////////////////////////////////////////
+// floatThreshMess
+//
+/////////////////////////////////////////////////////////
+void pix_opencv_bgsubstract :: floatThreshMess (float x_threshold)
+{
+ this->x_threshold = (int)x_threshold;
+}
+void pix_opencv_bgsubstract :: SetMess ()
+{
+ this->x_set = 1;
+}
+
+/////////////////////////////////////////////////////////
+// static member function
+//
+/////////////////////////////////////////////////////////
+void pix_opencv_bgsubstract :: obj_setupCallback(t_class *classPtr)
+{
+ class_addmethod(classPtr, (t_method)&pix_opencv_bgsubstract::floatTreshMessCallback,
+ gensym("ft1"), A_FLOAT, A_NULL);
+ class_addmethod(classPtr, (t_method)&pix_opencv_bgsubstract::SetMessCallback,
+ gensym("set"), A_NULL);
+}
+void pix_opencv_bgsubstract :: floatTreshMessCallback(void *data, t_floatarg x_threshold)
+{
+ GetMyClass(data)->floatThreshMess((float)x_threshold);
+}
+void pix_opencv_bgsubstract :: SetMessCallback(void *data)
+{
+ GetMyClass(data)->SetMess();
+}
Deleted: trunk/externals/pix_opencv/pix_opencv_bgsubstract.cpp
===================================================================
--- trunk/externals/pix_opencv/pix_opencv_bgsubstract.cpp 2008-05-25 22:44:13 UTC (rev 9915)
+++ trunk/externals/pix_opencv/pix_opencv_bgsubstract.cpp 2008-05-25 23:07:29 UTC (rev 9916)
@@ -1,257 +0,0 @@
-////////////////////////////////////////////////////////
-//
-// GEM - Graphics Environment for Multimedia
-//
-// zmoelnig at iem.kug.ac.at
-//
-// Implementation file
-//
-// Copyright (c) 1997-2000 Mark Danks.
-// Copyright (c) G\xFCnther Geiger.
-// Copyright (c) 2001-2002 IOhannes m zmoelnig. forum::f\xFCr::uml\xE4ute. IEM
-// Copyright (c) 2002 James Tittle & Chris Clepper
-// For information on usage and redistribution, and for a DISCLAIMER OF ALL
-// WARRANTIES, see the file, "GEM.LICENSE.TERMS" in this distribution.
-//
-/////////////////////////////////////////////////////////
-
-#include "pix_opencv_bgsubstract.h"
-
-CPPEXTERN_NEW(pix_opencv_bgsubstract)
-
-/////////////////////////////////////////////////////////
-//
-// pix_opencv_bgsubstract
-//
-/////////////////////////////////////////////////////////
-// Constructor
-//
-/////////////////////////////////////////////////////////
-pix_opencv_bgsubstract :: pix_opencv_bgsubstract()
-{
- inlet_new(this->x_obj, &this->x_obj->ob_pd, gensym("float"), gensym("ft1"));
- x_threshold = 13;
- x_set = 1;
- comp_xsize = 0;
- comp_ysize = 0;
- orig = NULL;
- gray = NULL;
- rgb = NULL;
- grayLow = NULL;
- grayUp = NULL;
- prev_gray = NULL;
- diff_8U = NULL;
-}
-
-/////////////////////////////////////////////////////////
-// Destructor
-//
-/////////////////////////////////////////////////////////
-pix_opencv_bgsubstract :: ~pix_opencv_bgsubstract()
-{
- //Destroy cv_images to clean memory
- cvReleaseImage(&orig);
- cvReleaseImage(&gray);
- cvReleaseImage(&rgb);
- cvReleaseImage(&prev_gray);
- cvReleaseImage(&grayLow);
- cvReleaseImage(&grayUp);
- cvReleaseImage(&diff_8U);
-}
-
-/////////////////////////////////////////////////////////
-// processImage
-//
-/////////////////////////////////////////////////////////
-void pix_opencv_bgsubstract :: processRGBAImage(imageStruct &image)
-{
-
- if ((this->comp_xsize!=image.xsize)||(this->comp_ysize!=image.ysize)||(!orig)) {
-
- this->comp_xsize = image.xsize;
- this->comp_ysize = image.ysize;
-
- //Destroy cv_images to clean memory
- cvReleaseImage(&orig);
- cvReleaseImage(&gray);
- cvReleaseImage(&rgb);
- cvReleaseImage(&prev_gray);
- cvReleaseImage(&grayLow);
- cvReleaseImage(&grayUp);
- cvReleaseImage(&diff_8U);
-
- //create the orig image with new size
- orig = cvCreateImage(cvSize(image.xsize,image.ysize), IPL_DEPTH_8U, 4);
- rgb = cvCreateImage(cvSize(image.xsize,image.ysize), IPL_DEPTH_8U, 3);
-
- // Create the output images with new sizes
- gray = cvCreateImage(cvSize(orig->width,orig->height), IPL_DEPTH_8U, 1);
- grayLow = cvCreateImage(cvSize(orig->width,orig->height), IPL_DEPTH_8U, 1);
- grayUp = cvCreateImage(cvSize(orig->width,orig->height), IPL_DEPTH_8U, 1);
- prev_gray = cvCreateImage(cvSize(orig->width,orig->height), 8, 1);
- diff_8U = cvCreateImage(cvSize(orig->width,orig->height), 8, 1);
- }
- // Here we make a copy of the pixel data from image to orig->imageData
- // orig is a IplImage struct, the default image type in openCV, take a look on the IplImage data structure here
- // http://www.cs.iit.edu/~agam/cs512/lect-notes/opencv-intro/opencv-intro.html
- memcpy( orig->imageData, image.data, image.xsize*image.ysize*4 );
-
- // Convert to grayscale
- cvCvtColor(orig, gray, CV_BGRA2GRAY);
-
- if (x_set) {
- memcpy( prev_gray->imageData, gray->imageData, image.xsize*image.ysize );
- x_set=0;
- }
-
- cvSubS (prev_gray,cvScalar(x_threshold,x_threshold,x_threshold,x_threshold),grayLow,NULL);
- cvAddS (prev_gray,cvScalar(x_threshold,x_threshold,x_threshold,x_threshold),grayUp,NULL);
- cvInRange (gray, grayLow, grayUp, diff_8U);
-
- cvNot (diff_8U,diff_8U);
-
- cvCvtColor(diff_8U, orig, CV_GRAY2BGRA);
-
- //copy back the processed frame to image
- memcpy( image.data, orig->imageData, image.xsize*image.ysize*4 );
-}
-
-void pix_opencv_bgsubstract :: processRGBImage(imageStruct &image)
-{
-
- if ((this->comp_xsize!=image.xsize)||(this->comp_ysize!=image.ysize)||(!orig)) {
-
- this->comp_xsize = image.xsize;
- this->comp_ysize = image.ysize;
-
- //Destroy cv_images to clean memory
- cvReleaseImage(&orig);
- cvReleaseImage(&gray);
- cvReleaseImage(&rgb);
- cvReleaseImage(&prev_gray);
- cvReleaseImage(&grayLow);
- cvReleaseImage(&grayUp);
- cvReleaseImage(&diff_8U);
-
- //create the orig image with new size
- orig = cvCreateImage(cvSize(image.xsize,image.ysize), IPL_DEPTH_8U, 4);
- rgb = cvCreateImage(cvSize(image.xsize,image.ysize), IPL_DEPTH_8U, 3);
-
- // Create the output images with new sizes
- gray = cvCreateImage(cvSize(orig->width,orig->height), IPL_DEPTH_8U, 1);
- grayLow = cvCreateImage(cvSize(orig->width,orig->height), IPL_DEPTH_8U, 1);
- grayUp = cvCreateImage(cvSize(orig->width,orig->height), IPL_DEPTH_8U, 1);
- prev_gray = cvCreateImage(cvSize(orig->width,orig->height), 8, 1);
- diff_8U = cvCreateImage(cvSize(orig->width,orig->height), 8, 1);
- }
- // Here we make a copy of the pixel data from image to orig->imageData
- // orig is a IplImage struct, the default image type in openCV, take a look on the IplImage data structure here
- // http://www.cs.iit.edu/~agam/cs512/lect-notes/opencv-intro/opencv-intro.html
- memcpy( rgb->imageData, image.data, image.xsize*image.ysize*3 );
-
- // Convert to grayscale
- cvCvtColor(rgb, gray, CV_BGRA2GRAY);
-
- if (x_set) {
- memcpy( prev_gray->imageData, gray->imageData, image.xsize*image.ysize );
- x_set=0;
- }
-
- cvSubS (prev_gray,cvScalar(x_threshold,x_threshold,x_threshold,x_threshold),grayLow,NULL);
- cvAddS (prev_gray,cvScalar(x_threshold,x_threshold,x_threshold,x_threshold),grayUp,NULL);
- cvInRange (gray, grayLow, grayUp, diff_8U);
-
- cvNot (diff_8U,diff_8U);
-
- cvCvtColor(diff_8U, rgb, CV_GRAY2BGR);
-
- //copy back the processed frame to image
- memcpy( image.data, rgb->imageData, image.xsize*image.ysize*3 );
-
-}
-
-void pix_opencv_bgsubstract :: processYUVImage(imageStruct &image)
-{
-}
-
-void pix_opencv_bgsubstract :: processGrayImage(imageStruct &image)
-{
-
- if ((this->comp_xsize!=image.xsize)||(this->comp_ysize!=image.ysize)||(!orig)) {
-
- this->comp_xsize = image.xsize;
- this->comp_ysize = image.ysize;
-
- //Destroy cv_images to clean memory
- cvReleaseImage(&orig);
- cvReleaseImage(&gray);
- cvReleaseImage(&rgb);
- cvReleaseImage(&prev_gray);
- cvReleaseImage(&grayLow);
- cvReleaseImage(&grayUp);
- cvReleaseImage(&diff_8U);
-
- //create the orig image with new size
- orig = cvCreateImage(cvSize(image.xsize,image.ysize), IPL_DEPTH_8U, 4);
- rgb = cvCreateImage(cvSize(image.xsize,image.ysize), IPL_DEPTH_8U, 3);
-
- // Create the output images with new sizes
- gray = cvCreateImage(cvSize(orig->width,orig->height), IPL_DEPTH_8U, 1);
- grayLow = cvCreateImage(cvSize(orig->width,orig->height), IPL_DEPTH_8U, 1);
- grayUp = cvCreateImage(cvSize(orig->width,orig->height), IPL_DEPTH_8U, 1);
- prev_gray = cvCreateImage(cvSize(orig->width,orig->height), 8, 1);
- diff_8U = cvCreateImage(cvSize(orig->width,orig->height), 8, 1);
- }
- // Here we make a copy of the pixel data from image to orig->imageData
- // orig is a IplImage struct, the default image type in openCV, take a look on the IplImage data structure here
- // http://www.cs.iit.edu/~agam/cs512/lect-notes/opencv-intro/opencv-intro.html
- memcpy( gray->imageData, image.data, image.xsize*image.ysize );
-
-
- if (x_set) {
- memcpy( prev_gray->imageData, gray->imageData, image.xsize*image.ysize );
- x_set=0;
- }
-
- cvSubS (prev_gray,cvScalar(x_threshold,x_threshold,x_threshold,x_threshold),grayLow,NULL);
- cvAddS (prev_gray,cvScalar(x_threshold,x_threshold,x_threshold,x_threshold),grayUp,NULL);
- cvInRange (gray, grayLow, grayUp, diff_8U);
-
- cvNot (diff_8U,diff_8U);
-
- //copy back the processed frame to image
- memcpy( image.data, diff_8U->imageData, image.xsize*image.ysize );
-}
-
-/////////////////////////////////////////////////////////
-// floatThreshMess
-//
-/////////////////////////////////////////////////////////
-void pix_opencv_bgsubstract :: floatThreshMess (float x_threshold)
-{
- this->x_threshold = (int)x_threshold;
-}
-void pix_opencv_bgsubstract :: SetMess ()
-{
- this->x_set = 1;
-}
-
-/////////////////////////////////////////////////////////
-// static member function
-//
-/////////////////////////////////////////////////////////
-void pix_opencv_bgsubstract :: obj_setupCallback(t_class *classPtr)
-{
- class_addmethod(classPtr, (t_method)&pix_opencv_bgsubstract::floatTreshMessCallback,
- gensym("ft1"), A_FLOAT, A_NULL);
- class_addmethod(classPtr, (t_method)&pix_opencv_bgsubstract::SetMessCallback,
- gensym("set"), A_NULL);
-}
-void pix_opencv_bgsubstract :: floatTreshMessCallback(void *data, t_floatarg x_threshold)
-{
- GetMyClass(data)->floatThreshMess((float)x_threshold);
-}
-void pix_opencv_bgsubstract :: SetMessCallback(void *data)
-{
- GetMyClass(data)->SetMess();
-}
Added: trunk/externals/pix_opencv/pix_opencv_contours_boundingrect.cc
===================================================================
--- trunk/externals/pix_opencv/pix_opencv_contours_boundingrect.cc (rev 0)
+++ trunk/externals/pix_opencv/pix_opencv_contours_boundingrect.cc 2008-05-25 23:07:29 UTC (rev 9916)
@@ -0,0 +1,305 @@
+////////////////////////////////////////////////////////
+//
+// GEM - Graphics Environment for Multimedia
+//
+// zmoelnig at iem.kug.ac.at
+//
+// Implementation file
+//
+// Copyright (c) 1997-2000 Mark Danks.
+// Copyright (c) G\xFCnther Geiger.
+// Copyright (c) 2001-2002 IOhannes m zmoelnig. forum::f\xFCr::uml\xE4ute. IEM
+// Copyright (c) 2002 James Tittle & Chris Clepper
+// For information on usage and redistribution, and for a DISCLAIMER OF ALL
+// WARRANTIES, see the file, "GEM.LICENSE.TERMS" in this distribution.
+//
+/////////////////////////////////////////////////////////
+
+#include "pix_opencv_contours_boundingrect.h"
+
+CPPEXTERN_NEW(pix_opencv_contours_boundingrect)
+
+/////////////////////////////////////////////////////////
+//
+// pix_opencv_contours_boundingrect
+//
+/////////////////////////////////////////////////////////
+// Constructor
+//
+/////////////////////////////////////////////////////////
+pix_opencv_contours_boundingrect :: pix_opencv_contours_boundingrect()
+{
+ inlet_new(this->x_obj, &this->x_obj->ob_pd, gensym("float"), gensym("minarea"));
+ inlet_new(this->x_obj, &this->x_obj->ob_pd, gensym("float"), gensym("maxarea"));
+ m_dataout = outlet_new(this->x_obj, 0);
+ minarea = 1;
+ maxarea = 320*240;
+ comp_xsize = 0;
+ comp_ysize = 0;
+ orig = NULL;
+ gray = NULL;
+ cnt_img = NULL;
+ rgb = NULL;
+
+}
+
+/////////////////////////////////////////////////////////
+// Destructor
+//
+/////////////////////////////////////////////////////////
+pix_opencv_contours_boundingrect :: ~pix_opencv_contours_boundingrect()
+{
+ //Destroy cv_images to clean memory
+ cvReleaseImage(&orig);
+ cvReleaseImage(&gray);
+ cvReleaseImage(&cnt_img);
+ cvReleaseImage(&rgb);
+}
+
+/////////////////////////////////////////////////////////
+// processImage
+//
+/////////////////////////////////////////////////////////
+void pix_opencv_contours_boundingrect :: processRGBAImage(imageStruct &image)
+{
+ unsigned char *pixels = image.data;
+
+ if ((this->comp_xsize!=image.xsize)||(this->comp_ysize!=image.ysize)||(!orig)) {
+
+ this->comp_xsize = image.xsize;
+ this->comp_ysize = image.ysize;
+
+ //Destroy cv_images to clean memory
+ cvReleaseImage(&orig);
+ cvReleaseImage(&gray);
+ cvReleaseImage(&cnt_img);
+ cvReleaseImage(&rgb);
+
+ //create the orig image with new size
+ orig = cvCreateImage(cvSize(image.xsize,image.ysize), IPL_DEPTH_8U, 4);
+
+ // Create the output images with new sizes
+ rgb = cvCreateImage(cvSize(orig->width,orig->height), IPL_DEPTH_8U, 3);
+ cnt_img = cvCreateImage(cvSize(orig->width,orig->height), IPL_DEPTH_8U, 3);
+
+ gray = cvCreateImage(cvSize(orig->width,orig->height), IPL_DEPTH_8U, 1);
+
+ }
+ // Here we make a copy of the pixel data from image to orig->imageData
+ // orig is a IplImage struct, the default image type in openCV, take a look on the IplImage data structure here
+ // http://www.cs.iit.edu/~agam/cs512/lect-notes/opencv-intro/opencv-intro.html
+ memcpy( orig->imageData, image.data, image.xsize*image.ysize*4 );
+
+ // Convert to grayscale
+ cvCvtColor(orig, gray, CV_RGBA2GRAY);
+
+ CvSeq* contours;
+ CvMemStorage* stor02;
+ stor02 = cvCreateMemStorage(0);
+
+ cvFindContours( gray, stor02, &contours, sizeof(CvContour), CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0) );
+ if (contours) contours = cvApproxPoly( contours, sizeof(CvContour), stor02, CV_POLY_APPROX_DP, 3, 1 );
+
+
+ int i = 0; // Indicator of cycles.
+ for( ; contours != 0; contours = contours->h_next )
+ {
+ int count = contours->total; // This is number point in contour
+ CvRect rect;
+
+ rect = cvContourBoundingRect( contours, 1);
+ if ( ( (rect.width*rect.height) > minarea ) && ( (rect.width*rect.height) < maxarea ) ) {
+ cvRectangle( orig, cvPoint(rect.x,rect.y), cvPoint(rect.x+rect.width,rect.y+rect.height), CV_RGB(255,0,0), 2, 8 , 0 );
+
+ t_atom rlist[4];
+ SETFLOAT(&rlist[0], i);
+ SETFLOAT(&rlist[1], rect.x);
+ SETFLOAT(&rlist[2], rect.y);
+ SETFLOAT(&rlist[3], rect.width);
+ SETFLOAT(&rlist[4], rect.height);
+
+ outlet_list( m_dataout, 0, 5, rlist );
+ i++;
+ }
+
+ }
+
+ cvReleaseMemStorage( &stor02 );
+
+
+ //copy back the processed frame to image
+ memcpy( image.data, orig->imageData, image.xsize*image.ysize*4 );
+}
+
+void pix_opencv_contours_boundingrect :: processRGBImage(imageStruct &image)
+{
+ unsigned char *pixels = image.data;
+
+ if ((this->comp_xsize!=image.xsize)||(this->comp_ysize!=image.ysize)||(!rgb)) {
+
+ this->comp_xsize = image.xsize;
+ this->comp_ysize = image.ysize;
+
+ //Destroy cv_images to clean memory
+ cvReleaseImage(&orig);
+ cvReleaseImage(&gray);
+ cvReleaseImage(&cnt_img);
+ cvReleaseImage(&rgb);
+
+ //create the orig image with new size
+ rgb = cvCreateImage(cvSize(image.xsize,image.ysize), IPL_DEPTH_8U, 3);
+
+ // Create the output images with new sizes
+ cnt_img = cvCreateImage(cvSize(rgb->width,rgb->height), IPL_DEPTH_8U, 3);
+
+ gray = cvCreateImage(cvSize(rgb->width,rgb->height), IPL_DEPTH_8U, 1);
+
+ }
+ // FEM UNA COPIA DEL PACKET A image->imageData ... http://www.cs.iit.edu/~agam/cs512/lect-notes/opencv-intro/opencv-intro.html aqui veiem la estructura de IplImage
+ memcpy( rgb->imageData, image.data, image.xsize*image.ysize*3 );
+
+ // Convert to grayscale
+ cvCvtColor(rgb, gray, CV_RGB2GRAY);
+
+ CvSeq* contours;
+ CvMemStorage* stor02;
+ stor02 = cvCreateMemStorage(0);
+
+ cvFindContours( gray, stor02, &contours, sizeof(CvContour), CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0) );
+ if (contours) contours = cvApproxPoly( contours, sizeof(CvContour), stor02, CV_POLY_APPROX_DP, 3, 1 );
+
+
+ int i = 0; // Indicator of cycles.
+ for( ; contours != 0; contours = contours->h_next )
+ {
+ int count = contours->total; // This is number point in contour
+ CvRect rect;
+
+ rect = cvContourBoundingRect( contours, 1);
+ if ( ( (rect.width*rect.height) > minarea ) && ( (rect.width*rect.height) < maxarea ) ) {
+ cvRectangle( rgb, cvPoint(rect.x,rect.y), cvPoint(rect.x+rect.width,rect.y+rect.height), CV_RGB(255,0,0), 2, 8 , 0 );
+
+ t_atom rlist[4];
+ SETFLOAT(&rlist[0], i);
+ SETFLOAT(&rlist[1], rect.x);
+ SETFLOAT(&rlist[2], rect.y);
+ SETFLOAT(&rlist[3], rect.width);
+ SETFLOAT(&rlist[4], rect.height);
+
+ outlet_list( m_dataout, 0, 5, rlist );
+ i++;
+ }
+
+ }
+
+ cvReleaseMemStorage( &stor02 );
+
+
+ //cvShowImage(wndname, cedge);
+ memcpy( image.data, rgb->imageData, image.xsize*image.ysize*3 );
+}
+
+void pix_opencv_contours_boundingrect :: processYUVImage(imageStruct &image)
+{
+}
+
+void pix_opencv_contours_boundingrect :: processGrayImage(imageStruct &image)
+{
+
+ if ((this->comp_xsize!=image.xsize)||(this->comp_ysize!=image.ysize)||(!orig)) {
+
+ this->comp_xsize = image.xsize;
+ this->comp_ysize = image.ysize;
+
+ //Destroy cv_images to clean memory
+ cvReleaseImage(&orig);
+ cvReleaseImage(&gray);
+ cvReleaseImage(&cnt_img);
+ cvReleaseImage(&rgb);
+
+ //create the orig image with new size
+ orig = cvCreateImage(cvSize(image.xsize,image.ysize), IPL_DEPTH_8U, 4);
+
+ // Create the output images with new sizes
+ rgb = cvCreateImage(cvSize(orig->width,orig->height), IPL_DEPTH_8U, 3);
+ cnt_img = cvCreateImage(cvSize(orig->width,orig->height), IPL_DEPTH_8U, 3);
+
+ gray = cvCreateImage(cvSize(orig->width,orig->height), IPL_DEPTH_8U, 1);
+
+ }
+ // Here we make a copy of the pixel data from image to orig->imageData
+ // orig is a IplImage struct, the default image type in openCV, take a look on the IplImage data structure here
+ // http://www.cs.iit.edu/~agam/cs512/lect-notes/opencv-intro/opencv-intro.html
+ memcpy( gray->imageData, image.data, image.xsize*image.ysize );
+
+
+ CvSeq* contours;
+ CvMemStorage* stor02;
+ stor02 = cvCreateMemStorage(0);
+
+ cvFindContours( gray, stor02, &contours, sizeof(CvContour), CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0) );
+ if (contours) contours = cvApproxPoly( contours, sizeof(CvContour), stor02, CV_POLY_APPROX_DP, 3, 1 );
+
+
+ int i = 0; // Indicator of cycles.
+ for( ; contours != 0; contours = contours->h_next )
+ {
+ int count = contours->total; // This is number point in contour
+ CvRect rect;
+
+ rect = cvContourBoundingRect( contours, 1);
+ if ( ( (rect.width*rect.height) > minarea ) && ( (rect.width*rect.height) < maxarea ) ) {
+ cvRectangle( gray, cvPoint(rect.x,rect.y), cvPoint(rect.x+rect.width,rect.y+rect.height), CV_RGB(255,0,0), 2, 8 , 0 );
+
+ t_atom rlist[4];
+ SETFLOAT(&rlist[0], i);
+ SETFLOAT(&rlist[1], rect.x);
+ SETFLOAT(&rlist[2], rect.y);
+ SETFLOAT(&rlist[3], rect.width);
+ SETFLOAT(&rlist[4], rect.height);
+
+ outlet_list( m_dataout, 0, 5, rlist );
+ i++;
+ }
+
+ }
+
+ cvReleaseMemStorage( &stor02 );
+
+
+ //copy back the processed frame to image
+ memcpy( image.data, gray->imageData, image.xsize*image.ysize );
+}
+
+/////////////////////////////////////////////////////////
+// floatThreshMess
+//
+/////////////////////////////////////////////////////////
+void pix_opencv_contours_boundingrect :: floatMinAreaMess (float minarea)
+{
+ if (minarea>0) this->minarea = (int)minarea;
+}
+void pix_opencv_contours_boundingrect :: floatMaxAreaMess (float maxarea)
+{
+ if (maxarea>0) this->maxarea = (int)maxarea;
+}
+
+/////////////////////////////////////////////////////////
+// static member function
+//
+/////////////////////////////////////////////////////////
+void pix_opencv_contours_boundingrect :: obj_setupCallback(t_class *classPtr)
+{
+ class_addmethod(classPtr, (t_method)&pix_opencv_contours_boundingrect::floatMinAreaMessCallback,
+ gensym("minarea"), A_FLOAT, A_NULL);
+ class_addmethod(classPtr, (t_method)&pix_opencv_contours_boundingrect::floatMaxAreaMessCallback,
+ gensym("maxarea"), A_FLOAT, A_NULL);
+}
+void pix_opencv_contours_boundingrect :: floatMaxAreaMessCallback(void *data, t_floatarg maxarea)
+{
+ GetMyClass(data)->floatMaxAreaMess((float)maxarea);
+}
+void pix_opencv_contours_boundingrect :: floatMinAreaMessCallback(void *data, t_floatarg minarea)
+{
+ GetMyClass(data)->floatMinAreaMess((float)minarea);
+}
Deleted: trunk/externals/pix_opencv/pix_opencv_contours_boundingrect.cpp
===================================================================
--- trunk/externals/pix_opencv/pix_opencv_contours_boundingrect.cpp 2008-05-25 22:44:13 UTC (rev 9915)
+++ trunk/externals/pix_opencv/pix_opencv_contours_boundingrect.cpp 2008-05-25 23:07:29 UTC (rev 9916)
@@ -1,305 +0,0 @@
-////////////////////////////////////////////////////////
-//
-// GEM - Graphics Environment for Multimedia
-//
-// zmoelnig at iem.kug.ac.at
-//
-// Implementation file
-//
-// Copyright (c) 1997-2000 Mark Danks.
-// Copyright (c) G\xFCnther Geiger.
-// Copyright (c) 2001-2002 IOhannes m zmoelnig. forum::f\xFCr::uml\xE4ute. IEM
-// Copyright (c) 2002 James Tittle & Chris Clepper
-// For information on usage and redistribution, and for a DISCLAIMER OF ALL
-// WARRANTIES, see the file, "GEM.LICENSE.TERMS" in this distribution.
-//
-/////////////////////////////////////////////////////////
-
-#include "pix_opencv_contours_boundingrect.h"
-
-CPPEXTERN_NEW(pix_opencv_contours_boundingrect)
-
-/////////////////////////////////////////////////////////
-//
-// pix_opencv_contours_boundingrect
-//
-/////////////////////////////////////////////////////////
-// Constructor
-//
-/////////////////////////////////////////////////////////
-pix_opencv_contours_boundingrect :: pix_opencv_contours_boundingrect()
-{
- inlet_new(this->x_obj, &this->x_obj->ob_pd, gensym("float"), gensym("minarea"));
- inlet_new(this->x_obj, &this->x_obj->ob_pd, gensym("float"), gensym("maxarea"));
- m_dataout = outlet_new(this->x_obj, 0);
- minarea = 1;
- maxarea = 320*240;
- comp_xsize = 0;
- comp_ysize = 0;
- orig = NULL;
- gray = NULL;
- cnt_img = NULL;
- rgb = NULL;
-
-}
-
-/////////////////////////////////////////////////////////
-// Destructor
-//
-/////////////////////////////////////////////////////////
-pix_opencv_contours_boundingrect :: ~pix_opencv_contours_boundingrect()
-{
- //Destroy cv_images to clean memory
- cvReleaseImage(&orig);
- cvReleaseImage(&gray);
- cvReleaseImage(&cnt_img);
- cvReleaseImage(&rgb);
-}
-
-/////////////////////////////////////////////////////////
-// processImage
-//
-/////////////////////////////////////////////////////////
-void pix_opencv_contours_boundingrect :: processRGBAImage(imageStruct &image)
-{
- unsigned char *pixels = image.data;
-
- if ((this->comp_xsize!=image.xsize)||(this->comp_ysize!=image.ysize)||(!orig)) {
-
- this->comp_xsize = image.xsize;
- this->comp_ysize = image.ysize;
-
- //Destroy cv_images to clean memory
- cvReleaseImage(&orig);
- cvReleaseImage(&gray);
- cvReleaseImage(&cnt_img);
- cvReleaseImage(&rgb);
-
- //create the orig image with new size
- orig = cvCreateImage(cvSize(image.xsize,image.ysize), IPL_DEPTH_8U, 4);
-
- // Create the output images with new sizes
- rgb = cvCreateImage(cvSize(orig->width,orig->height), IPL_DEPTH_8U, 3);
- cnt_img = cvCreateImage(cvSize(orig->width,orig->height), IPL_DEPTH_8U, 3);
-
- gray = cvCreateImage(cvSize(orig->width,orig->height), IPL_DEPTH_8U, 1);
-
- }
- // Here we make a copy of the pixel data from image to orig->imageData
- // orig is a IplImage struct, the default image type in openCV, take a look on the IplImage data structure here
- // http://www.cs.iit.edu/~agam/cs512/lect-notes/opencv-intro/opencv-intro.html
- memcpy( orig->imageData, image.data, image.xsize*image.ysize*4 );
-
- // Convert to grayscale
- cvCvtColor(orig, gray, CV_RGBA2GRAY);
-
- CvSeq* contours;
- CvMemStorage* stor02;
- stor02 = cvCreateMemStorage(0);
-
- cvFindContours( gray, stor02, &contours, sizeof(CvContour), CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0) );
- if (contours) contours = cvApproxPoly( contours, sizeof(CvContour), stor02, CV_POLY_APPROX_DP, 3, 1 );
-
-
- int i = 0; // Indicator of cycles.
- for( ; contours != 0; contours = contours->h_next )
- {
- int count = contours->total; // This is number point in contour
- CvRect rect;
-
- rect = cvContourBoundingRect( contours, 1);
- if ( ( (rect.width*rect.height) > minarea ) && ( (rect.width*rect.height) < maxarea ) ) {
- cvRectangle( orig, cvPoint(rect.x,rect.y), cvPoint(rect.x+rect.width,rect.y+rect.height), CV_RGB(255,0,0), 2, 8 , 0 );
-
- t_atom rlist[4];
- SETFLOAT(&rlist[0], i);
- SETFLOAT(&rlist[1], rect.x);
- SETFLOAT(&rlist[2], rect.y);
- SETFLOAT(&rlist[3], rect.width);
- SETFLOAT(&rlist[4], rect.height);
-
- outlet_list( m_dataout, 0, 5, rlist );
- i++;
- }
-
- }
-
- cvReleaseMemStorage( &stor02 );
-
-
- //copy back the processed frame to image
- memcpy( image.data, orig->imageData, image.xsize*image.ysize*4 );
-}
-
-void pix_opencv_contours_boundingrect :: processRGBImage(imageStruct &image)
-{
- unsigned char *pixels = image.data;
-
- if ((this->comp_xsize!=image.xsize)||(this->comp_ysize!=image.ysize)||(!rgb)) {
-
- this->comp_xsize = image.xsize;
- this->comp_ysize = image.ysize;
-
- //Destroy cv_images to clean memory
- cvReleaseImage(&orig);
- cvReleaseImage(&gray);
- cvReleaseImage(&cnt_img);
- cvReleaseImage(&rgb);
-
- //create the orig image with new size
- rgb = cvCreateImage(cvSize(image.xsize,image.ysize), IPL_DEPTH_8U, 3);
-
- // Create the output images with new sizes
- cnt_img = cvCreateImage(cvSize(rgb->width,rgb->height), IPL_DEPTH_8U, 3);
-
- gray = cvCreateImage(cvSize(rgb->width,rgb->height), IPL_DEPTH_8U, 1);
-
- }
- // FEM UNA COPIA DEL PACKET A image->imageData ... http://www.cs.iit.edu/~agam/cs512/lect-notes/opencv-intro/opencv-intro.html aqui veiem la estructura de IplImage
- memcpy( rgb->imageData, image.data, image.xsize*image.ysize*3 );
-
- // Convert to grayscale
- cvCvtColor(rgb, gray, CV_RGB2GRAY);
-
- CvSeq* contours;
- CvMemStorage* stor02;
- stor02 = cvCreateMemStorage(0);
-
- cvFindContours( gray, stor02, &contours, sizeof(CvContour), CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0) );
- if (contours) contours = cvApproxPoly( contours, sizeof(CvContour), stor02, CV_POLY_APPROX_DP, 3, 1 );
-
-
- int i = 0; // Indicator of cycles.
- for( ; contours != 0; contours = contours->h_next )
- {
- int count = contours->total; // This is number point in contour
- CvRect rect;
-
- rect = cvContourBoundingRect( contours, 1);
- if ( ( (rect.width*rect.height) > minarea ) && ( (rect.width*rect.height) < maxarea ) ) {
- cvRectangle( rgb, cvPoint(rect.x,rect.y), cvPoint(rect.x+rect.width,rect.y+rect.height), CV_RGB(255,0,0), 2, 8 , 0 );
-
- t_atom rlist[4];
- SETFLOAT(&rlist[0], i);
- SETFLOAT(&rlist[1], rect.x);
- SETFLOAT(&rlist[2], rect.y);
- SETFLOAT(&rlist[3], rect.width);
- SETFLOAT(&rlist[4], rect.height);
-
- outlet_list( m_dataout, 0, 5, rlist );
- i++;
- }
-
- }
-
- cvReleaseMemStorage( &stor02 );
-
-
- //cvShowImage(wndname, cedge);
- memcpy( image.data, rgb->imageData, image.xsize*image.ysize*3 );
-}
-
-void pix_opencv_contours_boundingrect :: processYUVImage(imageStruct &image)
-{
-}
-
-void pix_opencv_contours_boundingrect :: processGrayImage(imageStruct &image)
-{
-
- if ((this->comp_xsize!=image.xsize)||(this->comp_ysize!=image.ysize)||(!orig)) {
-
- this->comp_xsize = image.xsize;
- this->comp_ysize = image.ysize;
-
- //Destroy cv_images to clean memory
- cvReleaseImage(&orig);
- cvReleaseImage(&gray);
- cvReleaseImage(&cnt_img);
- cvReleaseImage(&rgb);
-
- //create the orig image with new size
- orig = cvCreateImage(cvSize(image.xsize,image.ysize), IPL_DEPTH_8U, 4);
-
- // Create the output images with new sizes
- rgb = cvCreateImage(cvSize(orig->width,orig->height), IPL_DEPTH_8U, 3);
- cnt_img = cvCreateImage(cvSize(orig->width,orig->height), IPL_DEPTH_8U, 3);
-
- gray = cvCreateImage(cvSize(orig->width,orig->height), IPL_DEPTH_8U, 1);
-
- }
- // Here we make a copy of the pixel data from image to orig->imageData
- // orig is a IplImage struct, the default image type in openCV, take a look on the IplImage data structure here
- // http://www.cs.iit.edu/~agam/cs512/lect-notes/opencv-intro/opencv-intro.html
- memcpy( gray->imageData, image.data, image.xsize*image.ysize );
-
-
- CvSeq* contours;
- CvMemStorage* stor02;
- stor02 = cvCreateMemStorage(0);
-
- cvFindContours( gray, stor02, &contours, sizeof(CvContour), CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0) );
- if (contours) contours = cvApproxPoly( contours, sizeof(CvContour), stor02, CV_POLY_APPROX_DP, 3, 1 );
-
-
- int i = 0; // Indicator of cycles.
- for( ; contours != 0; contours = contours->h_next )
- {
- int count = contours->total; // This is number point in contour
- CvRect rect;
-
- rect = cvContourBoundingRect( contours, 1);
- if ( ( (rect.width*rect.height) > minarea ) && ( (rect.width*rect.height) < maxarea ) ) {
- cvRectangle( gray, cvPoint(rect.x,rect.y), cvPoint(rect.x+rect.width,rect.y+rect.height), CV_RGB(255,0,0), 2, 8 , 0 );
-
- t_atom rlist[4];
- SETFLOAT(&rlist[0], i);
- SETFLOAT(&rlist[1], rect.x);
- SETFLOAT(&rlist[2], rect.y);
- SETFLOAT(&rlist[3], rect.width);
- SETFLOAT(&rlist[4], rect.height);
-
- outlet_list( m_dataout, 0, 5, rlist );
- i++;
- }
-
- }
-
- cvReleaseMemStorage( &stor02 );
-
-
- //copy back the processed frame to image
- memcpy( image.data, gray->imageData, image.xsize*image.ysize );
-}
-
-/////////////////////////////////////////////////////////
-// floatThreshMess
-//
-/////////////////////////////////////////////////////////
-void pix_opencv_contours_boundingrect :: floatMinAreaMess (float minarea)
-{
- if (minarea>0) this->minarea = (int)minarea;
-}
-void pix_opencv_contours_boundingrect :: floatMaxAreaMess (float maxarea)
-{
- if (maxarea>0) this->maxarea = (int)maxarea;
-}
-
-/////////////////////////////////////////////////////////
-// static member function
-//
-/////////////////////////////////////////////////////////
-void pix_opencv_contours_boundingrect :: obj_setupCallback(t_class *classPtr)
-{
- class_addmethod(classPtr, (t_method)&pix_opencv_contours_boundingrect::floatMinAreaMessCallback,
- gensym("minarea"), A_FLOAT, A_NULL);
- class_addmethod(classPtr, (t_method)&pix_opencv_contours_boundingrect::floatMaxAreaMessCallback,
- gensym("maxarea"), A_FLOAT, A_NULL);
-}
-void pix_opencv_contours_boundingrect :: floatMaxAreaMessCallback(void *data, t_floatarg maxarea)
-{
- GetMyClass(data)->floatMaxAreaMess((float)maxarea);
-}
-void pix_opencv_contours_boundingrect :: floatMinAreaMessCallback(void *data, t_floatarg minarea)
-{
- GetMyClass(data)->floatMinAreaMess((float)minarea);
-}
Added: trunk/externals/pix_opencv/pix_opencv_contours_convexity.cc
===================================================================
--- trunk/externals/pix_opencv/pix_opencv_contours_convexity.cc (rev 0)
+++ trunk/externals/pix_opencv/pix_opencv_contours_convexity.cc 2008-05-25 23:07:29 UTC (rev 9916)
@@ -0,0 +1,684 @@
+////////////////////////////////////////////////////////
+//
+// GEM - Graphics Environment for Multimedia
+//
+// zmoelnig at iem.kug.ac.at
+//
+// Implementation file
+//
+// Copyright (c) 1997-2000 Mark Danks.
+// Copyright (c) G\xFCnther Geiger.
+// Copyright (c) 2001-2002 IOhannes m zmoelnig. forum::f\xFCr::uml\xE4ute. IEM
+// Copyright (c) 2002 James Tittle & Chris Clepper
+// For information on usage and redistribution, and for a DISCLAIMER OF ALL
+// WARRANTIES, see the file, "GEM.LICENSE.TERMS" in this distribution.
+//
+/////////////////////////////////////////////////////////
+
+#include "pix_opencv_contours_convexity.h"
+
+CPPEXTERN_NEW(pix_opencv_contours_convexity)
+
+/////////////////////////////////////////////////////////
+//
+// pix_opencv_contours_convexity
+//
+/////////////////////////////////////////////////////////
+// Constructor
+//
+/////////////////////////////////////////////////////////
+pix_opencv_contours_convexity :: pix_opencv_contours_convexity()
+{
+ //inlet_new(this->x_obj, &this->x_obj->ob_pd, gensym("float"), gensym("minarea"));
+ //inlet_new(this->x_obj, &this->x_obj->ob_pd, gensym("float"), gensym("maxarea"));
+ m_nomdef = outlet_new(this->x_obj, 0);
+ m_dataout = outlet_new(this->x_obj, 0);
+ minarea = 1;
+ maxarea = 320*240;
+ comp_xsize = 0;
+ comp_ysize = 0;
+ orig = NULL;
+ gray = NULL;
+ rgb = NULL;
+
+}
+
+/////////////////////////////////////////////////////////
+// Destructor
+//
+/////////////////////////////////////////////////////////
+pix_opencv_contours_convexity :: ~pix_opencv_contours_convexity()
+{
+ //Destroy cv_images to clean memory
+ cvReleaseImage(&orig);
+ cvReleaseImage(&gray);
+ cvReleaseImage(&rgb);
+}
+
+/////////////////////////////////////////////////////////
+// processImage
+//
+/////////////////////////////////////////////////////////
+void pix_opencv_contours_convexity :: processRGBAImage(imageStruct &image)
+{
+ unsigned char *pixels = image.data;
+
+ if ((this->comp_xsize!=image.xsize)||(this->comp_ysize!=image.ysize)||(!orig)) {
+
+ this->comp_xsize = image.xsize;
+ this->comp_ysize = image.ysize;
+
+ //Destroy cv_images to clean memory
+ cvReleaseImage(&orig);
+ cvReleaseImage(&gray);
+ cvReleaseImage(&rgb);
+
+ //create the orig image with new size
+ orig = cvCreateImage(cvSize(image.xsize,image.ysize), IPL_DEPTH_8U, 4);
+
+ // Create the output images with new sizes
+ rgb = cvCreateImage(cvSize(orig->width,orig->height), IPL_DEPTH_8U, 3);
+
+ gray = cvCreateImage(cvSize(orig->width,orig->height), IPL_DEPTH_8U, 1);
+
+ }
+ // Here we make a copy of the pixel data from image to orig->imageData
+ // orig is a IplImage struct, the default image type in openCV, take a look on the IplImage data structure here
+ // http://www.cs.iit.edu/~agam/cs512/lect-notes/opencv-intro/opencv-intro.html
+ memcpy( orig->imageData, image.data, image.xsize*image.ysize*4 );
+
+ // Convert to grayscale
+ cvCvtColor(orig, gray, CV_RGBA2GRAY);
+ cvCvtColor(orig, rgb, CV_RGBA2RGB);
+
+ CvSeq* seqhull;
+ CvSeq* defects;
+ CvSeq* contours;
+ int* hull;
+ int hullsize;
+ CvPoint* PointArray;
+ CvConvexityDefect* defectArray;
+ CvMemStorage* stor02;
+ CvMemStorage* stor03;
+ stor02 = cvCreateMemStorage(0);
+ stor03 = cvCreateMemStorage(0);
+
+
+ cvFindContours( gray, stor02, &contours, sizeof(CvContour), CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0) );
+ if (contours) contours = cvApproxPoly( contours, sizeof(CvContour), stor02, CV_POLY_APPROX_DP, 3, 1 );
+
+ int i = 0;
+ int area = 0;
+ int selected = -1;
+
+ //busquem el contorn mes gran
+ CvSeq* first_contour;
+ first_contour = contours;
+ for( ; contours != 0; contours = contours->h_next )
+ {
+ CvRect rect;
+ int count = contours->total;
+ rect = cvContourBoundingRect(contours, 1);
+ if ( (rect.width*rect.height) > area )
+ {
+ selected = i;
+ area = rect.width*rect.height;
+ }
+ i++;
+ }
+
+ contours = first_contour;
+
+ int k = 0;
+ for( ; contours != 0; contours = contours->h_next )
+ {
+ int i; // Indicator of cycles.
+ int count = contours->total; // This is number point in contour
+ CvPoint center;
+ CvSize size;
+ CvRect rect;
+
+ rect = cvContourBoundingRect( contours, 1);
+ if ( (k==selected) ) {
+
+
+ //fprintf(stderr,"malloc\n");
+ // Alloc memory for contour point set.
+ PointArray = (CvPoint*)malloc( count*sizeof(CvPoint) );
+
+ // Alloc memory for indices of convex hull vertices.
+ hull = (int*)malloc(sizeof(int)*count);
+
+ // Get contour point set.
+ //fprintf(stderr,"cvCvtSeqToArray\n");
+ cvCvtSeqToArray(contours, PointArray, CV_WHOLE_SEQ);
+
+
+ // Find convex hull for curent contour.
+ //fprintf(stderr,"cvConvexHull\n");
+ cvConvexHull( PointArray,
+ count,
+ NULL,
+ CV_COUNTER_CLOCKWISE,
+ hull,
+ &hullsize);
+
+ // Find convex hull for current contour.
+ // This required for cvConvexityDefects().
+ //fprintf(stderr,"cvConvexHull2\n");
+ seqhull = cvConvexHull2( contours,0,
+ CV_COUNTER_CLOCKWISE,
+ 0);
+
+ // This required for cvConvexityDefects().
+ // Otherwise cvConvexityDefects() falled.
+ if( hullsize < 4 )
+ continue;
+
+ // Find defects of convexity of current contours.
+ //fprintf(stderr,"cvConvexityDefects\n");
+ defects = cvConvexityDefects( contours,
+ seqhull,
+ stor03);
+ int j=0;
+ // This cycle marks all defects of convexity of current contours.
+ for(;defects;defects = defects->h_next)
+ {
+ int nomdef = defects->total; // defect amount
+ outlet_float( m_nomdef, nomdef );
+
+ if(nomdef == 0)
+ continue;
+
+ // Alloc memory for defect set.
+ //fprintf(stderr,"malloc\n");
+ defectArray = (CvConvexityDefect*)malloc(sizeof(CvConvexityDefect)*nomdef);
+
+ // Get defect set.
+ //fprintf(stderr,"cvCvtSeqToArray\n");
+ cvCvtSeqToArray(defects,defectArray, CV_WHOLE_SEQ);
+
+
+ // Draw marks for all defects.
+ for(i=0; i<nomdef; i++)
+ {
+ cvLine(rgb, *(defectArray[i].start), *(defectArray[i].depth_point),CV_RGB(0,0,255),1, CV_AA, 0 );
+ cvCircle( rgb, *(defectArray[i].depth_point), 5, CV_RGB(0,255,0), -1, 8,0);
+ cvCircle( rgb, *(defectArray[i].start), 5, CV_RGB(0,255,0), -1, 8,0);
+ cvLine(rgb, *(defectArray[i].depth_point), *(defectArray[i].end),CV_RGB(0,0,255),1, CV_AA, 0 );
+ t_atom rlist[7];
+ SETFLOAT(&rlist[0], i);
+ SETFLOAT(&rlist[1], defectArray[i].start->x);
+ SETFLOAT(&rlist[2], defectArray[i].start->y);
+ SETFLOAT(&rlist[3], defectArray[i].depth_point->x);
+ SETFLOAT(&rlist[4], defectArray[i].depth_point->y);
+ SETFLOAT(&rlist[5], defectArray[i].end->x);
+ SETFLOAT(&rlist[6], defectArray[i].end->y);
+ outlet_list( m_dataout, 0, 7, rlist );
+ }
+
+ j++;
+
+ // Free memory.
+ free(defectArray);
+ }
+
+ // Draw current contour.
+ //cvDrawContours(x->cnt_img,contours,CV_RGB(255,255,255),CV_RGB(255,255,255),0,1, 8);
+ cvDrawContours( rgb, contours, CV_RGB(255,0,0), CV_RGB(0,255,0), 2, 2, CV_AA, cvPoint(0,0) );
+
+ // Draw convex hull for current contour.
+ for(i=0; i<hullsize-1; i++)
+ {
+ cvLine(rgb, PointArray[hull[i]],
+ PointArray[hull[i+1]],CV_RGB(255,255,255),1, CV_AA, 0 );
+ }
+ cvLine(rgb, PointArray[hull[hullsize-1]],
+ PointArray[hull[0]],CV_RGB(255,255,255),1, CV_AA, 0 );
+
+
+ // Free memory.
+ free(PointArray);
+ free(hull);
+ /* replace CV_FILLED with 1 to see the outlines */
+ //cvDrawContours( x->cnt_img, contours, CV_RGB(255,0,0), CV_RGB(0,255,0), x->levels, 3, CV_AA, cvPoint(0,0) );
+ //cvConvexityDefects( contours, cvConvexHull2( contours, 0, CV_CLOCKWISE, 0 ), stor022 );
+ }
+ k++;
+ }
+
+ cvReleaseMemStorage( &stor03 );
+ cvReleaseMemStorage( &stor02 );
+ //if (defects) cvClearSeq(defects);
+ //if (seqhull) cvClearSeq(seqhull);
+
+ cvCvtColor(rgb, orig, CV_RGB2RGBA);
+ //copy back the processed frame to image
+ memcpy( image.data, orig->imageData, image.xsize*image.ysize*4 );
+}
+
+void pix_opencv_contours_convexity :: processRGBImage(imageStruct &image)
+{
+ unsigned char *pixels = image.data;
+
+ if ((this->comp_xsize!=image.xsize)||(this->comp_ysize!=image.ysize)||(!rgb)) {
+
+ this->comp_xsize = image.xsize;
+ this->comp_ysize = image.ysize;
+
+ //Destroy cv_images to clean memory
+ cvReleaseImage(&orig);
+ cvReleaseImage(&gray);
+ cvReleaseImage(&rgb);
+
+ //create the orig image with new size
+ rgb = cvCreateImage(cvSize(image.xsize,image.ysize), IPL_DEPTH_8U, 3);
+
+ // Create the output images with new sizes
+
+ gray = cvCreateImage(cvSize(rgb->width,rgb->height), IPL_DEPTH_8U, 1);
+
+ }
+ // FEM UNA COPIA DEL PACKET A image->imageData ... http://www.cs.iit.edu/~agam/cs512/lect-notes/opencv-intro/opencv-intro.html aqui veiem la estructura de IplImage
+ memcpy( rgb->imageData, image.data, image.xsize*image.ysize*3 );
+
+ // Convert to grayscale
+ cvCvtColor(rgb, gray, CV_RGB2GRAY);
+
+
+ CvSeq* seqhull;
+ CvSeq* defects;
+ CvSeq* contours;
+ int* hull;
+ int hullsize;
+ CvPoint* PointArray;
+ CvConvexityDefect* defectArray;
+ CvMemStorage* stor02;
+ CvMemStorage* stor03;
+ stor02 = cvCreateMemStorage(0);
+ stor03 = cvCreateMemStorage(0);
+
+
+ cvFindContours( gray, stor02, &contours, sizeof(CvContour), CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0) );
+ if (contours) contours = cvApproxPoly( contours, sizeof(CvContour), stor02, CV_POLY_APPROX_DP, 3, 1 );
+
+ int i = 0;
+ int area = 0;
+ int selected = -1;
+
+ //busquem el contorn mes gran
+ CvSeq* first_contour;
+ first_contour = contours;
+ for( ; contours != 0; contours = contours->h_next )
+ {
+ CvRect rect;
+ int count = contours->total;
+ rect = cvContourBoundingRect(contours, 1);
+ if ( (rect.width*rect.height) > area )
+ {
+ selected = i;
+ area = rect.width*rect.height;
+ }
+ i++;
+ }
+
+ contours = first_contour;
+
+ int k = 0;
+ for( ; contours != 0; contours = contours->h_next )
+ {
+ int i; // Indicator of cycles.
+ int count = contours->total; // This is number point in contour
+ CvPoint center;
+ CvSize size;
+ CvRect rect;
+
+ rect = cvContourBoundingRect( contours, 1);
+ if ( (k==selected) ) {
+
+
+ //fprintf(stderr,"malloc\n");
+ // Alloc memory for contour point set.
+ PointArray = (CvPoint*)malloc( count*sizeof(CvPoint) );
+
+ // Alloc memory for indices of convex hull vertices.
+ hull = (int*)malloc(sizeof(int)*count);
+
+ // Get contour point set.
+ //fprintf(stderr,"cvCvtSeqToArray\n");
+ cvCvtSeqToArray(contours, PointArray, CV_WHOLE_SEQ);
+
+
+ // Find convex hull for curent contour.
+ //fprintf(stderr,"cvConvexHull\n");
+ cvConvexHull( PointArray,
+ count,
+ NULL,
+ CV_COUNTER_CLOCKWISE,
+ hull,
+ &hullsize);
+
+ // Find convex hull for current contour.
+ // This required for cvConvexityDefects().
+ //fprintf(stderr,"cvConvexHull2\n");
+ seqhull = cvConvexHull2( contours,0,
+ CV_COUNTER_CLOCKWISE,
+ 0);
+
+ // This required for cvConvexityDefects().
+ // Otherwise cvConvexityDefects() falled.
+ if( hullsize < 4 )
+ continue;
+
+ // Find defects of convexity of current contours.
+ //fprintf(stderr,"cvConvexityDefects\n");
+ defects = cvConvexityDefects( contours,
+ seqhull,
+ stor03);
+ int j=0;
+ // This cycle marks all defects of convexity of current contours.
+ for(;defects;defects = defects->h_next)
+ {
+ int nomdef = defects->total; // defect amount
+ outlet_float( m_nomdef, nomdef );
+
+ if(nomdef == 0)
+ continue;
+
+ // Alloc memory for defect set.
+ //fprintf(stderr,"malloc\n");
+ defectArray = (CvConvexityDefect*)malloc(sizeof(CvConvexityDefect)*nomdef);
+
+ // Get defect set.
+ //fprintf(stderr,"cvCvtSeqToArray\n");
+ cvCvtSeqToArray(defects,defectArray, CV_WHOLE_SEQ);
+
+
+ // Draw marks for all defects.
+ for(i=0; i<nomdef; i++)
+ {
+ cvLine(rgb, *(defectArray[i].start), *(defectArray[i].depth_point),CV_RGB(0,0,255),1, CV_AA, 0 );
+ cvCircle( rgb, *(defectArray[i].depth_point), 5, CV_RGB(0,255,0), -1, 8,0);
+ cvCircle( rgb, *(defectArray[i].start), 5, CV_RGB(0,255,0), -1, 8,0);
+ cvLine(rgb, *(defectArray[i].depth_point), *(defectArray[i].end),CV_RGB(0,0,255),1, CV_AA, 0 );
+ t_atom rlist[7];
+ SETFLOAT(&rlist[0], i);
+ SETFLOAT(&rlist[1], defectArray[i].start->x);
+ SETFLOAT(&rlist[2], defectArray[i].start->y);
+ SETFLOAT(&rlist[3], defectArray[i].depth_point->x);
+ SETFLOAT(&rlist[4], defectArray[i].depth_point->y);
+ SETFLOAT(&rlist[5], defectArray[i].end->x);
+ SETFLOAT(&rlist[6], defectArray[i].end->y);
+ outlet_list( m_dataout, 0, 7, rlist );
+ }
+
+ j++;
+
+ // Free memory.
+ free(defectArray);
+ }
+
+ // Draw current contour.
+ //cvDrawContours(x->cnt_img,contours,CV_RGB(255,255,255),CV_RGB(255,255,255),0,1, 8);
+ cvDrawContours( rgb, contours, CV_RGB(255,0,0), CV_RGB(0,255,0), 2, 2, CV_AA, cvPoint(0,0) );
+
+ // Draw convex hull for current contour.
+ for(i=0; i<hullsize-1; i++)
+ {
+ cvLine(rgb, PointArray[hull[i]],
+ PointArray[hull[i+1]],CV_RGB(255,255,255),1, CV_AA, 0 );
+ }
+ cvLine(rgb, PointArray[hull[hullsize-1]],
+ PointArray[hull[0]],CV_RGB(255,255,255),1, CV_AA, 0 );
+
+
+ // Free memory.
+ free(PointArray);
+ free(hull);
+ /* replace CV_FILLED with 1 to see the outlines */
+ //cvDrawContours( x->cnt_img, contours, CV_RGB(255,0,0), CV_RGB(0,255,0), x->levels, 3, CV_AA, cvPoint(0,0) );
+ //cvConvexityDefects( contours, cvConvexHull2( contours, 0, CV_CLOCKWISE, 0 ), stor022 );
+ }
+ k++;
+ }
+
+ cvReleaseMemStorage( &stor03 );
+ cvReleaseMemStorage( &stor02 );
+ //if (defects) cvClearSeq(defects);
+ //if (seqhull) cvClearSeq(seqhull);
+
+ //cvShowImage(wndname, cedge);
+ memcpy( image.data, rgb->imageData, image.xsize*image.ysize*3 );
+}
+
+void pix_opencv_contours_convexity :: processYUVImage(imageStruct &image)
+{
+}
+
+void pix_opencv_contours_convexity :: processGrayImage(imageStruct &image)
+{
+
+ if ((this->comp_xsize!=image.xsize)||(this->comp_ysize!=image.ysize)||(!orig)) {
+
+ this->comp_xsize = image.xsize;
+ this->comp_ysize = image.ysize;
+
+ //Destroy cv_images to clean memory
+ cvReleaseImage(&orig);
+ cvReleaseImage(&gray);
+ cvReleaseImage(&rgb);
+
+ //create the orig image with new size
+ orig = cvCreateImage(cvSize(image.xsize,image.ysize), IPL_DEPTH_8U, 4);
+
+ // Create the output images with new sizes
+ rgb = cvCreateImage(cvSize(orig->width,orig->height), IPL_DEPTH_8U, 3);
+
+ gray = cvCreateImage(cvSize(orig->width,orig->height), IPL_DEPTH_8U, 1);
+
+ }
+ // Here we make a copy of the pixel data from image to orig->imageData
+ // orig is a IplImage struct, the default image type in openCV, take a look on the IplImage data structure here
+ // http://www.cs.iit.edu/~agam/cs512/lect-notes/opencv-intro/opencv-intro.html
+ memcpy( gray->imageData, image.data, image.xsize*image.ysize );
+ cvCvtColor(gray, rgb, CV_GRAY2RGB);
+
+ CvSeq* seqhull;
+ CvSeq* defects;
+ CvSeq* contours;
+ int* hull;
+ int hullsize;
+ CvPoint* PointArray;
+ CvConvexityDefect* defectArray;
+ CvMemStorage* stor02;
+ CvMemStorage* stor03;
+ stor02 = cvCreateMemStorage(0);
+ stor03 = cvCreateMemStorage(0);
+
+
+ cvFindContours( gray, stor02, &contours, sizeof(CvContour), CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0) );
+ if (contours) contours = cvApproxPoly( contours, sizeof(CvContour), stor02, CV_POLY_APPROX_DP, 3, 1 );
+
+ int i = 0;
+ int area = 0;
+ int selected = -1;
+
+ //busquem el contorn mes gran
+ CvSeq* first_contour;
+ first_contour = contours;
+ for( ; contours != 0; contours = contours->h_next )
+ {
+ CvRect rect;
+ int count = contours->total;
+ rect = cvContourBoundingRect(contours, 1);
+ if ( (rect.width*rect.height) > area )
+ {
+ selected = i;
+ area = rect.width*rect.height;
+ }
+ i++;
+ }
+
+ contours = first_contour;
+
+ int k = 0;
+ for( ; contours != 0; contours = contours->h_next )
+ {
+ int i; // Indicator of cycles.
+ int count = contours->total; // This is number point in contour
+ CvPoint center;
+ CvSize size;
+ CvRect rect;
+
+ rect = cvContourBoundingRect( contours, 1);
+ if ( (k==selected) ) {
+
+
+ //fprintf(stderr,"malloc\n");
+ // Alloc memory for contour point set.
+ PointArray = (CvPoint*)malloc( count*sizeof(CvPoint) );
+
+ // Alloc memory for indices of convex hull vertices.
+ hull = (int*)malloc(sizeof(int)*count);
+
+ // Get contour point set.
+ //fprintf(stderr,"cvCvtSeqToArray\n");
+ cvCvtSeqToArray(contours, PointArray, CV_WHOLE_SEQ);
+
+
+ // Find convex hull for curent contour.
+ //fprintf(stderr,"cvConvexHull\n");
+ cvConvexHull( PointArray,
+ count,
+ NULL,
+ CV_COUNTER_CLOCKWISE,
+ hull,
+ &hullsize);
+
+ // Find convex hull for current contour.
+ // This required for cvConvexityDefects().
+ //fprintf(stderr,"cvConvexHull2\n");
+ seqhull = cvConvexHull2( contours,0,
+ CV_COUNTER_CLOCKWISE,
+ 0);
+
+ // This required for cvConvexityDefects().
+ // Otherwise cvConvexityDefects() falled.
+ if( hullsize < 4 )
+ continue;
+
+ // Find defects of convexity of current contours.
+ //fprintf(stderr,"cvConvexityDefects\n");
+ defects = cvConvexityDefects( contours,
+ seqhull,
+ stor03);
+ int j=0;
+ // This cycle marks all defects of convexity of current contours.
+ for(;defects;defects = defects->h_next)
+ {
+ int nomdef = defects->total; // defect amount
+ outlet_float( m_nomdef, nomdef );
+
+ if(nomdef == 0)
+ continue;
+
+ // Alloc memory for defect set.
+ //fprintf(stderr,"malloc\n");
+ defectArray = (CvConvexityDefect*)malloc(sizeof(CvConvexityDefect)*nomdef);
+
+ // Get defect set.
+ //fprintf(stderr,"cvCvtSeqToArray\n");
+ cvCvtSeqToArray(defects,defectArray, CV_WHOLE_SEQ);
+
+
+ // Draw marks for all defects.
+ for(i=0; i<nomdef; i++)
+ {
+ cvLine(rgb, *(defectArray[i].start), *(defectArray[i].depth_point),CV_RGB(0,0,255),1, CV_AA, 0 );
+ cvCircle( rgb, *(defectArray[i].depth_point), 5, CV_RGB(0,255,0), -1, 8,0);
+ cvCircle( rgb, *(defectArray[i].start), 5, CV_RGB(0,255,0), -1, 8,0);
+ cvLine(rgb, *(defectArray[i].depth_point), *(defectArray[i].end),CV_RGB(0,0,255),1, CV_AA, 0 );
+ t_atom rlist[7];
+ SETFLOAT(&rlist[0], i);
+ SETFLOAT(&rlist[1], defectArray[i].start->x);
+ SETFLOAT(&rlist[2], defectArray[i].start->y);
+ SETFLOAT(&rlist[3], defectArray[i].depth_point->x);
+ SETFLOAT(&rlist[4], defectArray[i].depth_point->y);
+ SETFLOAT(&rlist[5], defectArray[i].end->x);
+ SETFLOAT(&rlist[6], defectArray[i].end->y);
+ outlet_list( m_dataout, 0, 7, rlist );
+ }
+
+ j++;
+
+ // Free memory.
+ free(defectArray);
+ }
+
+ // Draw current contour.
+ //cvDrawContours(x->cnt_img,contours,CV_RGB(255,255,255),CV_RGB(255,255,255),0,1, 8);
+ cvDrawContours( rgb, contours, CV_RGB(255,0,0), CV_RGB(0,255,0), 2, 2, CV_AA, cvPoint(0,0) );
+
+ // Draw convex hull for current contour.
+ for(i=0; i<hullsize-1; i++)
+ {
+ cvLine(rgb, PointArray[hull[i]],
+ PointArray[hull[i+1]],CV_RGB(255,255,255),1, CV_AA, 0 );
+ }
+ cvLine(rgb, PointArray[hull[hullsize-1]],
+ PointArray[hull[0]],CV_RGB(255,255,255),1, CV_AA, 0 );
+
+
+ // Free memory.
+ free(PointArray);
+ free(hull);
+ /* replace CV_FILLED with 1 to see the outlines */
+ //cvDrawContours( x->cnt_img, contours, CV_RGB(255,0,0), CV_RGB(0,255,0), x->levels, 3, CV_AA, cvPoint(0,0) );
+ //cvConvexityDefects( contours, cvConvexHull2( contours, 0, CV_CLOCKWISE, 0 ), stor022 );
+ }
+ k++;
+ }
+
+ cvReleaseMemStorage( &stor03 );
+ cvReleaseMemStorage( &stor02 );
+ //if (defects) cvClearSeq(defects);
+ //if (seqhull) cvClearSeq(seqhull);
+
+ cvCvtColor(rgb, gray, CV_RGB2GRAY);
+
+ //copy back the processed frame to image
+ memcpy( image.data, gray->imageData, image.xsize*image.ysize );
+}
+
+/////////////////////////////////////////////////////////
+// floatThreshMess
+//
+/////////////////////////////////////////////////////////
+void pix_opencv_contours_convexity :: floatMinAreaMess (float minarea)
+{
+ if (minarea>0) this->minarea = (int)minarea;
+}
+void pix_opencv_contours_convexity :: floatMaxAreaMess (float maxarea)
+{
+ if (maxarea>0) this->maxarea = (int)maxarea;
+}
+
+/////////////////////////////////////////////////////////
+// static member function
+//
+/////////////////////////////////////////////////////////
+void pix_opencv_contours_convexity :: obj_setupCallback(t_class *classPtr)
+{
+ class_addmethod(classPtr, (t_method)&pix_opencv_contours_convexity::floatMinAreaMessCallback,
+ gensym("minarea"), A_FLOAT, A_NULL);
+ class_addmethod(classPtr, (t_method)&pix_opencv_contours_convexity::floatMaxAreaMessCallback,
+ gensym("maxarea"), A_FLOAT, A_NULL);
+}
+void pix_opencv_contours_convexity :: floatMaxAreaMessCallback(void *data, t_floatarg maxarea)
+{
+ GetMyClass(data)->floatMaxAreaMess((float)maxarea);
+}
+void pix_opencv_contours_convexity :: floatMinAreaMessCallback(void *data, t_floatarg minarea)
+{
+ GetMyClass(data)->floatMinAreaMess((float)minarea);
+}
Deleted: trunk/externals/pix_opencv/pix_opencv_contours_convexity.cpp
===================================================================
--- trunk/externals/pix_opencv/pix_opencv_contours_convexity.cpp 2008-05-25 22:44:13 UTC (rev 9915)
+++ trunk/externals/pix_opencv/pix_opencv_contours_convexity.cpp 2008-05-25 23:07:29 UTC (rev 9916)
@@ -1,684 +0,0 @@
-////////////////////////////////////////////////////////
-//
-// GEM - Graphics Environment for Multimedia
-//
-// zmoelnig at iem.kug.ac.at
-//
-// Implementation file
-//
-// Copyright (c) 1997-2000 Mark Danks.
-// Copyright (c) G\xFCnther Geiger.
-// Copyright (c) 2001-2002 IOhannes m zmoelnig. forum::f\xFCr::uml\xE4ute. IEM
-// Copyright (c) 2002 James Tittle & Chris Clepper
-// For information on usage and redistribution, and for a DISCLAIMER OF ALL
-// WARRANTIES, see the file, "GEM.LICENSE.TERMS" in this distribution.
-//
-/////////////////////////////////////////////////////////
-
-#include "pix_opencv_contours_convexity.h"
-
-CPPEXTERN_NEW(pix_opencv_contours_convexity)
-
-/////////////////////////////////////////////////////////
-//
-// pix_opencv_contours_convexity
-//
-/////////////////////////////////////////////////////////
-// Constructor
-//
-/////////////////////////////////////////////////////////
-pix_opencv_contours_convexity :: pix_opencv_contours_convexity()
-{
- //inlet_new(this->x_obj, &this->x_obj->ob_pd, gensym("float"), gensym("minarea"));
- //inlet_new(this->x_obj, &this->x_obj->ob_pd, gensym("float"), gensym("maxarea"));
- m_nomdef = outlet_new(this->x_obj, 0);
- m_dataout = outlet_new(this->x_obj, 0);
- minarea = 1;
- maxarea = 320*240;
- comp_xsize = 0;
- comp_ysize = 0;
- orig = NULL;
- gray = NULL;
- rgb = NULL;
-
-}
-
-/////////////////////////////////////////////////////////
-// Destructor
-//
-/////////////////////////////////////////////////////////
-pix_opencv_contours_convexity :: ~pix_opencv_contours_convexity()
-{
- //Destroy cv_images to clean memory
- cvReleaseImage(&orig);
- cvReleaseImage(&gray);
- cvReleaseImage(&rgb);
-}
-
-/////////////////////////////////////////////////////////
-// processImage
-//
-/////////////////////////////////////////////////////////
-void pix_opencv_contours_convexity :: processRGBAImage(imageStruct &image)
-{
- unsigned char *pixels = image.data;
-
- if ((this->comp_xsize!=image.xsize)||(this->comp_ysize!=image.ysize)||(!orig)) {
-
- this->comp_xsize = image.xsize;
- this->comp_ysize = image.ysize;
-
- //Destroy cv_images to clean memory
- cvReleaseImage(&orig);
- cvReleaseImage(&gray);
- cvReleaseImage(&rgb);
-
- //create the orig image with new size
- orig = cvCreateImage(cvSize(image.xsize,image.ysize), IPL_DEPTH_8U, 4);
-
- // Create the output images with new sizes
- rgb = cvCreateImage(cvSize(orig->width,orig->height), IPL_DEPTH_8U, 3);
-
- gray = cvCreateImage(cvSize(orig->width,orig->height), IPL_DEPTH_8U, 1);
-
- }
- // Here we make a copy of the pixel data from image to orig->imageData
- // orig is a IplImage struct, the default image type in openCV, take a look on the IplImage data structure here
- // http://www.cs.iit.edu/~agam/cs512/lect-notes/opencv-intro/opencv-intro.html
- memcpy( orig->imageData, image.data, image.xsize*image.ysize*4 );
-
- // Convert to grayscale
- cvCvtColor(orig, gray, CV_RGBA2GRAY);
- cvCvtColor(orig, rgb, CV_RGBA2RGB);
-
- CvSeq* seqhull;
- CvSeq* defects;
- CvSeq* contours;
- int* hull;
- int hullsize;
- CvPoint* PointArray;
- CvConvexityDefect* defectArray;
- CvMemStorage* stor02;
- CvMemStorage* stor03;
- stor02 = cvCreateMemStorage(0);
- stor03 = cvCreateMemStorage(0);
-
-
- cvFindContours( gray, stor02, &contours, sizeof(CvContour), CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0) );
- if (contours) contours = cvApproxPoly( contours, sizeof(CvContour), stor02, CV_POLY_APPROX_DP, 3, 1 );
-
- int i = 0;
- int area = 0;
- int selected = -1;
-
- //busquem el contorn mes gran
- CvSeq* first_contour;
- first_contour = contours;
- for( ; contours != 0; contours = contours->h_next )
- {
- CvRect rect;
- int count = contours->total;
- rect = cvContourBoundingRect(contours, 1);
- if ( (rect.width*rect.height) > area )
- {
- selected = i;
- area = rect.width*rect.height;
- }
- i++;
- }
-
- contours = first_contour;
-
- int k = 0;
- for( ; contours != 0; contours = contours->h_next )
- {
- int i; // Indicator of cycles.
- int count = contours->total; // This is number point in contour
- CvPoint center;
- CvSize size;
- CvRect rect;
-
- rect = cvContourBoundingRect( contours, 1);
- if ( (k==selected) ) {
-
-
- //fprintf(stderr,"malloc\n");
- // Alloc memory for contour point set.
- PointArray = (CvPoint*)malloc( count*sizeof(CvPoint) );
-
- // Alloc memory for indices of convex hull vertices.
- hull = (int*)malloc(sizeof(int)*count);
-
- // Get contour point set.
- //fprintf(stderr,"cvCvtSeqToArray\n");
- cvCvtSeqToArray(contours, PointArray, CV_WHOLE_SEQ);
-
-
- // Find convex hull for curent contour.
- //fprintf(stderr,"cvConvexHull\n");
- cvConvexHull( PointArray,
- count,
- NULL,
- CV_COUNTER_CLOCKWISE,
- hull,
- &hullsize);
-
- // Find convex hull for current contour.
- // This required for cvConvexityDefects().
- //fprintf(stderr,"cvConvexHull2\n");
- seqhull = cvConvexHull2( contours,0,
- CV_COUNTER_CLOCKWISE,
- 0);
-
- // This required for cvConvexityDefects().
- // Otherwise cvConvexityDefects() falled.
- if( hullsize < 4 )
- continue;
-
- // Find defects of convexity of current contours.
- //fprintf(stderr,"cvConvexityDefects\n");
- defects = cvConvexityDefects( contours,
- seqhull,
- stor03);
- int j=0;
- // This cycle marks all defects of convexity of current contours.
- for(;defects;defects = defects->h_next)
- {
- int nomdef = defects->total; // defect amount
- outlet_float( m_nomdef, nomdef );
-
- if(nomdef == 0)
- continue;
-
- // Alloc memory for defect set.
- //fprintf(stderr,"malloc\n");
- defectArray = (CvConvexityDefect*)malloc(sizeof(CvConvexityDefect)*nomdef);
-
- // Get defect set.
- //fprintf(stderr,"cvCvtSeqToArray\n");
- cvCvtSeqToArray(defects,defectArray, CV_WHOLE_SEQ);
-
-
- // Draw marks for all defects.
- for(i=0; i<nomdef; i++)
- {
- cvLine(rgb, *(defectArray[i].start), *(defectArray[i].depth_point),CV_RGB(0,0,255),1, CV_AA, 0 );
- cvCircle( rgb, *(defectArray[i].depth_point), 5, CV_RGB(0,255,0), -1, 8,0);
- cvCircle( rgb, *(defectArray[i].start), 5, CV_RGB(0,255,0), -1, 8,0);
- cvLine(rgb, *(defectArray[i].depth_point), *(defectArray[i].end),CV_RGB(0,0,255),1, CV_AA, 0 );
- t_atom rlist[7];
- SETFLOAT(&rlist[0], i);
- SETFLOAT(&rlist[1], defectArray[i].start->x);
- SETFLOAT(&rlist[2], defectArray[i].start->y);
- SETFLOAT(&rlist[3], defectArray[i].depth_point->x);
- SETFLOAT(&rlist[4], defectArray[i].depth_point->y);
- SETFLOAT(&rlist[5], defectArray[i].end->x);
- SETFLOAT(&rlist[6], defectArray[i].end->y);
- outlet_list( m_dataout, 0, 7, rlist );
- }
-
- j++;
-
- // Free memory.
- free(defectArray);
- }
-
- // Draw current contour.
- //cvDrawContours(x->cnt_img,contours,CV_RGB(255,255,255),CV_RGB(255,255,255),0,1, 8);
- cvDrawContours( rgb, contours, CV_RGB(255,0,0), CV_RGB(0,255,0), 2, 2, CV_AA, cvPoint(0,0) );
-
- // Draw convex hull for current contour.
- for(i=0; i<hullsize-1; i++)
- {
- cvLine(rgb, PointArray[hull[i]],
- PointArray[hull[i+1]],CV_RGB(255,255,255),1, CV_AA, 0 );
- }
- cvLine(rgb, PointArray[hull[hullsize-1]],
- PointArray[hull[0]],CV_RGB(255,255,255),1, CV_AA, 0 );
-
-
- // Free memory.
- free(PointArray);
- free(hull);
- /* replace CV_FILLED with 1 to see the outlines */
- //cvDrawContours( x->cnt_img, contours, CV_RGB(255,0,0), CV_RGB(0,255,0), x->levels, 3, CV_AA, cvPoint(0,0) );
- //cvConvexityDefects( contours, cvConvexHull2( contours, 0, CV_CLOCKWISE, 0 ), stor022 );
- }
- k++;
- }
-
- cvReleaseMemStorage( &stor03 );
- cvReleaseMemStorage( &stor02 );
- //if (defects) cvClearSeq(defects);
- //if (seqhull) cvClearSeq(seqhull);
-
- cvCvtColor(rgb, orig, CV_RGB2RGBA);
- //copy back the processed frame to image
- memcpy( image.data, orig->imageData, image.xsize*image.ysize*4 );
-}
-
-void pix_opencv_contours_convexity :: processRGBImage(imageStruct &image)
-{
- unsigned char *pixels = image.data;
-
- if ((this->comp_xsize!=image.xsize)||(this->comp_ysize!=image.ysize)||(!rgb)) {
-
- this->comp_xsize = image.xsize;
- this->comp_ysize = image.ysize;
-
- //Destroy cv_images to clean memory
- cvReleaseImage(&orig);
- cvReleaseImage(&gray);
- cvReleaseImage(&rgb);
-
- //create the orig image with new size
- rgb = cvCreateImage(cvSize(image.xsize,image.ysize), IPL_DEPTH_8U, 3);
-
- // Create the output images with new sizes
-
- gray = cvCreateImage(cvSize(rgb->width,rgb->height), IPL_DEPTH_8U, 1);
-
- }
- // FEM UNA COPIA DEL PACKET A image->imageData ... http://www.cs.iit.edu/~agam/cs512/lect-notes/opencv-intro/opencv-intro.html aqui veiem la estructura de IplImage
- memcpy( rgb->imageData, image.data, image.xsize*image.ysize*3 );
-
- // Convert to grayscale
- cvCvtColor(rgb, gray, CV_RGB2GRAY);
-
-
- CvSeq* seqhull;
- CvSeq* defects;
- CvSeq* contours;
- int* hull;
- int hullsize;
- CvPoint* PointArray;
- CvConvexityDefect* defectArray;
- CvMemStorage* stor02;
- CvMemStorage* stor03;
- stor02 = cvCreateMemStorage(0);
- stor03 = cvCreateMemStorage(0);
-
-
- cvFindContours( gray, stor02, &contours, sizeof(CvContour), CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0) );
- if (contours) contours = cvApproxPoly( contours, sizeof(CvContour), stor02, CV_POLY_APPROX_DP, 3, 1 );
-
- int i = 0;
- int area = 0;
- int selected = -1;
-
- //busquem el contorn mes gran
- CvSeq* first_contour;
- first_contour = contours;
- for( ; contours != 0; contours = contours->h_next )
- {
- CvRect rect;
- int count = contours->total;
- rect = cvContourBoundingRect(contours, 1);
- if ( (rect.width*rect.height) > area )
- {
- selected = i;
- area = rect.width*rect.height;
- }
- i++;
- }
-
- contours = first_contour;
-
- int k = 0;
- for( ; contours != 0; contours = contours->h_next )
- {
- int i; // Indicator of cycles.
- int count = contours->total; // This is number point in contour
- CvPoint center;
- CvSize size;
- CvRect rect;
-
- rect = cvContourBoundingRect( contours, 1);
- if ( (k==selected) ) {
-
-
- //fprintf(stderr,"malloc\n");
- // Alloc memory for contour point set.
- PointArray = (CvPoint*)malloc( count*sizeof(CvPoint) );
-
- // Alloc memory for indices of convex hull vertices.
- hull = (int*)malloc(sizeof(int)*count);
-
- // Get contour point set.
- //fprintf(stderr,"cvCvtSeqToArray\n");
- cvCvtSeqToArray(contours, PointArray, CV_WHOLE_SEQ);
-
-
- // Find convex hull for curent contour.
- //fprintf(stderr,"cvConvexHull\n");
- cvConvexHull( PointArray,
- count,
- NULL,
- CV_COUNTER_CLOCKWISE,
- hull,
- &hullsize);
-
- // Find convex hull for current contour.
- // This required for cvConvexityDefects().
- //fprintf(stderr,"cvConvexHull2\n");
- seqhull = cvConvexHull2( contours,0,
- CV_COUNTER_CLOCKWISE,
- 0);
-
- // This required for cvConvexityDefects().
- // Otherwise cvConvexityDefects() falled.
- if( hullsize < 4 )
- continue;
-
- // Find defects of convexity of current contours.
- //fprintf(stderr,"cvConvexityDefects\n");
- defects = cvConvexityDefects( contours,
- seqhull,
- stor03);
- int j=0;
- // This cycle marks all defects of convexity of current contours.
- for(;defects;defects = defects->h_next)
- {
- int nomdef = defects->total; // defect amount
- outlet_float( m_nomdef, nomdef );
-
- if(nomdef == 0)
- continue;
-
- // Alloc memory for defect set.
- //fprintf(stderr,"malloc\n");
- defectArray = (CvConvexityDefect*)malloc(sizeof(CvConvexityDefect)*nomdef);
-
- // Get defect set.
- //fprintf(stderr,"cvCvtSeqToArray\n");
- cvCvtSeqToArray(defects,defectArray, CV_WHOLE_SEQ);
-
-
- // Draw marks for all defects.
- for(i=0; i<nomdef; i++)
- {
- cvLine(rgb, *(defectArray[i].start), *(defectArray[i].depth_point),CV_RGB(0,0,255),1, CV_AA, 0 );
- cvCircle( rgb, *(defectArray[i].depth_point), 5, CV_RGB(0,255,0), -1, 8,0);
- cvCircle( rgb, *(defectArray[i].start), 5, CV_RGB(0,255,0), -1, 8,0);
- cvLine(rgb, *(defectArray[i].depth_point), *(defectArray[i].end),CV_RGB(0,0,255),1, CV_AA, 0 );
- t_atom rlist[7];
- SETFLOAT(&rlist[0], i);
- SETFLOAT(&rlist[1], defectArray[i].start->x);
- SETFLOAT(&rlist[2], defectArray[i].start->y);
- SETFLOAT(&rlist[3], defectArray[i].depth_point->x);
- SETFLOAT(&rlist[4], defectArray[i].depth_point->y);
- SETFLOAT(&rlist[5], defectArray[i].end->x);
- SETFLOAT(&rlist[6], defectArray[i].end->y);
- outlet_list( m_dataout, 0, 7, rlist );
- }
-
- j++;
-
- // Free memory.
- free(defectArray);
- }
-
- // Draw current contour.
- //cvDrawContours(x->cnt_img,contours,CV_RGB(255,255,255),CV_RGB(255,255,255),0,1, 8);
- cvDrawContours( rgb, contours, CV_RGB(255,0,0), CV_RGB(0,255,0), 2, 2, CV_AA, cvPoint(0,0) );
-
- // Draw convex hull for current contour.
- for(i=0; i<hullsize-1; i++)
- {
- cvLine(rgb, PointArray[hull[i]],
- PointArray[hull[i+1]],CV_RGB(255,255,255),1, CV_AA, 0 );
- }
- cvLine(rgb, PointArray[hull[hullsize-1]],
- PointArray[hull[0]],CV_RGB(255,255,255),1, CV_AA, 0 );
-
-
- // Free memory.
- free(PointArray);
- free(hull);
- /* replace CV_FILLED with 1 to see the outlines */
- //cvDrawContours( x->cnt_img, contours, CV_RGB(255,0,0), CV_RGB(0,255,0), x->levels, 3, CV_AA, cvPoint(0,0) );
- //cvConvexityDefects( contours, cvConvexHull2( contours, 0, CV_CLOCKWISE, 0 ), stor022 );
- }
- k++;
- }
-
- cvReleaseMemStorage( &stor03 );
- cvReleaseMemStorage( &stor02 );
- //if (defects) cvClearSeq(defects);
- //if (seqhull) cvClearSeq(seqhull);
-
- //cvShowImage(wndname, cedge);
- memcpy( image.data, rgb->imageData, image.xsize*image.ysize*3 );
-}
-
-void pix_opencv_contours_convexity :: processYUVImage(imageStruct &image)
-{
-}
-
-void pix_opencv_contours_convexity :: processGrayImage(imageStruct &image)
-{
-
- if ((this->comp_xsize!=image.xsize)||(this->comp_ysize!=image.ysize)||(!orig)) {
-
- this->comp_xsize = image.xsize;
- this->comp_ysize = image.ysize;
-
- //Destroy cv_images to clean memory
- cvReleaseImage(&orig);
- cvReleaseImage(&gray);
- cvReleaseImage(&rgb);
-
- //create the orig image with new size
- orig = cvCreateImage(cvSize(image.xsize,image.ysize), IPL_DEPTH_8U, 4);
-
- // Create the output images with new sizes
- rgb = cvCreateImage(cvSize(orig->width,orig->height), IPL_DEPTH_8U, 3);
-
- gray = cvCreateImage(cvSize(orig->width,orig->height), IPL_DEPTH_8U, 1);
-
- }
- // Here we make a copy of the pixel data from image to orig->imageData
- // orig is a IplImage struct, the default image type in openCV, take a look on the IplImage data structure here
- // http://www.cs.iit.edu/~agam/cs512/lect-notes/opencv-intro/opencv-intro.html
- memcpy( gray->imageData, image.data, image.xsize*image.ysize );
- cvCvtColor(gray, rgb, CV_GRAY2RGB);
-
- CvSeq* seqhull;
- CvSeq* defects;
- CvSeq* contours;
- int* hull;
- int hullsize;
- CvPoint* PointArray;
- CvConvexityDefect* defectArray;
- CvMemStorage* stor02;
- CvMemStorage* stor03;
- stor02 = cvCreateMemStorage(0);
- stor03 = cvCreateMemStorage(0);
-
-
- cvFindContours( gray, stor02, &contours, sizeof(CvContour), CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0) );
- if (contours) contours = cvApproxPoly( contours, sizeof(CvContour), stor02, CV_POLY_APPROX_DP, 3, 1 );
-
- int i = 0;
- int area = 0;
- int selected = -1;
-
- //busquem el contorn mes gran
- CvSeq* first_contour;
- first_contour = contours;
- for( ; contours != 0; contours = contours->h_next )
- {
- CvRect rect;
- int count = contours->total;
- rect = cvContourBoundingRect(contours, 1);
- if ( (rect.width*rect.height) > area )
- {
- selected = i;
- area = rect.width*rect.height;
- }
- i++;
- }
-
- contours = first_contour;
-
- int k = 0;
- for( ; contours != 0; contours = contours->h_next )
- {
- int i; // Indicator of cycles.
- int count = contours->total; // This is number point in contour
- CvPoint center;
- CvSize size;
- CvRect rect;
-
- rect = cvContourBoundingRect( contours, 1);
- if ( (k==selected) ) {
-
-
- //fprintf(stderr,"malloc\n");
- // Alloc memory for contour point set.
- PointArray = (CvPoint*)malloc( count*sizeof(CvPoint) );
-
- // Alloc memory for indices of convex hull vertices.
- hull = (int*)malloc(sizeof(int)*count);
-
- // Get contour point set.
- //fprintf(stderr,"cvCvtSeqToArray\n");
- cvCvtSeqToArray(contours, PointArray, CV_WHOLE_SEQ);
-
-
- // Find convex hull for curent contour.
- //fprintf(stderr,"cvConvexHull\n");
- cvConvexHull( PointArray,
- count,
- NULL,
- CV_COUNTER_CLOCKWISE,
- hull,
- &hullsize);
-
- // Find convex hull for current contour.
- // This required for cvConvexityDefects().
- //fprintf(stderr,"cvConvexHull2\n");
- seqhull = cvConvexHull2( contours,0,
- CV_COUNTER_CLOCKWISE,
- 0);
-
- // This required for cvConvexityDefects().
- // Otherwise cvConvexityDefects() falled.
- if( hullsize < 4 )
- continue;
-
- // Find defects of convexity of current contours.
- //fprintf(stderr,"cvConvexityDefects\n");
- defects = cvConvexityDefects( contours,
- seqhull,
- stor03);
- int j=0;
- // This cycle marks all defects of convexity of current contours.
- for(;defects;defects = defects->h_next)
- {
- int nomdef = defects->total; // defect amount
- outlet_float( m_nomdef, nomdef );
-
- if(nomdef == 0)
- continue;
-
- // Alloc memory for defect set.
- //fprintf(stderr,"malloc\n");
- defectArray = (CvConvexityDefect*)malloc(sizeof(CvConvexityDefect)*nomdef);
-
- // Get defect set.
- //fprintf(stderr,"cvCvtSeqToArray\n");
- cvCvtSeqToArray(defects,defectArray, CV_WHOLE_SEQ);
-
-
- // Draw marks for all defects.
- for(i=0; i<nomdef; i++)
- {
- cvLine(rgb, *(defectArray[i].start), *(defectArray[i].depth_point),CV_RGB(0,0,255),1, CV_AA, 0 );
- cvCircle( rgb, *(defectArray[i].depth_point), 5, CV_RGB(0,255,0), -1, 8,0);
- cvCircle( rgb, *(defectArray[i].start), 5, CV_RGB(0,255,0), -1, 8,0);
- cvLine(rgb, *(defectArray[i].depth_point), *(defectArray[i].end),CV_RGB(0,0,255),1, CV_AA, 0 );
- t_atom rlist[7];
- SETFLOAT(&rlist[0], i);
- SETFLOAT(&rlist[1], defectArray[i].start->x);
- SETFLOAT(&rlist[2], defectArray[i].start->y);
- SETFLOAT(&rlist[3], defectArray[i].depth_point->x);
- SETFLOAT(&rlist[4], defectArray[i].depth_point->y);
- SETFLOAT(&rlist[5], defectArray[i].end->x);
- SETFLOAT(&rlist[6], defectArray[i].end->y);
- outlet_list( m_dataout, 0, 7, rlist );
- }
-
- j++;
-
- // Free memory.
- free(defectArray);
- }
-
- // Draw current contour.
- //cvDrawContours(x->cnt_img,contours,CV_RGB(255,255,255),CV_RGB(255,255,255),0,1, 8);
- cvDrawContours( rgb, contours, CV_RGB(255,0,0), CV_RGB(0,255,0), 2, 2, CV_AA, cvPoint(0,0) );
-
- // Draw convex hull for current contour.
- for(i=0; i<hullsize-1; i++)
- {
- cvLine(rgb, PointArray[hull[i]],
- PointArray[hull[i+1]],CV_RGB(255,255,255),1, CV_AA, 0 );
- }
- cvLine(rgb, PointArray[hull[hullsize-1]],
- PointArray[hull[0]],CV_RGB(255,255,255),1, CV_AA, 0 );
-
-
- // Free memory.
- free(PointArray);
- free(hull);
- /* replace CV_FILLED with 1 to see the outlines */
- //cvDrawContours( x->cnt_img, contours, CV_RGB(255,0,0), CV_RGB(0,255,0), x->levels, 3, CV_AA, cvPoint(0,0) );
- //cvConvexityDefects( contours, cvConvexHull2( contours, 0, CV_CLOCKWISE, 0 ), stor022 );
- }
- k++;
- }
-
- cvReleaseMemStorage( &stor03 );
- cvReleaseMemStorage( &stor02 );
- //if (defects) cvClearSeq(defects);
- //if (seqhull) cvClearSeq(seqhull);
-
- cvCvtColor(rgb, gray, CV_RGB2GRAY);
-
- //copy back the processed frame to image
- memcpy( image.data, gray->imageData, image.xsize*image.ysize );
-}
-
-/////////////////////////////////////////////////////////
-// floatThreshMess
-//
-/////////////////////////////////////////////////////////
-void pix_opencv_contours_convexity :: floatMinAreaMess (float minarea)
-{
- if (minarea>0) this->minarea = (int)minarea;
-}
-void pix_opencv_contours_convexity :: floatMaxAreaMess (float maxarea)
-{
- if (maxarea>0) this->maxarea = (int)maxarea;
-}
-
-/////////////////////////////////////////////////////////
-// static member function
-//
-/////////////////////////////////////////////////////////
-void pix_opencv_contours_convexity :: obj_setupCallback(t_class *classPtr)
-{
- class_addmethod(classPtr, (t_method)&pix_opencv_contours_convexity::floatMinAreaMessCallback,
- gensym("minarea"), A_FLOAT, A_NULL);
- class_addmethod(classPtr, (t_method)&pix_opencv_contours_convexity::floatMaxAreaMessCallback,
- gensym("maxarea"), A_FLOAT, A_NULL);
-}
-void pix_opencv_contours_convexity :: floatMaxAreaMessCallback(void *data, t_floatarg maxarea)
-{
- GetMyClass(data)->floatMaxAreaMess((float)maxarea);
-}
-void pix_opencv_contours_convexity :: floatMinAreaMessCallback(void *data, t_floatarg minarea)
-{
- GetMyClass(data)->floatMinAreaMess((float)minarea);
-}
Added: trunk/externals/pix_opencv/pix_opencv_distrans.cc
===================================================================
--- trunk/externals/pix_opencv/pix_opencv_distrans.cc (rev 0)
+++ trunk/externals/pix_opencv/pix_opencv_distrans.cc 2008-05-25 23:07:29 UTC (rev 9916)
@@ -0,0 +1,428 @@
+////////////////////////////////////////////////////////
+//
+// GEM - Graphics Environment for Multimedia
+//
+// zmoelnig at iem.kug.ac.at
+//
+// Implementation file
+//
+// Copyright (c) 1997-2000 Mark Danks.
+// Copyright (c) G\xFCnther Geiger.
+// Copyright (c) 2001-2002 IOhannes m zmoelnig. forum::f\xFCr::uml\xE4ute. IEM
+// Copyright (c) 2002 James Tittle & Chris Clepper
+// For information on usage and redistribution, and for a DISCLAIMER OF ALL
+// WARRANTIES, see the file, "GEM.LICENSE.TERMS" in this distribution.
+//
+/////////////////////////////////////////////////////////
+
+#include "pix_opencv_distrans.h"
+
+CPPEXTERN_NEW(pix_opencv_distrans)
+
+/////////////////////////////////////////////////////////
+//
+// pix_opencv_distrans
+//
+/////////////////////////////////////////////////////////
+// Constructor
+//
+/////////////////////////////////////////////////////////
+pix_opencv_distrans :: pix_opencv_distrans()
+{
+ int i;
+
+ inlet_new(this->x_obj, &this->x_obj->ob_pd, gensym("float"), gensym("ft1"));
+
+ edge_thresh = 25;
+ build_voronoi = 0;
+ comp_xsize = 0;
+ comp_ysize = 0;
+
+ dist = NULL;
+ dist8u1 = NULL;
+ dist8u2 = NULL;
+ dist8u = NULL;
+ dist32s = NULL;
+ src = NULL;
+ gray = NULL;
+ edge = NULL;
+ labels = NULL;
+ rgba = NULL;
+ alpha = NULL;
+
+ mask_size = CV_DIST_MASK_PRECISE;
+
+}
+
+/////////////////////////////////////////////////////////
+// Destructor
+//
+/////////////////////////////////////////////////////////
+pix_opencv_distrans :: ~pix_opencv_distrans()
+{
+ //Destroy cv_images to clean memory
+ cvReleaseImage( &src );
+ cvReleaseImage( &gray );
+ cvReleaseImage( &edge );
+ cvReleaseImage( &dist );
+ cvReleaseImage( &dist8u );
+ cvReleaseImage( &dist8u1 );
+ cvReleaseImage( &dist8u2 );
+ cvReleaseImage( &dist32s );
+ cvReleaseImage( &labels );
+ cvReleaseImage( &rgba );
+ cvReleaseImage( &alpha );
+}
+
+/////////////////////////////////////////////////////////
+// processImage
+//
+/////////////////////////////////////////////////////////
+void pix_opencv_distrans :: processRGBAImage(imageStruct &image)
+{
+ unsigned char *pixels = image.data;
+ int i;
+ static const uchar colors[][3] =
+ {
+ {0,0,0},
+ {255,0,0},
+ {255,128,0},
+ {255,255,0},
+ {0,255,0},
+ {0,128,255},
+ {0,255,255},
+ {0,0,255},
+ {255,0,255}
+ };
+ int msize = mask_size;
+
+ if ((this->comp_xsize!=image.xsize)&&(this->comp_ysize!=image.ysize)) {
+
+ this->comp_xsize = image.xsize;
+ this->comp_ysize = image.ysize;
+
+ //Destroy cv_images to clean memory
+ cvReleaseImage( &src );
+ cvReleaseImage( &gray );
+ cvReleaseImage( &edge );
+ cvReleaseImage( &dist );
+ cvReleaseImage( &dist8u );
+ cvReleaseImage( &dist8u1 );
+ cvReleaseImage( &dist8u2 );
+ cvReleaseImage( &dist32s );
+ cvReleaseImage( &labels );
+ cvReleaseImage( &rgba );
+ cvReleaseImage( &alpha );
+
+ //Create cv_images
+ src = cvCreateImage(cvSize(image.xsize,image.ysize), IPL_DEPTH_8U, 3);
+ gray = cvCreateImage(cvSize(src->width,src->height), IPL_DEPTH_8U, 1);
+ dist = cvCreateImage( cvGetSize(gray), IPL_DEPTH_32F, 1 );
+ dist8u1 = cvCloneImage( gray );
+ dist8u2 = cvCloneImage( gray );
+ dist8u = cvCreateImage( cvGetSize(gray), IPL_DEPTH_8U, 3 );
+ dist32s = cvCreateImage( cvGetSize(gray), IPL_DEPTH_32S, 1 );
+ edge = cvCloneImage( gray );
+ labels = cvCreateImage( cvGetSize(gray), IPL_DEPTH_32S, 1 );
+ rgba = cvCreateImage( cvSize(image.xsize, image.ysize), 8, 4 );
+ alpha = cvCreateImage( cvSize(image.xsize, image.ysize), 8, 1 );
+ }
+ // FEM UNA COPIA DEL PACKET A image->imageData ... http://www.cs.iit.edu/~agam/cs512/lect-notes/opencv-intro/opencv-intro.html aqui veiem la estructura de IplImage
+ memcpy( rgba->imageData, image.data, image.xsize*image.ysize*4 );
+
+ CvArr* in[] = { rgba };
+ CvArr* out[] = { src, alpha };
+ int from_to[] = { 0, 0, 1, 1, 2, 2, 3, 3 };
+ //cvSet( rgba, cvScalar(1,2,3,4) );
+ cvMixChannels( (const CvArr**)in, 1, out, 2, from_to, 4 );
+
+ cvCvtColor(src, gray, CV_BGR2GRAY);
+
+ cvThreshold( gray, edge, (float)edge_thresh, (float)edge_thresh, CV_THRESH_BINARY );
+
+ if( build_voronoi )
+ msize = CV_DIST_MASK_5;
+
+ cvDistTransform( edge, dist, CV_DIST_L2, msize, NULL, build_voronoi ? labels : NULL );
+
+ if( !build_voronoi )
+ {
+ // begin "painting" the distance transform result
+ cvConvertScale( dist, dist, 5000.0, 0 );
+ cvPow( dist, dist, 0.5 );
+
+ cvConvertScale( dist, dist32s, 1.0, 0.5 );
+ cvAndS( dist32s, cvScalarAll(255), dist32s, 0 );
+ cvConvertScale( dist32s, dist8u1, 1, 0 );
+ cvConvertScale( dist32s, dist32s, -1, 0 );
+ cvAddS( dist32s, cvScalarAll(255), dist32s, 0 );
+ cvConvertScale( dist32s, dist8u2, 1, 0 );
+ cvMerge( dist8u1, dist8u2, dist8u2, 0, dist8u );
+ // end "painting" the distance transform result
+ }
+ else
+ {
+ int i, j;
+ for( i = 0; i < labels->height; i++ )
+ {
+ int* ll = (int*)(labels->imageData + i*labels->widthStep);
+ float* dd = (float*)(dist->imageData + i*dist->widthStep);
+ uchar* d = (uchar*)(dist8u->imageData + i*dist8u->widthStep);
+ for( j = 0; j < labels->width; j++ )
+ {
+ int idx = ll[j] == 0 || dd[j] == 0 ? 0 : (ll[j]-1)%8 + 1;
+ int b = cvRound(colors[idx][0]);
+ int g = cvRound(colors[idx][1]);
+ int r = cvRound(colors[idx][2]);
+ d[j*3] = (uchar)b;
+ d[j*3+1] = (uchar)g;
+ d[j*3+2] = (uchar)r;
+ }
+ }
+ }
+
+
+ CvArr* src[] = { dist8u, alpha };
+ CvArr* dst[] = { rgba };
+ cvMixChannels( (const CvArr**)src, 2, (CvArr**)dst, 1, from_to, 4 );
+ //cvShowImage(wndname, cedge);
+ memcpy( image.data, rgba->imageData, image.xsize*image.ysize*4 );
+}
+
+void pix_opencv_distrans :: processRGBImage(imageStruct &image)
+{
+ unsigned char *pixels = image.data;
+ int i;
+ static const uchar colors[][3] =
+ {
+ {0,0,0},
+ {255,0,0},
+ {255,128,0},
+ {255,255,0},
+ {0,255,0},
+ {0,128,255},
+ {0,255,255},
+ {0,0,255},
+ {255,0,255}
+ };
+ int msize = mask_size;
+
+ if ((this->comp_xsize!=image.xsize)&&(this->comp_ysize!=image.ysize)) {
+
+ this->comp_xsize = image.xsize;
+ this->comp_ysize = image.ysize;
+
+ //Destroy cv_images to clean memory
+ cvReleaseImage( &src );
+ cvReleaseImage( &gray );
+ cvReleaseImage( &edge );
+ cvReleaseImage( &dist );
+ cvReleaseImage( &dist8u );
+ cvReleaseImage( &dist8u1 );
+ cvReleaseImage( &dist8u2 );
+ cvReleaseImage( &dist32s );
+ cvReleaseImage( &labels );
+ cvReleaseImage( &rgba );
+ cvReleaseImage( &alpha );
+
+ //Create cv_images
+ src = cvCreateImage(cvSize(image.xsize,image.ysize), IPL_DEPTH_8U, 3);
+ gray = cvCreateImage(cvSize(src->width,src->height), IPL_DEPTH_8U, 1);
+ dist = cvCreateImage( cvGetSize(gray), IPL_DEPTH_32F, 1 );
+ dist8u1 = cvCloneImage( gray );
+ dist8u2 = cvCloneImage( gray );
+ dist8u = cvCreateImage( cvGetSize(gray), IPL_DEPTH_8U, 3 );
+ dist32s = cvCreateImage( cvGetSize(gray), IPL_DEPTH_32S, 1 );
+ edge = cvCloneImage( gray );
+ labels = cvCreateImage( cvGetSize(gray), IPL_DEPTH_32S, 1 );
+ rgba = cvCreateImage( cvSize(image.xsize, image.ysize), 8, 4 );
+ alpha = cvCreateImage( cvSize(image.xsize, image.ysize), 8, 1 );
+ }
+ // FEM UNA COPIA DEL PACKET A image->imageData ... http://www.cs.iit.edu/~agam/cs512/lect-notes/opencv-intro/opencv-intro.html aqui veiem la estructura de IplImage
+ memcpy( src->imageData, image.data, image.xsize*image.ysize*3 );
+
+ cvCvtColor(src, gray, CV_BGR2GRAY);
+
+ cvThreshold( gray, edge, (float)edge_thresh, (float)edge_thresh, CV_THRESH_BINARY );
+
+ if( build_voronoi )
+ msize = CV_DIST_MASK_5;
+
+ cvDistTransform( edge, dist, CV_DIST_L2, msize, NULL, build_voronoi ? labels : NULL );
+
+ if( !build_voronoi )
+ {
+ // begin "painting" the distance transform result
+ cvConvertScale( dist, dist, 5000.0, 0 );
+ cvPow( dist, dist, 0.5 );
+
+ cvConvertScale( dist, dist32s, 1.0, 0.5 );
+ cvAndS( dist32s, cvScalarAll(255), dist32s, 0 );
+ cvConvertScale( dist32s, dist8u1, 1, 0 );
+ cvConvertScale( dist32s, dist32s, -1, 0 );
+ cvAddS( dist32s, cvScalarAll(255), dist32s, 0 );
+ cvConvertScale( dist32s, dist8u2, 1, 0 );
+ cvMerge( dist8u1, dist8u2, dist8u2, 0, dist8u );
+ // end "painting" the distance transform result
+ }
+ else
+ {
+ int i, j;
+ for( i = 0; i < labels->height; i++ )
+ {
+ int* ll = (int*)(labels->imageData + i*labels->widthStep);
+ float* dd = (float*)(dist->imageData + i*dist->widthStep);
+ uchar* d = (uchar*)(dist8u->imageData + i*dist8u->widthStep);
+ for( j = 0; j < labels->width; j++ )
+ {
+ int idx = ll[j] == 0 || dd[j] == 0 ? 0 : (ll[j]-1)%8 + 1;
+ int b = cvRound(colors[idx][0]);
+ int g = cvRound(colors[idx][1]);
+ int r = cvRound(colors[idx][2]);
+ d[j*3] = (uchar)b;
+ d[j*3+1] = (uchar)g;
+ d[j*3+2] = (uchar)r;
+ }
+ }
+ }
+
+ //cvShowImage(wndname, cedge);
+ memcpy( image.data, dist8u->imageData, image.xsize*image.ysize*3 );
+}
+
+void pix_opencv_distrans :: processYUVImage(imageStruct &image)
+{
+}
+
+void pix_opencv_distrans :: processGrayImage(imageStruct &image)
+{
+ unsigned char *pixels = image.data;
+ int i;
+ static const uchar colors[][3] =
+ {
+ {0,0,0},
+ {255,0,0},
+ {255,128,0},
+ {255,255,0},
+ {0,255,0},
+ {0,128,255},
+ {0,255,255},
+ {0,0,255},
+ {255,0,255}
+ };
+ int msize = mask_size;
+
+ if ((this->comp_xsize!=image.xsize)&&(this->comp_ysize!=image.ysize)) {
+
+ this->comp_xsize = image.xsize;
+ this->comp_ysize = image.ysize;
+
+ //Destroy cv_images to clean memory
+ cvReleaseImage( &src );
+ cvReleaseImage( &gray );
+ cvReleaseImage( &edge );
+ cvReleaseImage( &dist );
+ cvReleaseImage( &dist8u );
+ cvReleaseImage( &dist8u1 );
+ cvReleaseImage( &dist8u2 );
+ cvReleaseImage( &dist32s );
+ cvReleaseImage( &labels );
+ cvReleaseImage( &rgba );
+ cvReleaseImage( &alpha );
+
+ //Create cv_images
+ src = cvCreateImage(cvSize(image.xsize,image.ysize), IPL_DEPTH_8U, 3);
+ gray = cvCreateImage(cvSize(src->width,src->height), IPL_DEPTH_8U, 1);
+ dist = cvCreateImage( cvGetSize(gray), IPL_DEPTH_32F, 1 );
+ dist8u1 = cvCloneImage( gray );
+ dist8u2 = cvCloneImage( gray );
+ dist8u = cvCreateImage( cvGetSize(gray), IPL_DEPTH_8U, 3 );
+ dist32s = cvCreateImage( cvGetSize(gray), IPL_DEPTH_32S, 1 );
+ edge = cvCloneImage( gray );
+ labels = cvCreateImage( cvGetSize(gray), IPL_DEPTH_32S, 1 );
+ rgba = cvCreateImage( cvSize(image.xsize, image.ysize), 8, 4 );
+ alpha = cvCreateImage( cvSize(image.xsize, image.ysize), 8, 1 );
+ }
@@ Diff output truncated at 100000 characters. @@
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Pd-cvs
mailing list