VS2015+opencv+MFC+显示图片

       网上有很多关于在MFC显示图片的教程,但是看下来感觉对一个小白来说太过于麻烦,总有些东西没有写完成,操作下来总有些错误,实在没有办法我只好下了一个可以运行的例子,比较之后自己按照下载的例子模仿操作总算可以显示图片了, 下面是我对opencv在MFC显示图片的总结,我将一步一步的阐述,尽可能的详细来讲。

     1 新建MFC应用程序

2 选择基于对话框

3 下面不再进行设置,直接点击完成

4 添加CvvImage.h和CvvImage.cpp文件

CvvImage.h文件

#include "opencv/cv.h"
#include "opencv/highgui.h"
#pragma once

#ifndef CVVIMAGE_CLASS_DEF

#define CVVIMAGE_CLASS_DEF

#include "opencv.hpp"

class  CvvImage

{

public:

	CvvImage();

	virtual ~CvvImage();



	virtual bool  Create(int width, int height, int bits_per_pixel, int image_origin = 0);



	virtual bool  Load(const char* filename, int desired_color = 1);



	virtual bool  LoadRect(const char* filename,

		int desired_color, CvRect r);

#if defined WIN32 || defined _WIN32

	virtual bool  LoadRect(const char* filename,

		int desired_color, RECT r)

	{

		return LoadRect(filename, desired_color,

			cvRect(r.left, r.top, r.right - r.left, r.bottom - r.top));

	}

#endif



	virtual bool  Save(const char* filename);



	virtual void  CopyOf(CvvImage& image, int desired_color = -1);

	virtual void  CopyOf(IplImage* img, int desired_color = -1);

	IplImage* GetImage() { return m_img; };

	virtual void  Destroy(void);



	int Width() { return !m_img ? 0 : !m_img->roi ? m_img->width : m_img->roi->width; };

	int Height() { return !m_img ? 0 : !m_img->roi ? m_img->height : m_img->roi->height; };

	int Bpp() { return m_img ? (m_img->depth & 255)*m_img->nChannels : 0; };

	virtual void  Fill(int color);



	virtual void  Show(const char* window);



#if defined WIN32 || defined _WIN32



	virtual void  Show(HDC dc, int x, int y, int width, int height,

		int from_x = 0, int from_y = 0);



	virtual void  DrawToHDC(HDC hDCDst, RECT* pDstRect);

#endif

protected:

	IplImage*  m_img;

};

//typedef CvvImage CImage;
namespace cv
{
	typedef CvvImage CImage;
}
#endif

CvvImage

  • 6
    点赞
  • 43
    收藏
    觉得还不错? 一键收藏
  • 11
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值