0
我想在視頻暫停時使用鼠標繪製視頻區域,但我遇到了一些問題。當我暫停視頻並嘗試繪製一個區域時,只有在按下鍵盤上的任何按鍵(未實現該按鍵)後纔會出現繪製區域。我想知道當我按下鼠標按鈕時,可以對繪製區域做什麼?使用鼠標在OpenCV上繪製視頻區域
謝謝:)
我的代碼:
//mouse callback
void rotina_mouse(int event, int x, int y, int flags, void* param);
bool continua = false;
//function to paint
void pinta(IplImage* image, int x, int y){
cvFloodFill (image, cvPoint (x,y), cvScalar(103), cvScalarAll(2), cvScalarAll(2), 0, CV_FLOODFILL_FIXED_RANGE , 0);
}
//main program
int _tmain(int argc, _TCHAR* argv[])
{
cvNamedWindow ("saida", CV_WINDOW_AUTOSIZE);
CvCapture* g_capture = cvCreateFileCapture ("vid.avi");
IplImage* frame = cvQueryFrame(g_capture);
IplImage* temp = cvCloneImage(frame);
cvSetMouseCallback("saida",rotina_mouse,(void*) frame);
while(1){
frame = cvQueryFrame(g_capture);
cvNot(frame, frame);
cvCopyImage(frame, temp);
cvShowImage("saida", temp);
if(!frame) break;
//pause with 'p'
char e = cvWaitKey(33);
if(e==112){
while(1){
cvCopyImage(frame, temp);
cvShowImage("saida", temp);
char d = cvWaitKey(0);
if(d==112) break;
}
}
//close video with'esc'
if(e==27) break;
}
cvReleaseCapture (&g_capture);
cvDestroyWindow("saida");
return 0;
}
//mouse callback
void rotina_mouse(int event, int x, int y, int flags, void* param) {
IplImage* image = (IplImage*) param;
switch(event) {
case CV_EVENT_MOUSEMOVE: {
if(continua==true)
pinta(image, x, y);
}
break;
case CV_EVENT_LBUTTONDOWN: {
pinta(image, x, y);
continua=true;
}
break;
case CV_EVENT_LBUTTONUP: {
continua=false;
}
break;
default:
break;
}
}
它的工作原理! = DD非常感謝你! –