moving object using slider openCV c++ -


i'm new opencv (c++), lecturer ask me make simple slider every position in slider have different place in window. code below can move object in window based on slider position when moved slider old position still there. looks duplicate not move. can me on problem?? there way solve problem or must change code completely??

#include "stdafx.h" #include "cv.h"  #include "ml.h"  #include "cxcore.h"  #include "highgui.h"    int g_switch_value = 0;  int colorint = 0;   void switch_callback( int position ){      if( position == 0 ){          colorint = 0;      }else{          colorint = 1;      }  }   int _tmain(int argc, _tchar* argv[])  {  const char* name = "change color of circle in picture";  int radius = 30;  int thickness = 12;  int connectivity = 8;  cvscalar red = cv_rgb(0,0,255);   iplimage* src1 = cvloadimage( "e:/2.jpg" );   cvpoint pt1 = cvpoint(405,195);  cvpoint pt2 = cvpoint(620,400);  cvnamedwindow( name, 1 );  cvshowimage(name, src1);   cvcreatetrackbar( "change", name, &g_switch_value, 1, switch_callback );   while( 1 ) {      if( colorint == 0) {          cvcircle(src1,pt1,radius,red,thickness,connectivity);}     else {          cvcircle(src1,pt2,radius,red,thickness,connectivity); }         colorint == 1;         cvshowimage(name, src1);      if( cvwaitkey( 15 ) == 27 )  break;  }  cvreleaseimage( &src1 );  cvdestroywindow( name );   return 0; }  

drawing overwrite image, should keep fresh copy each different painting. easier way:

iplimage* src1 = cvloadimage( "..." ); iplimage* src2 = cvloadimage( "..." ); ...  while( 1 ) {     if( colorint == 0) {         cvshowimage(name, src1);         cvcircle(src1,pt1,radius,red,thickness,connectivity);     }     else {         cvshowimage(name, src2);         cvcircle(src2,pt2,radius,red,thickness,connectivity);     }     if( cvwaitkey( 15 ) == 27 )  break; } cvreleaseimage( &src1 ); cvreleaseimage( &src2 ); 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -