aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntoine Villeret <avilleret@users.sourceforge.net>2013-05-18 10:09:50 +0000
committerAntoine Villeret <avilleret@users.sourceforge.net>2013-05-18 10:09:50 +0000
commit29cd98626deb592c816b6b27aff942c8ae038d9d (patch)
treea1f923d589480a8d026385520249458edf6c056f
parentd86511957eb97505955c3371d8952336a74dfb3e (diff)
add getParam and setParam method to control module's parameter
WARNING ! this is quite experimental ! since there is no way to get parameters boundaries and those are not clipped, set to a wrong value could lead to crash svn path=/trunk/externals/pix_opencv/; revision=17135
-rw-r--r--pix_opencv_blobtrack.cc135
1 files changed, 129 insertions, 6 deletions
diff --git a/pix_opencv_blobtrack.cc b/pix_opencv_blobtrack.cc
index 9181528..8fb4752 100644
--- a/pix_opencv_blobtrack.cc
+++ b/pix_opencv_blobtrack.cc
@@ -121,13 +121,14 @@ void pix_opencv_blobtrack :: RunBlobTrackingAuto( IplImage* img )
//~ SETFLOAT(&blob_num, m_tracker->GetBlobNum());
//~ outlet_anything(m_dataout, gensym("blobnum"), 1, &blob_num);
- int blob_atom_size = 2+m_tracker->GetBlobNum()*6;
+ int blob_num=m_tracker->GetBlobNum();
+ int blob_atom_size = 2+blob_num*6;
t_atom* blob_atom = new t_atom[blob_atom_size];
- SETFLOAT(&blob_atom[0], m_tracker->GetBlobNum());
+ SETFLOAT(&blob_atom[0], blob_num);
SETFLOAT(&blob_atom[1], 6);
- for(int i=0; i<m_tracker->GetBlobNum(); i++){
+ for(int i=0; i<blob_num; i++){
CvBlob* blob = m_tracker->GetBlob(i);
SETFLOAT(&blob_atom[2+i*6], blob->ID);
SETFLOAT(&blob_atom[3+i*6], blob->x/img->width);
@@ -454,12 +455,134 @@ void pix_opencv_blobtrack :: printParamsMess(void)
void pix_opencv_blobtrack :: getParamMess(t_symbol*s, int argc, t_atom*argv)
{
- // TODO
-}
+ int i;
+ CvVSModule* pM;
+ pM=NULL;
+ if ( argc < 1 ){
+ error("getParam need a module name as symbol arg");
+ return;
+ }
+
+ if ( argv[0].a_type == A_SYMBOL ) {
+ if (std::string(argv[0].a_w.w_symbol->s_name) == "fg") {
+ pM=m_param.pFG;
+ }
+ else if (std::string(argv[0].a_w.w_symbol->s_name) == "bd") {
+ pM=m_param.pBD;
+ }
+ else if (std::string(argv[0].a_w.w_symbol->s_name) == "bt") {
+ pM=m_param.pBT;
+ }
+ else if (std::string(argv[0].a_w.w_symbol->s_name) == "btpp") {
+ pM=m_param.pBTPP;
+ }
+ else if (std::string(argv[0].a_w.w_symbol->s_name) == "bta") {
+ pM=m_param.pBTA;
+ }
+ else {
+ error("unknown module : %s",argv[0].a_w.w_symbol->s_name);
+ return;
+ }
+ } else {
+ error("getParam need a module name as symbol arg");
+ }
+
+ t_atom a_param[4];
+
+ a_param[0] = argv[0];
+
+ if(pM->GetParamName(0) == NULL ) return;
+
+ for (i=0; ; ++i)
+ {
+ const char* param = pM->GetParamName(i);
+ const char* str = param?pM->GetParamStr(param):NULL;
+
+ if(param == NULL)break;
+ SETSYMBOL(a_param+1,gensym(param));
+ if(str)
+ {
+ SETSYMBOL(a_param+2,gensym(str));
+ }
+ else
+ {
+ SETFLOAT(a_param+2,pM->GetParam(param));
+ }
+ const char* comment = pM->GetParamComment(param);
+ if ( !comment ) comment = "N/A";
+ SETSYMBOL(a_param+3,gensym(comment));
+
+ outlet_anything(m_dataout, gensym("param"), 4, a_param);
+ }
+} /* getParamMess */
void pix_opencv_blobtrack :: setParamMess(t_symbol*s, int argc, t_atom*argv)
{
- // TODO
+ if ( argc != 3 ){
+ error("setParam need 3 args : <module name> <parameter name> <value>");
+ return;
+ }
+
+ int i;
+ CvVSModule* pM;
+ pM=NULL;
+
+ if ( argv[0].a_type == A_SYMBOL ) {
+ if (std::string(argv[0].a_w.w_symbol->s_name) == "fg") {
+ pM=m_param.pFG;
+ }
+ else if (std::string(argv[0].a_w.w_symbol->s_name) == "bd") {
+ pM=m_param.pBD;
+ }
+ else if (std::string(argv[0].a_w.w_symbol->s_name) == "bt") {
+ pM=m_param.pBT;
+ }
+ else if (std::string(argv[0].a_w.w_symbol->s_name) == "btpp") {
+ pM=m_param.pBTPP;
+ }
+ else if (std::string(argv[0].a_w.w_symbol->s_name) == "bta") {
+ pM=m_param.pBTA;
+ }
+ else {
+ error("unknown module : %s",argv[0].a_w.w_symbol->s_name);
+ return;
+ }
+ } else {
+ error("getParam need a module name as symbol arg");
+ }
+
+ const char* param;
+ const char* str;
+ for ( i = 0 ; ; i++ ){
+ param = pM->GetParamName(i);
+ str = param?pM->GetParamStr(param):NULL;
+
+ if(param == NULL){
+ error("module %s doesn't have a %s parameter", argv[0].a_w.w_symbol->s_name, argv[1].a_w.w_symbol->s_name);
+ return;
+ }
+
+ if( std::string(argv[1].a_w.w_symbol->s_name) == param )
+ break;
+ }
+
+ if ( str ){ /* parameter is a string */
+ if ( argv[2].a_type != A_SYMBOL ){
+ error("module (%s) parameter (%s) is a symbol");
+ return;
+ } else {
+ pM->SetParamStr(param, argv[2].a_w.w_symbol->s_name);
+ }
+ } else {
+ if ( argv[2].a_type != A_FLOAT ){
+ error("module (%s) parameter (%s) is a float");
+ return;
+ } else {
+ pM->SetParam(param, argv[2].a_w.w_float);
+ }
+ }
+
+ pM->ParamUpdate();
}
void pix_opencv_blobtrack :: getModuleMess(t_symbol*s, int argc, t_atom*argv)