こんにちは、私はまだopenCVの初心者です...aviビデオを読み込んで、特定のフレーム数の後にフレームを表示して、ユーザーが関心領域(ROI)の周りにボックスを描画できるようにして、ユーザーがビデオの名前を付けられるようにしようとしていますこの数のフレームをスキップした後にフレームをスキップするために使用された数は、次のフレームを表示し、ユーザーがボックスを描画してピクセルコーナー座標を保存できるようにします
問題は...コードのどこに問題があるのか わかりません...ボックスを描画できません(ボックスが表示されません)
どんな助けでも感謝します
これは私のコードです...私はopenCV 2.4.0を使用しています
CvRect ボックス; bool drawing_box = false;
void draw_box( IplImage* img, CvRect rect ) { cvRectangle( img, cvPoint(box.x, box.y), cvPoint(box.x+box.width,box.y+box.height), cvScalar(255, 255,255) ),1 ); }
void my_mouse_callback( int event, int x, int y, int flags, void* param ) { IplImage* image = (IplImage*) param;
switch( event )
{
case CV_EVENT_MOUSEMOVE:
if( drawing_box )
{
box.width = x-box.x;
box.height = y-box.y;
}
break;
case CV_EVENT_LBUTTONDOWN:
drawing_box = true;
box = cvRect( x, y, 0, 0 );
break;
case CV_EVENT_LBUTTONUP:
drawing_box = false;
if( box.width < 0 )
{
box.x += box.width;
box.width *= -1;
}
if( box.height < 0 )
{
box.y += box.height;
box.height *= -1;
}
draw_box( image, box );
break;
}
}
int main (int argc, char * const argv[]) {
int n;
char name [50];
box = cvRect(-1,-1,0,0);
if (argc==1)
{
printf("\nEnter the name of the video:");
scanf("%s",name);
printf("\nEnter number of frames:");
scanf("%d",&n);
} else if (argc == 3)
{
strcpy(name, argv[1]);
n = atoi (argv[2]);
}
else
{
printf("To run this program you should enter the name of the program at least, or you can enter the name of the program then the file name then the number of frames ");
return 0;
}
// GET video
CvCapture* capture = cvCreateFileCapture( name );
if (!capture )
{
printf( "Unable to read input video." );
return 0;
}
int nframes = cvGetCaptureProperty( capture,CV_CAP_PROP_FRAME_COUNT);
//mouse data
int ** points= new int*[nframes]; //x1, y1 , x2 , y2
for (int i=0 ; i< nframes; i++)
points[i]=new int [4];
// Read frame
IplImage* frame = cvQueryFrame( capture );
int c = 1;
int sum = 1;
char k ;
cvNamedWindow("Draw box around the ROI ", CV_WINDOW_AUTOSIZE);
while(c <= nframes)
{
if(c == sum)
{
cvSetMouseCallback( "Draw box around the ROI ", my_mouse_callback, (void*) frame);
cvShowImage("Draw box around the ROI ", frame);
if( drawing_box )
{
draw_box( frame, box );
cvShowImage("Draw box around the ROI ", frame);
cvWaitKey( 15 );
}
points[c-1][0]= box.x ;//x1
points[c-1][1]= box.y ;//y1
points[c-1][2]= box.x+box.width ;//x2
points[c-1][3]= box.y+box.height ;//y2
sum += n;
}
frame = cvQueryFrame( capture );
c++;
k = cvWaitKey(33);
if( k == 27 )
break;
}
// CLEAN everything
cvReleaseImage( &frame );
cvReleaseCapture( &capture );
cvDestroyWindow( "Draw box around the ROI" );
return 0;
}