您的位置:首页 > 产品设计 > UI/UE

Opencv--High-level GUI使用介绍

2012-11-10 22:01 471 查看
It provides easy interface to:

Create and manipulate windows that can display images and “remember” their content (no need to handle repaint events from OS).
Add trackbars to the windows, handle simple mouse events as well as keyboard commmands.
Read and write images to/from disk or memory.
Read video from camera or file and write video to a file.

User Interface

createTrackbar
getTrackbarPos
imshow
namedWindow
destroyWindow
destroyAllWindows
MoveWindow
ResizeWindow
SetMouseCallback
setTrackbarPos
waitKey

Reading and Writing Images and Video

imdecode
imencode
imread
imwrite
VideoCapture
VideoCapture::VideoCapture
VideoCapture::open
VideoCapture::isOpened
VideoCapture::release
VideoCapture::grab
VideoCapture::retrieve
VideoCapture::read
VideoCapture::get
VideoCapture::set
VideoWriter
VideoWriter::VideoWriter
ReleaseVideoWriter
VideoWriter::open
VideoWriter::isOpened
VideoWriter::write

Qt New Functions

setWindowProperty
getWindowProperty
fontQt
addText
displayOverlay
displayStatusBar
createOpenGLCallback
saveWindowParameters
loadWindowParameters
createButton

下面是一段自己整理的代码,功能:能够打开摄像头并保存成AVI视频格式
int main(int argc, char *argv[], char *window_name)
{
VideoCapture inputVideo(0);        // Open input
if ( !inputVideo.isOpened())
{
cout  << "Could not open the input video."  << endl;
return -1;
}

VideoWriter outputVideo;                                        // Open the output
Size S = Size((int) inputVideo.get(CV_CAP_PROP_FRAME_WIDTH),    //Acquire input size
(int) inputVideo.get(CV_CAP_PROP_FRAME_HEIGHT));
outputVideo.open("video.avi" , CV_FOURCC('X', 'V', 'I', 'D'), 25,S, true);
if (!outputVideo.isOpened())
{
cout  << "Could not open the output video for write: " << endl;
return -1;
}

cout << "Input frame resolution: Width=" << S.width << "  Height=" << S.height<< endl;
namedWindow("Video");
while(true)
{
Mat frame;
inputVideo >>frame;
imshow("Video",frame);
outputVideo << frame;

int key = cvWaitKey(25);         //ESC 退出
if( key == 27 )
{
break;
}
}
inputVideo.release();
outputVideo.release();
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: