• [学习OpenCV攻略][005][视频播放控制]


    cvSetCaptureProperty(视频,属性,属性值)

    设置视频的属性,属性可以是宏CV_CAP_PROP_POS_FRAMES 视频帧的位置

    cvGetCaptureProperty(视频,属性)

    得到视频的属性值,属性可以是宏CV_CAP_PROP_FRAMES_COUNT视频帧数,CV_CAP_PROP_FRAME_WIDTH视频的宽度,CV_CAP_PROP_FRAME_HEIGHT

    cvCreateTrackbar(滚动条名称,窗口名称,滑动条位置,总帧数,回调函数)

    在窗口中创建滚动条,并设置位置和总帧数,当滚动条被拖动时,触发回调函数

    cvSetTrackbarPos(滚动条名称,窗口名称,位置)

    设置窗口中滚动条的位置

    #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
    	);
    }
    
    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("hello", 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
    ", frames, tmpw, tmph);
    	
    	frames = getAVIFrames(argv[1]);
    	
    	printf("hacked frames %d w %d h %d
    ", frames, tmpw, tmph);
    	
    	cvCreateTrackbar(
    		"position",
    		"hello",
    		&g_slider_position,
    		frames,
    		onTrackbarSlide
    	);
    	
    	IplImage *frame;
    	frames = 0;
    	while(1){
    		frame = cvQueryFrame(g_capture);
    		if(!frame){
    			break;
    		}
    		
    		frames++;
    		printf("
    Frame number=%d", frames);
    		cvSetTrackbarPos("position", "hello", frames);
    		
    		cvShowImage("hello", frame);
    		
    		char c = (char)cvWaitKey(10);
    		if(c == 27){
    			break;
    		}
    	}
    	
    	cvReleaseCapture(&g_capture);
    	cvDestroyWindow("hello");
    	
    	return 0;
    }
    
  • 相关阅读:
    日期时间格式
    input表单加disable的后无法获取其value值
    登录判断,清除中间变量
    弹出层嵌套
    转换qq音乐格式为mp3
    layui双击表格,跳转修改页面
    设置输入电话号码为11位
    layui表格设置,分数合计
    解决数据库传回时间类型为数字
    自定义标签
  • 原文地址:https://www.cnblogs.com/d442130165/p/4918494.html
Copyright © 2020-2023  润新知