需要添加的参数以及步骤
滚动条及目标检测
#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