单从MFC的角度,这部分比较简单,无非就是添加控件,然后对控件添加对应的响应事件函数!
关于添加控件和添加对应的响应事件函数,可以查看:项目MFC总结(二)——读取CSV文件将数据转化为图像显示在图片控件
比较需要思考一下的是一些事件之间的协调,做到不冲突和影响!这里就先把代码记录一下吧~
代码实现
- 上一帧
//上一帧
void CTouch_test_CKV10Dlg::OnBnClickedButtonbefore()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
zoom = false;
if (current_frame == 1){
INT_PTR nRes;
// 显示消息对话框
nRes = MessageBox(_T("当前为第一帧!"), _T("数据读取"), MB_OKCANCEL | MB_ICONWARNING);
}
else if (current_frame>0){
current_frame = current_frame - 1;
img = get_img(csvData_Slip, 1920, 1080, current_frame-1,Color);
CRect rect;
GetDlgItem(IDC_STATIC_IMG)->GetClientRect(&rect);
Rect dst(rect.left, rect.top, rect.right, rect.bottom);
resize(img, current_img, cv::Size(rect.Width(), rect.Height()));
//若当前帧缩放,后一帧也保持前一帧的尺寸不变
if (pre_zoom){
double new_Zoom = double(resize_mat.rows) / current_img.rows;
resize(current_img, current_img, Size(), new_Zoom, new_Zoom, INTER_NEAREST); //按比例放大图片
}
//分辨率
RX = current_img.cols;
RY = current_img.rows;
if (g_iZoom <= 1)
m_resize = g_iZoom * 4;
else
m_resize = g_iZoom + 3;
imshow("view", current_img);
//g_iZoom = 1;
//将质心清除
pre_CXY.clear();
for (int i = 0; i < pre_CXY_ALL.size(); ++i){
if (pre_CXY_ALL[i].first == current_frame){
circle(canvas, Point(pre_CXY_ALL[i].second.x, pre_CXY_ALL[i].second.y), m_Line_size, Scalar(255, 255, 0), -1); //可视化,在质心画圆
}
}
cv::imshow("Visaul", canvas);
waitKey(1);
}
UpdateData(FALSE);
}
- 下一帧
//下一帧
void CTouch_test_CKV10Dlg::OnBnClickedButtonnext()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
zoom = false;
if (current_frame == Frame_Num){
INT_PTR nRes;
// 显示消息对话框
nRes = MessageBox(_T("当前为最后一帧,是否从第一帧开始?"), _T("数据读取"), MB_OKCANCEL | MB_ICONWARNING);
if (IDCANCEL == nRes)
return;
if (IDOK == nRes){
img = get_img(csvData_Slip, 1920, 1080, 0, Color);
CRect rect;
GetDlgItem(IDC_STATIC_IMG)->GetClientRect(&rect);
Rect dst(rect.left, rect.top, rect.right, rect.bottom);
resize(img, current_img, cv::Size(rect.Width(), rect.Height()));
//若前一帧缩放,后一帧也保持前一张的尺寸不变
if (pre_zoom){
double new_zoom = double(resize_mat.rows) / current_img.rows;
resize(current_img, current_img, Size(), new_zoom, new_zoom, INTER_NEAREST); //按比例放大图片
}
//分辨率
RX = current_img.cols;
RY = current_img.rows;
if (g_iZoom <= 1)
m_resize = g_iZoom * 4;
else
m_resize = g_iZoom + 3;
imshow("view", current_img);
current_frame = 1;
}
}
else if (Frame_Num>0){
current_frame = current_frame + 1;
img = get_img(csvData_Slip, 1920, 1080, current_frame - 1, Color);
CRect rect;
GetDlgItem(IDC_STATIC_IMG)->GetClientRect(&rect);
Rect dst(rect.left, rect.top, rect.right, rect.bottom);
resize(img, current_img, cv::Size(rect.Width(), rect.Height()));
//若前一帧缩放,后一帧也保持前一张的尺寸不变
if (pre_zoom){
double new_zoom = double(resize_mat.rows) / current_img.rows;
resize(current_img, current_img, Size(), new_zoom, new_zoom, INTER_NEAREST); //按比例放大图片
}
//分辨率
RX = current_img.cols;
RY = current_img.rows;
if (g_iZoom <= 1)
m_resize = g_iZoom * 4;
else
m_resize = g_iZoom + 3;
imshow("view", current_img);
test_multi_Touch(csvData_Slip, canvas, m_zoom_size, m_TH, current_frame - 1, m_Line_size, m_extend,m_touch_seg);
cv::imshow("Visaul", canvas);
waitKey(1);
}
UpdateData(FALSE);
}
- 跳转至
//跳转至
void CTouch_test_CKV10Dlg::OnBnClickedButtongoto()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
zoom = false;
if (goto_frame < 1){
INT_PTR nRes;
// 显示消息对话框
nRes = MessageBox(_T("请输入大于1的正整数!"), _T("数据读取"), MB_OKCANCEL | MB_ICONWARNING);
}
else if (goto_frame >Frame_Num){
INT_PTR nRes;
// 显示消息对话框
nRes = MessageBox(_T("超出总帧数,请重新输入|"), _T("数据读取"), MB_OKCANCEL | MB_ICONWARNING);
}
else{
img = get_img(csvData_Slip, 1920, 1080, goto_frame - 1, Color);
CRect rect;
GetDlgItem(IDC_STATIC_IMG)->GetClientRect(&rect);
Rect dst(rect.left, rect.top, rect.right, rect.bottom);
resize(img, current_img, cv::Size(rect.Width(), rect.Height()));
//若前一帧缩放,后一帧也保持前一张的尺寸不变
if (pre_zoom){
double new_zoom = double(resize_mat.rows) / current_img.rows;
resize(current_img, current_img, Size(), new_zoom, new_zoom, INTER_NEAREST); //按比例放大图片
}
//分辨率
RX = current_img.cols;
RY = current_img.rows;
if (g_iZoom <= 1)
m_resize = g_iZoom * 4;
else
m_resize = g_iZoom + 3;
imshow("view", current_img);
current_frame = goto_frame;
//将质心清除
pre_CXY.clear();
for (int i = 0; i < pre_CXY_ALL.size(); ++i){
if (pre_CXY_ALL[i].first == current_frame){
circle(canvas, Point(pre_CXY_ALL[i].second.x, pre_CXY_ALL[i].second.y), m_Line_size, Scalar(255, 255, 0), -1); //可视化,在质心画圆
}
}
cv::imshow("Visaul", canvas);
waitKey(1);
UpdateData(FALSE);
}
}