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

[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
[Function] IplImage 에 한글text 삽입하기  (1) 2013.11.07
DC -> IplImage로 전환  (0) 2013.08.08
cv::Mat Class 사용법  (0) 2013.05.06
OpenCV 주요함수  (0) 2013.04.29
블로그 이미지

매직블럭

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

Tag function, IplImage, puttext 한글
트랙백 0개, 댓글 1개가 달렸습니다

댓글을 달아 주세요

  • 안녕하세요 2015.09.28 19:28  댓글주소  수정/삭제  댓글쓰기

    안녕하세요 혹시 한글폰트의 크기를 조절하는부분은 어디를 수정하면되나요?

  • «
  • 1
  • ···
  • 356
  • 357
  • 358
  • 359
  • 360
  • 361
  • 362
  • 363
  • 364
  • ···
  • 418
  • »

카테고리

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

태그목록

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

달력

«   2022/08   »
일 월 화 수 목 금 토
  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      
08-14 12:41

LATEST FROM OUR BLOG

  • windows terminal(powershell⋯.
  • vscode terminal 에 conda를⋯.
  • vscode에 conda 가상환경을⋯.
  • vscode keymap을 변경하자.
  • 골뱅이 연산자의 의미 (행렬곱)..
  • 프린터 용지 부족 문제를 해⋯.
  • [MXNet] 데이터 리스트를 만⋯.
  • 예쁘게 출력하자 pprint - pr⋯.
  • 작업표시줄 미리보기를 리스⋯.
  • 이미지 실제 파일 포맷 확인하기.
RSS 구독하기

BLOG VISITORS

  • Total : 1,149,449
  • Today : 38
  • Yesterday : 164

Copyright © 2015 Socialdev. All Rights Reserved.

티스토리툴바