opencv mat读取图片

一、在源文件dlg.cpp添加

#include "stdafx.h"
#include "afxdialogex.h"
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace std;
using namespace cv;
Mat image, imagedst;
int width,height;

二、在oninit里面添加

//页面样式
	namedWindow("view", WINDOW_AUTOSIZE);
	HWND hWnd = (HWND)cvGetWindowHandle("view");
	HWND hParent = ::GetParent(hWnd);
	::SetParent(hWnd, GetDlgItem(IDC_STATIC)->m_hWnd);
	::ShowWindow(hParent, SW_HIDE);	

三、在按钮方法下添加

CString picPath;   //定义图片路径变量  
CFileDialog dlg(TRUE, NULL, NULL, OFN_HIDEREADONLY |
	OFN_OVERWRITEPROMPT | OFN_ALLOWMULTISELECT, NULL, this);  //选择文件对话框  
if (dlg.DoModal() == IDOK)
{
	picPath = dlg.GetPathName();  //获取图片路径  
}
//CString to string  使用这个方法记得字符集选用“使用多字节字符”,不然会报错  
string picpath = picPath.GetBuffer(0);
image = imread(picpath);
//Mat imagedst;
//以下操作获取图形控件尺寸并以此改变图片尺寸  
CRect rect;
GetDlgItem(IDC_STATIC)->GetClientRect(&rect);
Rect dst(rect.left, rect.top, rect.right, rect.bottom);
width = rect.Width();
height = rect.Height();
resize(image, imagedst, cv::Size(rect.Width(), rect.Height()));
imshow("view", imagedst);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值