안녕하세요?
전체 화면을 캡쳐해서 화면의 내용을 누적 평균시켜 표현 하려고 합니다...
캡쳐하는건 쓰레드를 이용해서 구현했는데요, 누적하는 부분이 계속 말썽이네요...
아래와 같이 FrameCount를 이용하여 RESULT에 계속 누적시켜가며 평균을 구했습니다만...
누적이 안되네요... ResultLine쪽에 문제가 있는건지...
현재화면 캡쳐는 잘 되는데, 이전화면(누적된)이 누적이 안되고 그냥 이전 화면만 나옵니다.
이전화면이 계속 리프레쉬 되는 듯 한....
Graphics::TBitmap *CAPTURE;
Graphics::TBitmap *RESULT;
//전체화면 캡쳐
BitBlt(CAPTURE->Canvas->Handle, 0, 0, Screen->Width, Screen->Height, DC, 0, 0, SRCCOPY);
//첫번째 프레임
if(FrameCount==0) RESULT = CAPTURE;
for(int row = 0; row < Screen->Height; row++) {
CurrentLine = (Byte *)(CAPTURE->ScanLine[row]);
if(FrameCount!=0)ResultLine = (Byte *)(RESULT->ScanLine[row]);
for(int col = 0; col < Screen->Width; col++) {
// 현재 프레임의 평균 그레이 계산
PixelCount = col+(row*(Screen->Width));
RAve = RAve + CurrentLine[col*3+0];
GAve = GAve + CurrentLine[col*3+1];
BAve = BAve + CurrentLine[col*3+2];
if(FrameCount!=0){
// 평균프레임과 현재 프레임과 픽셀연산
// (이전평균*카운트 + 현재프레임데이타) / 카운트+1
// (이전평균 * 카운트)/카운트+1
RtempPrev=ResultLine[col*3+0]*FrameCount/(FrameCount+1);
GtempPrev=ResultLine[col*3+1]*FrameCount/(FrameCount+1);
BtempPrev=ResultLine[col*3+2]*FrameCount/(FrameCount+1);
// 현재프레임/카운트+1
RtempCurr=CurrentLine[col*3+0]/(FrameCount+1);
GtempCurr=CurrentLine[col*3+1]/(FrameCount+1);
BtempCurr=CurrentLine[col*3+2]/(FrameCount+1);
// 위의 두 변수를 더함 = (이전평균*카운트 + 현재프레임데이타) / 카운트+1
ResultLine[col*3+0] = (Byte)RtempPrev + (Byte)RtempCurr;
ResultLine[col*3+1] = (Byte)GtempPrev + (Byte)GtempCurr;
ResultLine[col*3+2] = (Byte)BtempPrev + (Byte)BtempCurr;
}
}
}
FrameCount++;
CAPTURE->SaveToFile("test_C.bmp");
RESULT->SaveToFile("test_R.bmp");
|