|
Canvas->Draw(0,0,im); 이렇게 하면 form에 동영상이 바로 뜨는데요 이것을 panel 위에 있는 image에다가 띄울려고
Image1->Canvas->Draw(10,10,im); 이렇게 했습니다.
그런데 run은 되는데 버튼을 클릭해도 동영상이 안 나옵니다.
아래는 프로그램 코드 입니다.
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;
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Graphics::TBitmap *im = new Graphics::TBitmap;
Graphics::TBitmap *img = new Graphics::TBitmap;
int i, threshold = 128; // 임계값(Threshold) 설정
IplImage *frame;
IplImage* output = 0;
IplImage* gray = 0;
CvCapture* capture = NULL;
capture = cvCaptureFromCAM(0);//카메라 시작
if(capture)
{
while(1)
{
if(!cvGrabFrame(capture))
break;
frame = cvRetrieveFrame(capture);
if(!frame)
break;
IplImageToTBitmap (frame,im);
//IplImageToTBitmap (output,img);
//Image1->Canvas->Draw(10,10,im);
Canvas->Draw(0,0,im);//Bitmap영상을 보여줌.
//Canvas->Draw(400,0,img);
if(cvWaitKey(0)>= 0)
break;
}
cvReleaseCapture(&capture);
}
}
그리고 질문 하나더요...
canvas를 이용해서 form에 동영상을 띄운후 button2를 클릭하면 동영상이 사라지게 만들고 싶은데요 그것도 쉽지가 안네요...
button1 윗부분은 opencv 코드 입니다.
|