-
大小: 50.83MB文件类型: .rar金币: 1下载: 0 次发布日期: 2022-11-03
- 语言: C/C++
- 标签: MFC+VS2013+O
资源简介
MFC+VS2013+OpenCV打开任意路径下的图片并显示,图片的格式可以是多种,显示的结果可以是原图,也可以是灰度图,这个困惑了很久的问题终于解决了
代码片段和文件信息
#include “StdAfx.h“
#include “CvvImage.h“
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CV_INLINE RECT NormalizeRect(RECT r);
CV_INLINE RECT NormalizeRect(RECT r)
{
int t;
if (r.left > r.right)
{
t = r.left;
r.left = r.right;
r.right = t;
}
if (r.top > r.bottom)
{
t = r.top;
r.top = r.bottom;
r.bottom = t;
}
return r;
}
CV_INLINE CvRect RectToCvRect(RECT sr);
CV_INLINE CvRect RectToCvRect(RECT sr)
{
sr = NormalizeRect(sr);
return cvRect(sr.left sr.top sr.right - sr.left sr.bottom - sr.top);
}
CV_INLINE RECT CvRectToRect(CvRect sr);
CV_INLINE RECT CvRectToRect(CvRect sr)
{
RECT dr;
dr.left = sr.x;
dr.top = sr.y;
dr.right = sr.x + sr.width;
dr.bottom = sr.y + sr.height;
return dr;
}
CV_INLINE IplROI RectToROI(RECT r);
CV_INLINE IplROI RectToROI(RECT r)
{
IplROI roi;
r = NormalizeRect(r);
roi.xOffset = r.left;
roi.yOffset = r.top;
roi.width = r.right - r.left;
roi.height = r.bottom - r.top;
roi.coi = 0;
return roi;
}
void FillBitmapInfo(BITMAPINFO* bmi int width int height int bpp int origin)
{
assert(bmi && width >= 0 && height >= 0 && (bpp == 8 || bpp == 24 || bpp == 32));
BITMAPINFOHEADER* bmih = &(bmi->bmiHeader);
memset(bmih 0 sizeof(*bmih));
bmih->biSize = sizeof(BITMAPINFOHEADER);
bmih->biWidth = width;
bmih->biHeight = origin ? abs(height) : -abs(height);
bmih->biPlanes = 1;
bmih->biBitCount = (unsigned short)bpp;
bmih->biCompression = BI_RGB;
if (bpp == 8)
{
RGBQUAD* palette = bmi->bmiColors;
int i;
for (i = 0; i < 256; i++)
{
palette[i].rgbBlue = palette[i].rgbGreen = palette[i].rgbRed = (BYTE)i;
palette[i].rgbReserved = 0;
}
}
}
CvvImage::CvvImage()
{
m_img = 0;
}
void CvvImage::Destroy()
{
cvReleaseImage(&m_img);
}
CvvImage::~CvvImage()
{
Destroy();
}
bool CvvImage::Create(int w int h int bpp int origin)
{
const unsigned max_img_size = 10000;
if ((bpp != 8 && bpp != 24 && bpp != 32) ||
(unsigned)w >= max_img_size || (unsigned)h >= max_img_size ||
(origin != IPL_ORIGIN_TL && origin != IPL_ORIGIN_BL))
{
assert(0); // most probably it is a programming error
return false;
}
if (!m_img || Bpp() != bpp || m_img->width != w || m_img->height != h)
{
if (m_img && m_img->nSize == sizeof(IplImage))
Destroy();
m_img = cvCreateImage(cvSize(w h) IPL_DEPTH_8U bpp / 8);
}
if (m_img)
m_img->origin = origin == 0 ? IPL_ORIGIN_TL : IPL_ORIGIN_BL;
return m_img != 0;
}
void CvvImage::CopyOf(CvvImage& image int desired_color)
{
IplImage* img = image.GetImage();
if (img)
{
CopyOf(img desired_color);
}
}
#define HG_IS_IMAGE(img) \
((img) != 0 && ((const IplImage*)(img))->nSize == sizeof(IplImage) && \
((IplImage*)img)->imageData != 0)
void CvvI
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 217088 2018-06-26 16:12 OpenImage\Debug\OpenImage.exe
文件 1467776 2018-06-26 16:12 OpenImage\Debug\OpenImage.ilk
文件 8612864 2018-06-26 16:12 OpenImage\Debug\OpenImage.pdb
文件 93847552 2018-06-26 16:10 OpenImage\ipch\openimage-7800facc\openimage-7cc11c61.ipch
文件 6417 2018-06-26 16:10 OpenImage\OpenImage\CvvImage.cpp
文件 1695 2018-06-26 16:06 OpenImage\OpenImage\CvvImage.h
文件 305965 2018-06-26 16:10 OpenImage\OpenImage\Debug\CvvImage.obj
文件 2355 2018-06-26 16:12 OpenImage\OpenImage\Debug\OpenImage.log
文件 316481 2018-06-26 16:10 OpenImage\OpenImage\Debug\OpenImage.obj
文件 43188224 2018-06-26 16:10 OpenImage\OpenImage\Debug\OpenImage.pch
文件 69672 2018-06-26 16:10 OpenImage\OpenImage\Debug\OpenImage.res
文件 2942 2018-06-26 16:12 OpenImage\OpenImage\Debug\OpenImage.tlog\cl.command.1.tlog
文件 135590 2018-06-26 16:12 OpenImage\OpenImage\Debug\OpenImage.tlog\CL.read.1.tlog
文件 1882 2018-06-26 16:12 OpenImage\OpenImage\Debug\OpenImage.tlog\CL.write.1.tlog
文件 3178 2018-06-26 16:12 OpenImage\OpenImage\Debug\OpenImage.tlog\li
文件 11610 2018-06-26 16:12 OpenImage\OpenImage\Debug\OpenImage.tlog\li
文件 702 2018-06-26 16:12 OpenImage\OpenImage\Debug\OpenImage.tlog\li
文件 156 2018-06-26 16:12 OpenImage\OpenImage\Debug\OpenImage.tlog\OpenImage.lastbuildstate
文件 582 2018-06-26 16:10 OpenImage\OpenImage\Debug\OpenImage.tlog\rc.command.1.tlog
文件 2868 2018-06-26 16:10 OpenImage\OpenImage\Debug\OpenImage.tlog\rc.read.1.tlog
文件 182 2018-06-26 16:10 OpenImage\OpenImage\Debug\OpenImage.tlog\rc.write.1.tlog
文件 352793 2018-06-26 16:12 OpenImage\OpenImage\Debug\OpenImageDlg.obj
文件 916248 2018-06-26 16:10 OpenImage\OpenImage\Debug\stdafx.obj
文件 3116032 2018-06-26 16:12 OpenImage\OpenImage\Debug\vc120.idb
文件 8212480 2018-06-26 16:12 OpenImage\OpenImage\Debug\vc120.pdb
文件 108544 2018-06-26 16:10 OpenImage\OpenImage\OpenImage.aps
文件 2413 2018-06-26 16:02 OpenImage\OpenImage\OpenImage.cpp
文件 461 2018-06-26 16:02 OpenImage\OpenImage\OpenImage.h
文件 10756 2018-06-26 16:10 OpenImage\OpenImage\OpenImage.rc
文件 6239 2018-06-26 16:10 OpenImage\OpenImage\OpenImage.vcxproj
............此处省略24个文件信息
评论
共有 条评论