opencv在mfc中的应用

本文介绍如何在MFC应用程序中使用OpenCV库进行图像处理。首先创建一个辅助类来处理相关操作,然后探讨如何实现回调函数以集成OpenCV的功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

首先 先建立一个类,作为打杂使用

#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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值