我对 OpenCV (c++) 很陌生,我的讲师让我制作一个简单的滑块,滑块中的每个位置在窗口中都有不同的位置。我下面的代码可以根据滑块位置在窗口中移动对象,但是当我移动滑块时,旧位置仍然存在。所以它看起来像一个重复的不动。谁能帮我解决这个问题??有没有办法解决这个问题或者我必须完全改变代码?
#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 the color of circle in the 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; }