• Tistory
    • 태그
    • 위치로그
    • 방명록
    • 관리자
    • 글쓰기
Carousel 01
Carousel 02
Previous Next

'IplImage'에 해당되는 글 1건

  • 2013.11.07 [Function] IplImage 에 한글text 삽입하기 1

[Function] IplImage 에 한글text 삽입하기

Programming/OpenCV 2013. 11. 7. 20:50




//========= header 에 추가 =========================


void setPutText( IplImage* src_image, IplImage* dst_image, char* text, CvPoint textPos, CvScalar color);

HBITMAP setTextToBitmap( char* text, CvScalar color);

IplImage* setBitmapToIplImage( HBITMAP hBitmap );



//========== 소스코드 ===============================



void CbrailleDlg::setPutText(IplImage* src_image, IplImage* dst_image, char* text, CvPoint textPos, CvScalar color)

{

// 명암도 영상에 대한 처리는 안함 칼라만 처리 일단..


if( src_image->nChannels != 1 )

cvCopy( src_image, dst_image );


int width = src_image->width;

int height = src_image->height;


if( (textPos.y > src_image->height) || (textPos.x > src_image->width) )

{

cvCopy( src_image, dst_image );

}


CvScalar var = {0,0,0,0};

HBITMAP hBitmap = setTextToBitmap(text, color);

IplImage* text_image = setBitmapToIplImage( hBitmap );


for( int nRow = textPos.y; nRow<(textPos.y + text_image->height); nRow++)

{

for( int nCol = textPos.x; nCol<(textPos.x + text_image->width); nCol++)

{

if( nRow >= height || nCol >= width) continue;

var = cvGet2D(text_image, nRow-textPos.y, nCol-textPos.x);


if( var.val[0] == color.val[0] && var.val[1] == color.val[1] && var.val[2] == color.val[2] )

cvSet2D(dst_image, nRow, nCol, var);

}

}


free(text_image->imageData);

cvReleaseImage( &text_image );

DeleteObject( hBitmap );

}



HBITMAP CbrailleDlg::setTextToBitmap( char* text, CvScalar color)

{

int textLength = (int)strlen(text);


if( textLength <= 0 ) return NULL;


HDC hTextDC = CreateCompatibleDC(NULL);


HFONT hOldFont = (HFONT)SelectObject( hTextDC, (HFONT)GetStockObject(SYSTEM_FONT) );

HBITMAP hDstBMP = NULL;


RECT textArea = {0, 0, 0, 0};


DrawText(hTextDC, (LPCTSTR)text, textLength, &textArea, DT_CALCRECT);


if( (textArea.right > textArea.left) && (textArea.bottom > textArea.top) )

{

BITMAPINFOHEADER bitmapInfoHeader;


memset( &bitmapInfoHeader, 0x0, sizeof(BITMAPINFOHEADER) );


void* lpvBits = NULL;


bitmapInfoHeader.biSize = sizeof(bitmapInfoHeader);

bitmapInfoHeader.biWidth = textArea.right-textArea.left;

bitmapInfoHeader.biHeight = textArea.bottom-textArea.top;

bitmapInfoHeader.biPlanes = 1;

bitmapInfoHeader.biBitCount = 32;

bitmapInfoHeader.biCompression = BI_RGB;


hDstBMP = CreateDIBSection( hTextDC, (LPBITMAPINFO)&bitmapInfoHeader, 0, (LPVOID*)&lpvBits, NULL, 0 );


HBITMAP hOldBMP = (HBITMAP)SelectObject( hTextDC, hDstBMP );


if( hOldBMP != NULL)

{

int TEXT_RED = (int)color.val[2];

int TEXT_GREEN = (int)color.val[1];

int TEXT_BLUE = (int)color.val[0];


SetTextColor( hTextDC, RGB(TEXT_RED, TEXT_GREEN, TEXT_BLUE) ); //text color


SetBkColor( hTextDC, 0x00EFFEFF ); //Background color


SetBkMode( hTextDC, OPAQUE ); // 투명


DrawText( hTextDC, (LPCTSTR)text, textLength, &textArea, DT_NOCLIP);

}

::SelectObject( hTextDC, hOldBMP );

}

::SelectObject( hTextDC, hOldFont );


if( hTextDC) { ::DeleteDC( hTextDC ); }

if( hOldFont) { ::DeleteObject( hOldFont ); }


return hDstBMP;

}



IplImage* CbrailleDlg::setBitmapToIplImage( HBITMAP hBitmap )

{

BITMAP bitmap;


GetObject( hBitmap, sizeof( BITMAP ), (LPSTR)&bitmap );


int nChannels = (bitmap.bmBitsPixel == 1)? 1: bitmap.bmBitsPixel*0.125;

int depth = (bitmap.bmBitsPixel == 1)? IPL_DEPTH_1U : IPL_DEPTH_8U;


IplImage* mImage = cvCreateImageHeader( cvSize(bitmap.bmWidth, bitmap.bmHeight), depth, nChannels );


mImage->imageData = (char*)malloc(bitmap.bmHeight * bitmap.bmWidth * nChannels * sizeof(char) );


memcpy(mImage->imageData, (char*)(bitmap.bmBits), bitmap.bmHeight * bitmap.bmWidth * nChannels );


cvFlip( mImage, mImage, 0 );


return mImage;

}


//================사용 예 ==========================

CString str;

str.Format( _T("한글") );

setPutText( &IplImage(m_Image), &IplImage(m_Image), (LPSTR)(LPCTSTR)str, cvPoint(10,10), CV_RGB(255,255,100) ); 

저작자표시 비영리 (새창열림)

'Programming > OpenCV' 카테고리의 다른 글

[Function] HoG Destriptor in OpenCV  (0) 2014.01.27
[Function] 영상을 회전 시키기  (0) 2014.01.23
DC -> IplImage로 전환  (0) 2013.08.08
cv::Mat Class 사용법  (0) 2013.05.06
OpenCV 주요함수  (0) 2013.04.29
블로그 이미지

매직블럭

작은 지식들 그리고 기억 한조각

,
  • «
  • 1
  • »

카테고리

  • 살다보니.. (449)
    • 주절거림 (3)
    • 취미생활 (36)
      • 지식과 지혜 (3)
      • 풍경이 되어 (4)
      • Memories (17)
      • 엥겔지수를 높여라 (2)
    • mathematics (6)
      • Matrix Computation (2)
      • RandomProcesses (3)
    • English.. (8)
    • Programming (147)
      • C, C++, MFC (51)
      • C# (1)
      • OpenCV (17)
      • Python (58)
      • Git, Docker (3)
      • Matlab (4)
      • Windows (3)
      • Kinect V2 (2)
      • 기타 etc. (8)
    • 전공관련 (80)
      • Algorithm (6)
      • Deep Learning (54)
      • 실습 프로그램 (4)
      • 주워들은 용어정리 (8)
      • 기타 etc. (8)
    • Computer (118)
      • Utility (21)
      • Windows (31)
      • Mac (4)
      • Ubuntu, Linux (58)
      • NAS (2)
      • Embedded, Mobile (2)
    • IT, Device (41)
      • 제품 사용기, 개봉기 (14)
      • 스마트 체험단 신청 (27)
    • Wish List (3)
    • TISTORY TIP (5)
    • 미분류. 수정중 (1)

태그목록

  • function
  • 크롬
  • LIBSVM
  • utility
  • 에누리닷컴
  • 오봉자싸롱
  • 매트랩
  • CStdioFile
  • 후쿠오카
  • Computer Tip
  • DeepLearning
  • 포르투갈
  • review
  • 칼로리 대폭발
  • 큐슈
  • Deep Learning
  • matlab
  • Convolutional Neural Networks
  • DSLR
  • 딥러닝
  • 스마트체험단
  • 갤럭시노트3
  • SVM
  • ColorMeRad
  • random variable
  • 매트랩 함수
  • matlab function
  • portugal
  • 일본
  • ReadString

달력

«   2025/07   »
일 월 화 수 목 금 토
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
07-21 03:20

LATEST FROM OUR BLOG

RSS 구독하기

BLOG VISITORS

  • Total :
  • Today :
  • Yesterday :

Copyright © 2015 Socialdev. All Rights Reserved.

티스토리툴바