반응형
250x250
Notice
Recent Posts
Recent Comments
Link
«   2025/04   »
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
Archives
Today
Total
관리 메뉴

폴크(FOLC)

머신 비전 사용법 - 버퍼 데이터 복사 본문

머신 비전/머신 비전 사용법 CPP

머신 비전 사용법 - 버퍼 데이터 복사

folcjin 2021. 12. 26. 18:15
728x90
반응형

# 8bit / 16bit / 24bit / 32bit 등의 여러가지 이미지 데이터 포멧이 있다.
   > CImage 형태 이용

   > 8bit : 0 ~ 255까지의 값을 표현 ( Gray )
   > 16bit : 0 ~ 65,535까지의 값을 표현 ( HQ Gray )
   > 24bit : 0 ~ 16,777,215까지의 값을 표현 ( RGB )
   > 32bit : 0 ~ 4,294,967,295까지의 값을 표현 ( RGBA )

# 소스 코드
const int src_sizex = src.GetWidth();
const int src_sizey = src.GetHeight();
const int src_pitch = abs(src.GetPitch());
const int src_bitpp = src.GetBPP();
const BYTE *srcPtr = (BYTE *)src.GetImageBuffer();

const int dst_sizex = dst.GetWidth();
const int dst_sizey = dst.GetHeight();
const int dst_pitch = abs(dst.GetPitch());
const int dst_bitpp = dst.GetBPP();
BYTE *dstPtr = (BYTE *)dst.GetImageBuffer();

for (int y = 0; y < src_sizey; ++y)
{
   for (int x = 0; x < src_sizex; ++x)
   {
      const int src_pos = y * src_pitch + x;
      const int dst_pos = y * dst_pitch + (x * (dst_bitpp / 8));
      for (int bt = 0; bt < (dst_bitpp / 8); bt++)
      {
         dstPtr[bt] = srcPtr[src_pos];
      }
   }
}

# 특수한 경우 ( 자료형이 float(실수) 으로 정해진 상태 )
const int src_sizex = src.GetWidth();
const int src_sizey = src.GetHeight();
const int src_pitch = abs(src.GetPitch());
const int src_bitpp = src.GetBPP();
const BYTE *srcPtr = (BYTE *)src.GetImageBuffer();

const int dst_sizex = dst.GetWidth();
const int dst_sizey = dst.GetHeight();
const int dst_pitch = abs(dst.GetPitch());
const int dst_bitpp = dst.GetBPP();
float *dstPtr = (float *)dst.GetImageBuffer();

for (int y = 0; y < src_sizey; ++y)
{
   for (int x = 0; x < src_sizex; ++x)
   {
      const int src_pos = y * src_pitch + x;
      const int dst_pos = y * dst_pitch / (dst_bitpp / 8) + x;
      dstPtr[dst_pos] = (float)srcPtr[src_pos];
   }
}

728x90
반응형
사업자 정보 표시
사업자 등록번호 : -- | TEL : --