(代码4)简单视频控制
来源:互联网 发布:mac上的解压缩软件 编辑:程序博客网 时间:2024/05/21 21:37
#include <stdio.h>
#include <iostream>
#include <fstream>
#include "cv.h"
#include "highgui.h"
using namespace std;
int g_slider_position = 0;
CvCapture* g_capture = NULL;
void onTrackbarSlide(int pos) {
cvSetCaptureProperty(
g_capture,
CV_CAP_PROP_POS_FRAMES,
pos
);
}
//Hack because sometimes the number of frames in a video is not accessible.
//Probably delete this on Widows
int getAVIFrames(char * fname) {
char tempSize[4];
// Trying to open the video file
ifstream videoFile( fname , ios::in | ios::binary );
// Checking the availablity of the file
if ( !videoFile ) {
cout << "Couldn’t open the input file " << fname << endl;
exit( 1 );
}
// get the number of frames
videoFile.seekg( 0x30 , ios::beg );
videoFile.read( tempSize , 4 );
int frames = (unsigned char ) tempSize[0] + 0x100*(unsigned char ) tempSize[1] + 0x10000*(unsigned char ) tempSize[2] + 0x1000000*(unsigned char ) tempSize[3];
videoFile.close( );
return frames;
}
int main( int argc, char** argv ) {
cvNamedWindow( "Example2_3", CV_WINDOW_AUTOSIZE );
g_capture = cvCreateFileCapture( argv[1] );
IplImage *foo = cvQueryFrame( g_capture);
int frames = (int) cvGetCaptureProperty(
g_capture,
CV_CAP_PROP_FRAME_COUNT
);
int tmpw = (int) cvGetCaptureProperty(
g_capture,
CV_CAP_PROP_FRAME_WIDTH
);
int tmph = (int) cvGetCaptureProperty(
g_capture,
CV_CAP_PROP_FRAME_HEIGHT
);
printf("opencv frames %d w %d h %d\n",frames,tmpw,tmph);
frames = getAVIFrames(argv[1]); //This is a hack because on linux, getting number of frames often doesn't work
printf("hacked frames %d w %d h %d\n",frames,tmpw,tmph);
cvCreateTrackbar(
"Position",
"Example2_3",
&g_slider_position,
frames,
onTrackbarSlide
);
IplImage* frame;
frames = 0;
while(1) {
frame = cvQueryFrame( g_capture );
if( !frame ) break;
// int frames = cvGetCaptureProperty( g_capture, CV_CAP_PROP_POS_FRAMES);//This should work, sometimes it does not on linux
frames++; //My cheat
printf("\nFrame number=%d\n",frames);
cvSetTrackbarPos("Position","Example2_3",frames);
cvShowImage( "Example2_3", frame );
char c = (char)cvWaitKey(10);
if( c == 27 ) break;
}
cvReleaseCapture( &g_capture );
cvDestroyWindow( "Example2_3" );
return(0);
#include <iostream>
#include <fstream>
#include "cv.h"
#include "highgui.h"
using namespace std;
int g_slider_position = 0;
CvCapture* g_capture = NULL;
void onTrackbarSlide(int pos) {
cvSetCaptureProperty(
g_capture,
CV_CAP_PROP_POS_FRAMES,
pos
);
}
//Hack because sometimes the number of frames in a video is not accessible.
//Probably delete this on Widows
int getAVIFrames(char * fname) {
char tempSize[4];
// Trying to open the video file
ifstream videoFile( fname , ios::in | ios::binary );
// Checking the availablity of the file
if ( !videoFile ) {
cout << "Couldn’t open the input file " << fname << endl;
exit( 1 );
}
// get the number of frames
videoFile.seekg( 0x30 , ios::beg );
videoFile.read( tempSize , 4 );
int frames = (unsigned char ) tempSize[0] + 0x100*(unsigned char ) tempSize[1] + 0x10000*(unsigned char ) tempSize[2] + 0x1000000*(unsigned char ) tempSize[3];
videoFile.close( );
return frames;
}
int main( int argc, char** argv ) {
cvNamedWindow( "Example2_3", CV_WINDOW_AUTOSIZE );
g_capture = cvCreateFileCapture( argv[1] );
IplImage *foo = cvQueryFrame( g_capture);
int frames = (int) cvGetCaptureProperty(
g_capture,
CV_CAP_PROP_FRAME_COUNT
);
int tmpw = (int) cvGetCaptureProperty(
g_capture,
CV_CAP_PROP_FRAME_WIDTH
);
int tmph = (int) cvGetCaptureProperty(
g_capture,
CV_CAP_PROP_FRAME_HEIGHT
);
printf("opencv frames %d w %d h %d\n",frames,tmpw,tmph);
frames = getAVIFrames(argv[1]); //This is a hack because on linux, getting number of frames often doesn't work
printf("hacked frames %d w %d h %d\n",frames,tmpw,tmph);
cvCreateTrackbar(
"Position",
"Example2_3",
&g_slider_position,
frames,
onTrackbarSlide
);
IplImage* frame;
frames = 0;
while(1) {
frame = cvQueryFrame( g_capture );
if( !frame ) break;
// int frames = cvGetCaptureProperty( g_capture, CV_CAP_PROP_POS_FRAMES);//This should work, sometimes it does not on linux
frames++; //My cheat
printf("\nFrame number=%d\n",frames);
cvSetTrackbarPos("Position","Example2_3",frames);
cvShowImage( "Example2_3", frame );
char c = (char)cvWaitKey(10);
if( c == 27 ) break;
}
cvReleaseCapture( &g_capture );
cvDestroyWindow( "Example2_3" );
return(0);
}
cvSetCaptureProperty
设置视频获取属性
int cvSetCaptureProperty( CvCapture* capture, int property_id, double value );
- capture
- 视频获取结构。
- property_id
- 属性标识符。可以是下面之一:
- CV_CAP_PROP_POS_MSEC - 从文件开始的位置,单位为毫秒
- CV_CAP_PROP_POS_FRAMES - 单位为帧数的位置(只对视频文件有效)
- CV_CAP_PROP_POS_AVI_RATIO - 视频文件的相对位置(0 - 影片的开始,1 - 影片的结尾)
- CV_CAP_PROP_FRAME_WIDTH - 视频流的帧宽度(只对摄像头有效)
- CV_CAP_PROP_FRAME_HEIGHT - 视频流的帧高度(只对摄像头有效)
- CV_CAP_PROP_FPS - 帧率(只对摄像头有效)
- CV_CAP_PROP_FOURCC - 表示codec的四个字符(只对摄像头有效)
- value
- 属性的值。
函数cvSetCaptureProperty设置指定视频获取的属性。目前这个函数对视频文件只支持: CV_CAP_PROP_POS_MSEC, CV_CAP_PROP_POS_FRAMES, CV_CAP_PROP_POS_AVI_RATIO
- (代码4)简单视频控制
- 3_opencv简单视频播放控制
- opencv入门(简单的视频播放控制)
- Android 视频播放控制View核心代码
- 简单的SWF视频播放器代码
- AutoLayout(自动布局代码控制)简单总结
- unity3d笔记(4)——声音,视频播放控制
- 视频控制
- Android 视频播放状态链控制简单实现
- AS3.0用代码控制播放一段视频
- 用opencv简单显示图像和视频(代码有注释)
- 第65篇一对多之加载控制语音视频代码(一)及PHP array_slice() 函数
- 第66篇一对多之加载控制语音视频代码(二)及array_splice及array_sum
- 基于android手机的3G+GPS远程控制模型车工程-android手机编程5-伪视频控制车载手机端程序(代码篇)
- 基于android手机的3G+GPS远程控制模型车工程-android手机编程7-伪视频控制远程手机端程序(代码篇)
- OpenCV(五): Opencv视频播放控制
- 游戏手柄(JoyStick)编程控制的一个简单代码(Qt)
- 视频二值化处理基本方法以及简单代码实现
- Struts2的OGNL标签详解
- i OS UT coverage
- struct关键字---C语言深度剖析读书笔记9
- POJ 1236 Network of Schools
- Kinect SDK1.7 迎来重大更新
- (代码4)简单视频控制
- C#对EXCEL文件操作
- winRT 图片验证码生成
- Apache Common fileUpload API 详解
- js---js的concat函数、join 、slice函数及二维数组的定义方式
- Android关于OnTouch 和OnClick同时调用冲突的解决方案
- UML类图
- 一个简单的哈希表的实现
- ajax 在debug和alert时都正确但是直接运行却报错