CvvImage类Word格式.docx

上传人:b****3 文档编号:16927367 上传时间:2022-11-27 格式:DOCX 页数:11 大小:17.28KB
下载 相关 举报
CvvImage类Word格式.docx_第1页
第1页 / 共11页
CvvImage类Word格式.docx_第2页
第2页 / 共11页
CvvImage类Word格式.docx_第3页
第3页 / 共11页
CvvImage类Word格式.docx_第4页
第4页 / 共11页
CvvImage类Word格式.docx_第5页
第5页 / 共11页
点击查看更多>>
下载资源
资源描述

CvvImage类Word格式.docx

《CvvImage类Word格式.docx》由会员分享,可在线阅读,更多相关《CvvImage类Word格式.docx(11页珍藏版)》请在冰豆网上搜索。

CvvImage类Word格式.docx

LoadRect(constchar*filename,

intdesired_color,CvRectr);

#ifdefinedWIN32||defined_WIN32

intdesired_color,RECTr)

returnLoadRect(filename,desired_color,

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

}

#endif

Save(constchar*filename);

virtualvoid 

CopyOf(CvvImage&

image,intdesired_color=-1);

CopyOf(IplImage*img,intdesired_color=-1);

IplImage*GetImage(){returnm_img;

};

Destroy(void);

intWidth(){return!

m_img?

0:

!

m_img->

roi?

m_img->

width:

roi->

width;

intHeight(){return!

height:

height;

};

intBpp(){returnm_img?

(m_img->

depth&

255)*m_img->

nChannels:

0;

Fill(intcolor);

Show(constchar*window);

Show(HDCdc,intx,inty,intwidth,intheight,

intfrom_x=0,intfrom_y=0);

DrawToHDC(HDChDCDst,RECT*pDstRect);

protected:

IplImage* 

m_img;

typedefCvvImageCImage;

//---------------------------------------------------------------

CvvImage.cpp

StdAfx.h"

//////////////////////////////////////////////////////////////////////

//Construction/Destruction

CV_INLINERECTNormalizeRect(RECTr);

CV_INLINERECTNormalizeRect(RECTr)

intt;

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;

returnr;

CV_INLINECvRectRectToCvRect(RECTsr);

CV_INLINECvRectRectToCvRect(RECTsr)

sr=NormalizeRect(sr);

returncvRect(sr.left,sr.top,sr.right-sr.left,sr.bottom-sr.top);

CV_INLINERECTCvRectToRect(CvRectsr);

CV_INLINERECTCvRectToRect(CvRectsr)

RECTdr;

dr.left=sr.x;

dr.top=sr.y;

dr.right=sr.x+sr.width;

dr.bottom=sr.y+sr.height;

returndr;

CV_INLINEIplROIRectToROI(RECTr);

CV_INLINEIplROIRectToROI(RECTr)

IplROIroi;

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;

returnroi;

void 

FillBitmapInfo(BITMAPINFO*bmi,intwidth,intheight,intbpp,intorigin)

assert(bmi&

&

width>

=0&

height>

(bpp==8||bpp==24||bpp==32));

BITMAPINFOHEADER*bmih=&

(bmi->

bmiHeader);

memset(bmih,0,sizeof(*bmih));

bmih->

biSize=sizeof(BITMAPINFOHEADER);

biWidth=width;

biHeight=origin?

abs(height):

-abs(height);

biPlanes=1;

biBitCount=(unsignedshort)bpp;

biCompression=BI_RGB;

if(bpp==8)

RGBQUAD*palette=bmi->

bmiColors;

inti;

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;

voidCvvImage:

Destroy()

cvReleaseImage(&

m_img);

~CvvImage()

Destroy();

bool 

CvvImage:

Create(intw,inth,intbpp,intorigin)

constunsignedmax_img_size=10000;

if((bpp!

=8&

bpp!

=24&

=32)||

(unsigned)w>

max_img_size||(unsigned)h>

=max_img_size||

(origin!

=IPL_ORIGIN_TL&

origin!

=IPL_ORIGIN_BL))

assert(0);

//mostprobably,itisaprogrammingerror

returnfalse;

if(!

m_img||Bpp()!

=bpp||m_img->

width!

=w||m_img->

height!

=h)

if(m_img&

nSize==sizeof(IplImage))

m_img=cvCreateImage(cvSize(w,h),IPL_DEPTH_8U,bpp/8);

if(m_img)

origin=origin==0?

IPL_ORIGIN_TL:

IPL_ORIGIN_BL;

returnm_img!

=0;

CopyOf(CvvImage&

image,intdesired_color)

IplImage*img=image.GetImage();

if(img)

CopyOf(img,desired_color);

#defineHG_IS_IMAGE(img) 

\

((img)!

((constIplImage*)(img))->

nSize==sizeof(IplImage)&

((IplImage*)img)->

imageData!

=0)

CopyOf(IplImage*img,intdesired_color)

if(HG_IS_IMAGE(img))

intcolor=desired_color;

CvSizesize=cvGetSize(img);

if(color<

0)

color=img->

nChannels>

1;

if(Create(size.width,size.height,

(!

color?

1:

img->

1?

3)*8,

img->

origin))

cvConvertImage(img,m_img,0);

Load(constchar*filename,intdesired_color)

IplImage*img=cvLoadImage(filename,desired_color);

img)

img);

returntrue;

LoadRect(constchar*filename,

intdesired_color,CvRectr)

if(r.width<

0||r.height<

0)returnfalse;

if(r.width==0||r.height==0)

r.width=img->

r.height=img->

r.x=r.y=0;

if(r.x>

width||r.y>

height||

r.x+r.width<

0||r.y+r.height<

if(r.x<

r.width+=r.x;

r.x=0;

if(r.y<

r.height+=r.y;

r.y=0;

if(r.x+r.width>

width)

width-r.x;

if(r.y+r.height>

height)

height-r.y;

cvSetImageROI(img,r);

Save(constchar*filename)

m_img)

cvSaveImage(filename,m_img);

Show(constchar*window)

cvShowImage(window,m_img);

Show(HDCdc,intx,inty,intw,inth,intfrom_x,intfrom_y)

depth==IPL_DEPTH_8U)

ucharbuffer[sizeof(BITMAPINFOHEADER)+1024];

BITMAPINFO*bmi=(BITMAPINFO*)buffer;

intbmp_w=m_img->

width,bmp_h=m_img->

FillBitmapInfo(bmi,bmp_w,bmp_h,Bpp(),m_img->

origin);

from_x=MIN(MAX(from_x,0),bmp_w-1);

from_y=MIN(MAX(from_y,0),bmp_h-1);

intsw=MAX(MIN(bmp_w-from_x,w),0);

intsh=MAX(MIN(bmp_h-from_y,h),0);

SetDIBitsToDevice(

dc,x,y,sw,sh,from_x,from_y,from_y,sh,

imageData+from_y*m_img->

widthStep,

bmi,DIB_RGB_COLORS);

DrawToHDC(HDChDCDst,RECT*pDstRect)

if(pDstRect&

m_img&

depth==IPL_DEPTH_8U&

imageData)

CvRectroi=cvGetImageROI(m_img);

CvRectdst=RectToCvRect(*pDstRect);

if(roi.width==dst.width&

roi.height==dst.height)

Show(hDCDst,dst.x,dst.y,dst.width,dst.height,roi.x,roi.y);

return;

if(roi.width>

dst.width)

SetStretchBltMode(

hDCDst, 

//handletodevicecontext

HALFTONE);

else

COLORONCOLOR);

StretchDIBits(

hDCDst,

dst.x,dst.y,dst.width,dst.height,

roi.x,roi.y,roi.width,roi.height,

imageData,bmi,DIB_RGB_COLORS,SRCCOPY);

Fill(intcolor)

cvSet(m_img,cvScalar(color&

255,(color>

>

8)&

16)&

24)&

255));

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 工程科技 > 能源化工

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1