MFC C++视频播放和视频的浓缩播放和检测目标接口

需要添加的参数以及步骤

滚动条及目标检测

#include "VIDEO.h" //导入控制视频播放的包
VIDEO video; // 创建对象调用已经定义好的函数

	namedWindow("view11", WINDOW_AUTOSIZE);
	HWND hWnd = (HWND)cvGetWindowHandle("view11");
	HWND hParent = ::GetParent(hWnd);
	::SetParent(hWnd, GetDlgItem(IDC_DOC1)->m_hWnd);
	::ShowWindow(hParent, SW_HIDE);
	
	CRect rect;
	GetDlgItem(IDC_DOC1)->GetClientRect(&rect);

视频浓缩

//调用需要用到的包
#include <opencv2/highgui/highgui.hpp>
#include “VIDEO.h”
using namespace std;
using namespace cv;
VIDEO vid1;

//窗口句柄
namedWindow("view01", WINDOW_AUTOSIZE);
HWND hWnd1 = (HWND)cvGetWindowHandle("view01");
HWND hParent1 = ::GetParent(hWnd1);
::SetParent(hWnd1, GetDlgItem(IDC_LDOC)->m_hWnd);
::ShowWindow(hParent1, SW_HIDE);

CStatic* pStatic = (CStatic*)GetDlgItem(IDC_LDOC);
vid1.SetMember("view01", pStatic);

VIDEO.cpp

#include "stdafx.h"
#include "VIDEO.h"
#include<opencv2/core/core.hpp>
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/imgproc/imgproc.hpp>
#include "resource.h"

#include <opencv2/highgui/highgui.hpp>
using namespace std;
using namespace cv;

VIDEO::VIDEO()

{

}


VIDEO::~VIDEO()
{
}
//播放器部分
double zhen;
double nowzhen = 0;
bool z = FALSE;
bool q = FALSE;
bool q1 = FALSE;
//打开滚动条视频展示
void VIDEO::VideoShow(CScrollBar &gdt, CRect &rect, String name)
{
	try
	{
		q1 = TRUE;
		q = FALSE;
		m_name1 = name;
		m_rect = rect;
		CString piPath;//定义图片路径变量  
		Mat frame;
		CFileDialog dlg(TRUE, NULL, NULL, OFN_HIDEREADONLY |
			OFN_OVERWRITEPROMPT | OFN_ALLOWMULTISELECT, NULL);  //选择文件对话框  
		if (dlg.DoModal() == IDOK)
		{
			piPath = dlg.GetPathName();  //获取图片路径  
		}
		//CString to string  使用这个方法记得字符集选用“使用多字节字符”,不然会报错 
		picpath1 = piPath.GetBuffer(0);
		//ShiPin = imread(picpath);
		Mat dst;
		VideoCapture capture(picpath1);//读入视频
		zhen = capture.get(CV_CAP_PROP_FRAME_COUNT);
		gdt.SetScrollRange(1, zhen);//设置滚动条的初始值范围

		while (1)
		{
			if (nowzhen == zhen | nowzhen >= zhen)//循环播放
			{
				gdt.SetScrollPos(0);//初始化
				nowzhen = 0;
				z = FALSE;//默认暂停
			}
			char string[10];
			double t, fps;

			//设置帧率模块
			t = (double)getTickCount();
			capture.set(CV_CAP_PROP_POS_FRAMES, nowzhen);//滚动条改变后设置新帧率
			capture >> frame;//读取当前帧
			t = ((double)getTickCount() - t) / getTickFrequency();
			fps = 1.0 / t;
			sprintf_s(string, "%.2f", fps);
			String fpsString("FPS:");

			//若视频播放完成,退出循环
			if (z)//判断是否暂停
			{
				nowzhen++; //自增帧
				gdt.SetScrollPos(nowzhen);//滑动条跟踪
				fpsString += string;//帧率运动
			}
			resize(frame, dst, Size(rect.Width(), rect.Height()));
			putText(dst, fpsString, Point(20, 20), FONT_HERSHEY_PLAIN, 1, (255, 0, 0));
			imshow(name, dst);
			waitKey(30);//延时30ms
			if (q)
			{
				break;
			}
		}
	}
	catch (const std::exception&)
	{
		MessageBox(NULL, TEX
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值