首先 先建立一个类,作为打杂使用
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
//#include "colordetector.h"
class Detect {
private:
//static ColorDetectController *singleton; // pointer to the singleton
//ColorDetector *cdetect;
// The image to be processed
cv::Mat image;
cv::Mat result;
public:<pre name="code" class="cpp">bool setInputImage(std::string filename) {
image= cv::imread(filename);
if (!image.data)
return false;
else
return true;
}
// Returns the current input image.
const cv::Mat getInputImage() const {
return image;
}
}
// 建立。cpp
#include "stdafx.h"
#include "detect.h"
// 通过建立mfc对话框资源进行,首先打开*dlg.h
</pre><pre name="code" class="cpp"><pre name="code" class="cpp">// open image4Dlg.h : 头文件
//
#include "detect.h"
#pragma once
// Copenimage4Dlg 对话框
class Copenimage4Dlg : public CDialogEx
{
// 构造
private:
Detect *cdetect;
public:
Copenimage4Dlg(CWnd* pParent = NULL); // 标准构造函数
// 对话框数据
enum { IDD = IDD_OPENIMAGE4_DIALOG };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
// 实现
protected:
HICON m_hIcon;
// 生成的消息映射函数
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnBnClickedButton1();
afx_msg void OnBnClickedButton2();
~Copenimage4Dlg()
{
delete cdetect;
}
afx_msg void OnBnClickedButton3();
afx_msg void OnBnClickedButton4();
afx_msg void OnBnClickedButton5();
afx_msg void OnBnClickedButton6();
afx_msg void OnBnClickedButton7();
afx_msg void OnBnClickedButton8();
afx_msg void OnBnClickedButton9();
afx_msg void OnBnClickedButton10();
afx_msg void OnBnClickedButton11();
};
//打开dlg.cpp
//文件头
#include "stdafx.h"
#include "open image4.h"
#include "open image4Dlg.h"
#include "afxdialogex.h"
#include <opencv2/core/core.hpp>
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/imgproc/imgproc.hpp>
#include <iostream>
using namespace std;
using namespace cv;
//打开其中的一个button 作为open onepicture
<pre name="code" class="cpp">Mat src;
void Copenimage4Dlg::OnBnClickedButton1()
{
// TODO: 在此添加控件通知处理程序代码
CF