aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntoine Villeret <avilleret@users.sourceforge.net>2013-04-03 20:29:50 +0000
committerAntoine Villeret <avilleret@users.sourceforge.net>2013-04-03 20:29:50 +0000
commit5b22d6b02a953bd107fd800b6ca1afda1bf33558 (patch)
tree99390b9341805268164101126642af760c779465
parente5cfd34d8bcdb7c2971db443e05f37b0b9d44ebc (diff)
add repeat_point, a useless option
svn path=/trunk/externals/pix_opencv/; revision=17069
-rw-r--r--pix_opencv_contours.cc61
-rw-r--r--pix_opencv_contours.h8
2 files changed, 50 insertions, 19 deletions
diff --git a/pix_opencv_contours.cc b/pix_opencv_contours.cc
index 3c5124f..c6eefbb 100644
--- a/pix_opencv_contours.cc
+++ b/pix_opencv_contours.cc
@@ -33,7 +33,8 @@ CPPEXTERN_NEW(pix_opencv_contours)
// Constructor
//
/////////////////////////////////////////////////////////
-pix_opencv_contours :: pix_opencv_contours() : m_area_threshold(30), \
+pix_opencv_contours :: pix_opencv_contours() : m_repeat_point(1), \
+ m_area_threshold(30), \
m_epsilon(2), \
m_enable_contours(1), \
m_enable_hulls(1), \
@@ -177,7 +178,7 @@ void pix_opencv_contours :: processGrayImage(imageStruct &image)
SETFLOAT(info+info_offset+11, rot_rect.size.width/image.xsize);
SETFLOAT(info+info_offset+12, rot_rect.size.height/image.xsize);
SETFLOAT(info+info_offset+13, rot_rect.angle);
- SETFLOAT(info+info_offset+14, m_contours[i].size()); // number of points in segment
+ SETFLOAT(info+info_offset+14, m_contours[i].size()+m_repeat_point*2); // number of points in segment
SETFLOAT(info+info_offset+15, (float) length);
SETFLOAT(info+info_offset+16, 0);
SETFLOAT(info+info_offset+17, 0);
@@ -196,20 +197,36 @@ void pix_opencv_contours :: processGrayImage(imageStruct &image)
if ( !m_taboutput ){
for( size_t i = 0 ; i < m_contours.size() ; i++ )
{
+
if (!m_contours[i].empty() && m_contours[i].size() > 2) {
- int size = 2+m_contours[i].size()*2;
+ int size = 2+(m_repeat_point*2+m_contours[i].size())*2;
t_atom*ap = new t_atom[size];
- SETFLOAT(ap, static_cast<t_float>(m_contours[i].size()));
+ SETFLOAT(ap, static_cast<t_float>(m_repeat_point*2+m_contours[i].size()));
SETFLOAT(ap+1, 2.0);
int offset(2);
- for ( size_t j = 0 ; j < m_contours[i].size() ; j++){
+ for ( size_t j = 0 ; j < m_repeat_point ; j++){
+ cv::Point pt = m_contours[i][0];
+ SETFLOAT(ap+offset, (float) pt.x/image.xsize);
+ SETFLOAT(ap+offset+1,(float) pt.y/image.ysize);
+ offset+=2;
+ }
+
+ for ( size_t j = 1 ; j < m_contours[i].size() ; j++){
cv::Point pt = m_contours[i][j];
SETFLOAT(ap+offset,(float) pt.x/image.xsize);
SETFLOAT(ap+offset+1,(float) pt.y/image.ysize);
offset+=2;
}
+
+ for ( size_t j = 0 ; j < m_repeat_point ; j++){
+ cv::Point pt = m_contours[i][0]; // repeat the first point to close the contour
+ SETFLOAT(ap+offset, (float) pt.x/image.xsize);
+ SETFLOAT(ap+offset+1,(float) pt.y/image.ysize);
+ offset+=2;
+ }
+
outlet_anything(m_dataout_middle, gensym("contour"), size, ap);
if(ap)delete[]ap;ap=NULL;
@@ -223,7 +240,7 @@ void pix_opencv_contours :: processGrayImage(imageStruct &image)
} else {
//~ put contours in 3 tables.
- //~ contours are separated by a -1 value
+ //~ contours are separated by 0 values
if ( m_x_arrayname == NULL || m_y_arrayname == NULL || m_z_arrayname == NULL){
error("please settab before trying to write into...");
@@ -250,8 +267,9 @@ void pix_opencv_contours :: processGrayImage(imageStruct &image)
//~ check array and resize if needed
for( size_t i = 0 ; i < m_contours.size(); i++ ){
- size+=m_contours[i].size()+3;
+ size+=m_contours[i].size();
}
+ size+=m_contours.size()*m_repeat_point*2; // on ajoute 2 fois m_repeat_point points (au début et à la fin)
if (!garray_getfloatwords(ax, &vecxsize, &vecx)){
error("%s: bad template for tabwrite", m_x_arrayname->s_name);
@@ -300,10 +318,12 @@ void pix_opencv_contours :: processGrayImage(imageStruct &image)
cv::Point pt;
pt = m_contours[i][0];
//~ start with blank point
- vecx[n].w_float = (float) pt.x/image.xsize;
- vecy[n].w_float = (float) pt.y/image.ysize;
- vecz[n].w_float = 0.;
- n++;
+ for (j=0; j<m_repeat_point; j++){
+ vecx[n].w_float = (float) pt.x/image.xsize;
+ vecy[n].w_float = (float) pt.y/image.ysize;
+ vecz[n].w_float = 0.;
+ n++;
+ }
for ( j = 0 ; j < m_contours[i].size() ; j++) {
@@ -316,12 +336,14 @@ void pix_opencv_contours :: processGrayImage(imageStruct &image)
}
// close contour
pt = m_contours[i][0];
- vecx[n].w_float = (float) pt.x/image.xsize;
- vecy[n].w_float = (float) pt.y/image.ysize;
- vecz[n].w_float = 1.;
- n++;
+ for (j=0; j<m_repeat_point; j++){
+ vecx[n].w_float = (float) pt.x/image.xsize;
+ vecy[n].w_float = (float) pt.y/image.ysize;
+ vecz[n].w_float = 0.;
+ n++;
+ }
// add a blank point to draw invisible segment
- vecz[n++].w_float = 0.;
+ //~ vecz[n++].w_float = 0.;
}
@@ -450,6 +472,7 @@ void pix_opencv_contours :: obj_setupCallback(t_class *classPtr)
CPPEXTERN_MSG1(classPtr, "hierarchy_level", hierarchyMess, double);
CPPEXTERN_MSG1(classPtr, "taboutput", taboutputMess, float);
CPPEXTERN_MSG3(classPtr, "settab", tableMess, t_symbol*, t_symbol*, t_symbol*);
+ CPPEXTERN_MSG1(classPtr, "repeat_point", repeat_pointMess, float);
}
/////////////////////////////////////////////////////////
@@ -492,6 +515,12 @@ void pix_opencv_contours :: taboutputMess(float arg)
{
m_taboutput = arg > 0;
}
+
+void pix_opencv_contours :: repeat_pointMess(float arg)
+{
+ m_repeat_point = arg > 1 ? arg : 1;
+}
+
void pix_opencv_contours :: tableMess(t_symbol*xarray, t_symbol*yarray, t_symbol*zarray)
{
// check if arrays exist
diff --git a/pix_opencv_contours.h b/pix_opencv_contours.h
index b546aca..e861642 100644
--- a/pix_opencv_contours.h
+++ b/pix_opencv_contours.h
@@ -2,8 +2,6 @@
LOG
GEM - Graphics Environment for Multimedia
- Threshold filter
-
Copyright (c) 1997-1999 Mark Danks. mark@danks.org
Copyright (c) Günther Geiger. geiger@epy.co.at
Copyright (c) 2001-2002 IOhannes m zmoelnig. forum::für::umläute. IEM. zmoelnig@iem.kug.ac.at
@@ -67,6 +65,7 @@ class GEM_EXTERN pix_opencv_contours : public GemPixObj
void hierarchyMess(double arg);
void taboutputMess(float arg);
void tableMess(t_symbol*x, t_symbol*y, t_symbol*z);
+ void repeat_pointMess(float arg);
private:
@@ -75,9 +74,12 @@ class GEM_EXTERN pix_opencv_contours : public GemPixObj
std::vector<std::vector<cv::Point> > m_contours;
std::vector<std::vector<int> > m_convexhulls;
//~ std::vector<cv::Vec4i> m_hierarchy;
+
+ unsigned int m_repeat_point;
double m_area_threshold; // min area for contour
double m_epsilon;
-
+
+
int m_enable_contours, m_enable_hulls, m_enable_defects, m_hierarchy_level, m_mode, m_taboutput;
t_symbol *m_x_arrayname, *m_y_arrayname, *m_z_arrayname;