#include <opencv2/highgui/highgui.hpp>
#include <cv.h>
#include <iostream>
using namespace cv;
using namespace std;
int g_slider_position = 0;
int n = 0;
CvCapture *g_cap = nullptr;
void onTrackbarslide(int pos)
{
if (cvGetTrackbarPos("position","example3")!=n)
{
cvSetCaptureProperty(g_cap,CV_CAP_PROP_POS_FRAMES,pos);
n = cvGetTrackbarPos("position","example3");
}
}
void main()
{
cvNamedWindow("example3",CV_WINDOW_AUTOSIZE);
g_cap = cvCreateFileCapture("D:\\1.wmv");
int frames = static_cast<int>(cvGetCaptureProperty(g_cap,CV_CAP_PROP_FRAME_COUNT));
cout<<frames<<endl;
int framerate = static_cast<int>(cvGetCaptureProperty(g_cap,CV_CAP_PROP_FPS));
cout<<endl<<framerate<<endl;
if (frames != 0)
{
cvCreateTrackbar("position","example3",&g_slider_position,frames,onTrackbarslide);
}
IplImage *frame;
while(1)
{
frame = cvQueryFrame(g_cap);
if(!frame)
break;
cvSetTrackbarPos("position","example3",++n);//这儿我不清楚为啥改成n++就会有视频播放问题
cvShowImage("example3",frame);
char c = waitKey(framerate);
if (c == 27)
{
break;
}
}
cvReleaseCapture(&g_cap);
cvDestroyWindow("example3");
system("pause");
}
此贴解决了上两贴中提到的”33“的问题,一个函数
cvGetCaptureProperty(g_cap,CV_CAP_PROP_FPS)
可以解决视频每秒多少帧的问题
opencv提供了很多画图的函数
Point center = Point(250,250); //首先给定圆心的位置就是(250,250) int r = 200; // 给定这个圆的半径,如果想要这个圆能够在范围内,那么圆心+半径<=下面的范围500 Mat image(500,500,CV_8UC3,Scalar(255,255,255)); //image(长,宽,类型,颜色) //该类型的形式是:CV_<bit数>(S|U|F)C<通道数> //例如,数据类型可能是CV32FC1,即32bit的浮点数 //或CV_8UC3,8bit的无符号整数 //或CV_8UC3,无符号8bit整数,3通道
//画矩形 //参数为:承载的图像、顶点、对角点、颜色(这里是蓝色)、粗细、大小 Point b = Point(100,100); rectangle(image,b,center,Scalar(255,0,0)); imshow("rectangle",image);
circle(image,center,r,Scalar(0,0,0));//画圆//(图像,圆心,半径,颜色,粗细,线形)imshow("circle",image);waitKey(0); return 0;
椭圆是同样的道理
ellipse(image1,center,Size(240,100),0,0,360,Scalar(100,100,100)); imshow("Ellipse",image1);
画线比较简单
//参数为:承载的图像、起始点、结束点、颜色、粗细、线型 Point a = Point(500,500); line(image,a,center,Scalar(200,0,0)); imshow("line",image);
画矩形直接rectangle就可以//画矩形 //参数为:承载的图像、顶点、对角点、颜色(这里是蓝色)、粗细、大小 Point b = Point(100,100); rectangle(image,b,center,Scalar(255,0,0)); imshow("rectangle",image);
在图像里插入文字的过程可以利用ROI来解决把文字当成一个图像
当然也可以直接putText//插入文字 //参数为:承载的图片,插入的文字,文字的位置(文本框左下角),字体,大小,颜色 string words= "good luck"; putText( image, words, Point( image.rows/2,image.cols/4),CV_FONT_HERSHEY_COMPLEX, 1, Scalar(255, 0, 0) ); imshow("image",image);