在vc++里用opencv处理bmp图片,求大侠帮忙! 100
我有一个bmp图片的函数,想换成opencv的方法把他实现,希望各位大侠能够帮忙,不胜感激!代码如下:voidCBmpText::DrawData(UCHAR*pAddr...
我有一个bmp图片的函数,想换成opencv的方法把他实现,希望各位大侠能够帮忙,不胜感激!代码如下:
void CBmpText::DrawData( UCHAR* pAddr, int wid, int hei, vector<SBmpText> texts )
{
pDc.CreateDC("DISPLAY", NULL, NULL, NULL);
int Width = wid;
int Height = hei;
memDC.CreateCompatibleDC(&pDc);
CBitmap pMemBmp;
pMemBmp.CreateCompatibleBitmap(&pDc, Width, Height);
CBitmap* pOld = memDC.SelectObject(&pMemBmp);
memDC.FillSolidRect(0, 0, Width, Height, RGB(255, 255, 255));
BITMAP btm;
pMemBmp.GetBitmap(&btm);
DWORD size = btm.bmWidthBytes * btm.bmHeight * 4;
DWORD sizeHead = sizeof(BITMAPINFOHEADER);
BITMAPINFOHEADER bmpHdr;
bmpHdr.biBitCount = btm.bmBitsPixel;
bmpHdr.biClrImportant = 0;
bmpHdr.biClrUsed = 0;
bmpHdr.biCompression = 0;
bmpHdr.biHeight = btm.bmHeight;
bmpHdr.biPlanes = 1;
bmpHdr.biSize = sizeof(BITMAPINFOHEADER);
bmpHdr.biSizeImage = size;
bmpHdr.biWidth = btm.bmWidth;
bmpHdr.biXPelsPerMeter = 0;
bmpHdr.biYPelsPerMeter = 0;
int iCount = 0;
UCHAR * pImage = NULL;
pImage = pAddr/*GetImagePtr(m_pFvxColorImage)*/;
for (int i=0; i<Height; i++)
{
memcpy(pTemp+Width*4*i, pImage+Width*4*(Height-i-1), Width*4);
}
iCount = SetDIBits(memDC.GetSafeHdc(), (HBITMAP)pMemBmp.m_hObject,
0, bmpHdr.biHeight, (LPVOID)pTemp, (BITMAPINFO*)&bmpHdr, DIB_RGB_COLORS);
CFont *pOldFont =(CFont*)memDC.SelectObject(&fontText);
memDC.SetBkMode(TRANSPARENT);
memDC.SetTextColor(RGB(255, 0, 0));
for (int index = 0; index < (int)texts.size(); index++)
{
SBmpText text = texts[index];
memDC.SetTextColor(text.color);
memDC.TextOut(text.x, text.y , text.strtext);
}
iCount = GetDIBits(memDC.GetSafeHdc(), (HBITMAP)pMemBmp.m_hObject, 0, bmpHdr.biHeight,
(LPVOID)pTemp, (BITMAPINFO*)&bmpHdr, DIB_RGB_COLORS);
if (iCount > 0)
{
for (int i=0; i<Height; i++)
{
memcpy(pImage+Width*4*i, pTemp+Width*4*(Height-i-1), Width*4);
}
}
memDC.SelectObject(pOld);
memDC.DeleteDC();
pDc.DeleteDC();
} 展开
void CBmpText::DrawData( UCHAR* pAddr, int wid, int hei, vector<SBmpText> texts )
{
pDc.CreateDC("DISPLAY", NULL, NULL, NULL);
int Width = wid;
int Height = hei;
memDC.CreateCompatibleDC(&pDc);
CBitmap pMemBmp;
pMemBmp.CreateCompatibleBitmap(&pDc, Width, Height);
CBitmap* pOld = memDC.SelectObject(&pMemBmp);
memDC.FillSolidRect(0, 0, Width, Height, RGB(255, 255, 255));
BITMAP btm;
pMemBmp.GetBitmap(&btm);
DWORD size = btm.bmWidthBytes * btm.bmHeight * 4;
DWORD sizeHead = sizeof(BITMAPINFOHEADER);
BITMAPINFOHEADER bmpHdr;
bmpHdr.biBitCount = btm.bmBitsPixel;
bmpHdr.biClrImportant = 0;
bmpHdr.biClrUsed = 0;
bmpHdr.biCompression = 0;
bmpHdr.biHeight = btm.bmHeight;
bmpHdr.biPlanes = 1;
bmpHdr.biSize = sizeof(BITMAPINFOHEADER);
bmpHdr.biSizeImage = size;
bmpHdr.biWidth = btm.bmWidth;
bmpHdr.biXPelsPerMeter = 0;
bmpHdr.biYPelsPerMeter = 0;
int iCount = 0;
UCHAR * pImage = NULL;
pImage = pAddr/*GetImagePtr(m_pFvxColorImage)*/;
for (int i=0; i<Height; i++)
{
memcpy(pTemp+Width*4*i, pImage+Width*4*(Height-i-1), Width*4);
}
iCount = SetDIBits(memDC.GetSafeHdc(), (HBITMAP)pMemBmp.m_hObject,
0, bmpHdr.biHeight, (LPVOID)pTemp, (BITMAPINFO*)&bmpHdr, DIB_RGB_COLORS);
CFont *pOldFont =(CFont*)memDC.SelectObject(&fontText);
memDC.SetBkMode(TRANSPARENT);
memDC.SetTextColor(RGB(255, 0, 0));
for (int index = 0; index < (int)texts.size(); index++)
{
SBmpText text = texts[index];
memDC.SetTextColor(text.color);
memDC.TextOut(text.x, text.y , text.strtext);
}
iCount = GetDIBits(memDC.GetSafeHdc(), (HBITMAP)pMemBmp.m_hObject, 0, bmpHdr.biHeight,
(LPVOID)pTemp, (BITMAPINFO*)&bmpHdr, DIB_RGB_COLORS);
if (iCount > 0)
{
for (int i=0; i<Height; i++)
{
memcpy(pImage+Width*4*i, pTemp+Width*4*(Height-i-1), Width*4);
}
}
memDC.SelectObject(pOld);
memDC.DeleteDC();
pDc.DeleteDC();
} 展开
3个回答
展开全部
PutText
Draws text string
void cvPutText( CvArr* img, const char* text, CvPoint org, const CvFont* font, CvScalar color );
imgInput image.textString to print.orgCoordinates of the bottom-left corner of the first letter.fontPointer to the font structure.colorText color.
The function cvPutText renders the text in the image with the specified font and color. The printed text is clipped by ROI rectangle. Symbols that do not belong to the specified font are replaced with the rectangle symbol.
具体实现因为太忙了不写了
给你几个建议:1 IplImage* image = cvCreateImage( cvSize(width,height), 8, 3 );
生成image指针
2.用上面的函数把字写到image里
不明白,可以写信给我zb_xutao@163.com
Draws text string
void cvPutText( CvArr* img, const char* text, CvPoint org, const CvFont* font, CvScalar color );
imgInput image.textString to print.orgCoordinates of the bottom-left corner of the first letter.fontPointer to the font structure.colorText color.
The function cvPutText renders the text in the image with the specified font and color. The printed text is clipped by ROI rectangle. Symbols that do not belong to the specified font are replaced with the rectangle symbol.
具体实现因为太忙了不写了
给你几个建议:1 IplImage* image = cvCreateImage( cvSize(width,height), 8, 3 );
生成image指针
2.用上面的函数把字写到image里
不明白,可以写信给我zb_xutao@163.com
参考资料: OpenCv manual
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询