|
아래와 같이 버튼 이벤트 발생시 Image 컴포넌트에 영상을 출력하고 싶은데
버튼 이벤트 발생시에 프로그램이 죽어버리네요.. 뭐가 문제인지 잘 모르겠습니다.
그리고 아래 주석으로 처리된 cvNamedWindow 를 주석 해제 하면 Image에 영상이
출력이 되더군요... 그리고 다시 창을 없애 버리면 영상이 나오질 않습니다.
그리고 Image에 영상이 나오더라도 영상의 깜박이게 되는 문제도 발생하게 됩니다..
뭐가 문제인지 찾다가 도저히 안되서.. 도움 요청 드립니다.
답변 좀 부탁드리겠습니다.
//---------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
int c;
Graphics::TBitmap *im = new Graphics::TBitmap;
IplImage *frame;
CvCapture* capture = cvCaptureFromCAM(0);
//cvNamedWindow("test",1);
while(1)
{
cvGrabFrame(capture);
frame = cvRetrieveFrame(capture);
IplImageToTBitmap (frame,im);
Image1->Picture->Bitmap->Assign(im);
c = cvWaitKey(10);
if ( c == 27) break;
}
cvReleaseCapture(&capture);
}
//---------------------------------------------------------------
bool __fastcall IplImageToTBitmap (const IplImage *src,Graphics::TBitmap *dest)
{
if (!src || !dest)
return false;
IplImage *temp;
CvRect roi;
if (src->roi)
roi=cvGetImageROI(src);
else
roi=cvRect(0,0,src->width,src->height);
temp=cvCreateImage(cvSize(roi.width,roi.height),IPL_DEPTH_8U,3);
if (src->nChannels!=3)
cvCvtColor(src,temp,CV_GRAY2RGB);
else
cvCopy(src,temp);
if (dest->Width==0 || dest->Height==0){
dest->Width = roi.width;
dest->Height = roi.height;
}
else{
IplImage *temp1=cvCloneImage(temp);
cvReleaseImageData(temp);
cvInitImageHeader(temp,cvSize(dest->Width,dest->Height),IPL_DEPTH_8U,3,src->origin,4);
cvCreateImageData(temp);
roi.width=dest->Width;
roi.height=dest->Height;
cvResize(temp1,temp);
cvReleaseImage(&temp1);
}
dest->PixelFormat=pf24bit;
try{
unsigned char *pLine;
int x,y;
for(y=0 ;y<roi.height;y++){
pLine = (unsigned char *)dest->ScanLine[roi.height-y-1];
for(x=0 ;x <roi.width*3 ;x++){
pLine[x]= ((unsigned char*)(temp->imageData + temp->widthStep*y))[x];
}
}
}
catch(...){
ShowMessage("Error while converting ...");
}
cvReleaseImage(&temp);
return true;
}
//---------------------------------------------------------------
|