기본 콘텐츠로 건너뛰기

5월, 2021의 게시물 표시

기타 - 영상인식과 색상모델(Gray,RGB,HSV,YCbCr)

  영상인식과 색상모델(Gray,RGB,HSV,YCbCr) 영상처리   2013. 5. 17. 16:27 어떤 색상 모델을 선택하는 것이 좋을까? 어떤 색상 모델을 사용해야 영상인식 알고리즘의 성능을 극대화할 수 있을까? 영상인식 알고리즘을 개발하는 사람이라면 한 번쯤은 고민해 봤을 문제입니다. 이 글에서는 색상모델을 선택하는데 도움이 될 수 있도록 색상모델에 대한 전반적인 내용을 영상처리 관점에서 정리해 보겠습니다. 1. 기본적인 색상 모델 알아보기 색상모델하면 Gray 모델, RGB 모델, HSV 모델, YCbCr 모델 등이 떠오를 것이다. Gray 모델은 색(color) 정보를 사용하지 않고 밝기 정보만으로 영상을 표현하는 것이다. 검정색 0부터 흰색 255까지 총 256단계의 밝기값(intensity)으로 영상 픽셀값을 표현한다. RGB 모델은 가장 기보적인 색상모델로서 색(color)을 Red, Green, Blue의 3가지 성분의 조합으로 생각하는 것이다. RGB 모델에서 검은색은 R=G=B=0, 흰색은 R=G=B=255, 빨강색은 R=255, G=B=0, 노란색은 R=G=255, B=0로 표현된다. R=G=B인 경우는 무채색인 Gray 색상이 된다. R, G, B 각각은 0 ~ 255 사이의 값을 가질 수 있기 때문에 RGB 색상 모델을 사용하면 총 256*256*256 = 16,777,216가지의 색을 표현할 수 있다. HSV 모델은 Hue(색조), Saturation(채도), Value(명도)의 3가지 성분으로 색을 표현한다. Hue는 색조(예: 붉은색 계열인지 푸른색 계열인지, ...)를, Saturation은 그 색이 얼마나 선명한(순수한) 색인지를, Value는 밝기(intensity)를 나타낸다. HSV 모델은 우리가 색을 가장 직관적으로 표현할 수 있는 모델이며 또한 머리속에서 상상하는 색을 가장 쉽게 만들어낼 수 있는 모델이다. 영상처리/영상인식에서 HSV 모델을 사용할 때, H, S, V 각각은 0...

C++ - Int[] to SAFEARRAY 테스트 2

 SAFEARRAY* IntArrayToSafeArray(int pts[], int nPoints) { SAFEARRAY* safearray; SAFEARRAYBOUND BoundOutput; BoundOutput.cElements = nPoints; BoundOutput.lLbound = 0; safearray = SafeArrayCreate(VT_I4, 1, &BoundOutput); int* pdata; SafeArrayAccessData(safearray, (void**)&pdata); for (int i = 0; i < nPoints; i++) pdata[i] = pts[i]; SafeArrayUnaccessData(safearray); return safearray; } int getPerspectiveTransform(char* src_img_file, char* dst_img_file) { int result; const int nPoints = 8; _bstr_t src_img_file2(src_img_file); _bstr_t dst_img_file2(dst_img_file); int src_pts[8] = { 10, 25, 120, 790, 2200, 750, 2275, 10 }; int dst_pts[8] = { 10, 25, 10, 790, 2275, 790, 2275, 25 }; SAFEARRAY* output; SAFEARRAY* output2; output = IntArrayToSafeArray(src_pts, nPoints); output2 = IntArrayToSafeArray(dst_pts, nPoints); OpenCVInterface* ocv = NULL; CoInitialize(NULL); HRESULT hr = CoCreateInstance(CLSID_OpenCV, NULL, CLSCTX_INPROC_SER...

C++ - int[] to SafeArray 변환 테스트

 int getPerspectiveTransform(char* src_img_file, char* dst_img_file) { int result; const int nPoints = 8; _bstr_t src_img_file2(src_img_file); _bstr_t dst_img_file2(dst_img_file); int src_pts[8] = { 10, 25, 120, 790, 2200, 750, 2275, 10 }; int dst_pts[8] = { 10, 25, 10, 790, 2275, 790, 2275, 25 }; SAFEARRAY* output; SAFEARRAYBOUND BoundOutput; BoundOutput.cElements = nPoints; BoundOutput.lLbound = 0; output = SafeArrayCreate(VT_I4, 1, &BoundOutput); int* pdata1; SafeArrayAccessData(output, (void**)&pdata1); for (int i = 0; i < nPoints; i++) pdata1[i] = src_pts[i]; SafeArrayUnaccessData(output); SAFEARRAY* output2; SAFEARRAYBOUND BoundOutput2; BoundOutput2.cElements = nPoints; BoundOutput2.lLbound = 0; output2 = SafeArrayCreate(VT_I4, 1, &BoundOutput2); int* pdata2; SafeArrayAccessData(output2, (void**)&pdata2); for (int i = 0; i < nPoints; i++) pdata2[i] = dst_pts[i]; SafeArrayUnaccessData(output2); OpenC...

C++ - VT_array

  VT 는 Variant의 약자로서 여러 type의 변수의 형태를 다 가지고 있는 변수 입니다. 실제 VT를 자세히 들여다 보면 아래같은 내용을 갖고 있습니다 union { unsigned char bVal; // VT_UI1. short iVal; // VT_I2 . long lVal; // VT_I4 . float fltVal; // VT_R4 . double dblVal; // VT_R8 . VARIANT_BOOL boolVal; // VT_BOOL. SCODE scode; // VT_ERROR. CY cyVal; // VT_CY . DATE date; // VT_DATE. BSTR bstrVal; // VT_BSTR. IUnknown FAR* punkVal; // VT_UNKNOWN. IDispatch FAR* pdispVal; // VT_DISPATCH. SAFEARRAY FAR* parray; // VT_ARRAY|*. unsigned char FAR* pbVal; // VT_BYREF|VT_UI1. short FAR* piVal; // VT_BYREF|VT_I2. long FAR* plVal; // VT_BYREF|VT_I4. float FAR* pfltVal; // VT_BYREF|VT_R4. double FAR* pdblVal; // VT_BYREF|VT_R8. VARIANT_BOOL FAR* pboolVal; // VT_BYREF|VT_BOOL. SCODE FAR* pscode; // VT_BYREF|VT_ERROR. CY FAR* pcyVal; // VT_BYREF|VT_CY. DATE FAR* pdate; // VT_BYREF|VT_DATE. BSTR FAR* pbstrVal; // VT_BYREF|VT_BSTR. IUnknown FAR* FAR* ppunkVal; // VT_BYREF|VT_UNKNOWN. IDispatch FAR* FAR* ppdispVal; // VT_BYREF|VT_DISPATCH. SAFEARRAY FAR...

C++ StretchBlt

  StretchBlt  함수 StretchBlt function (wingdi.h) 12/05/2018 3 minutes to read The  StretchBlt  function copies a bitmap from a source rectangle into a destination rectangle, stretching or compressing the bitmap to fit the dimensions of the destination rectangle, if necessary. The system stretches or compresses the bitmap according to the stretching mode currently set in the destination device context. Syntax C++ Copy BOOL StretchBlt ( HDC hdcDest, int xDest, int yDest, int wDest, int hDest, HDC hdcSrc, int xSrc, int ySrc, int wSrc, int hSrc, DWORD rop ) ; Parameters hdcDest A handle to the destination device context. xDest The x-coordinate, in logical units, of the upper-left corner of the destination rectangle. yDest The y-coordinate, in logical units, of the upper-left corner of the destination rectangle. wDest The width, in logical units, of the destination rectangle. hDest The height, in logical units, of the desti...