全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:4879
推到 Plurk!
推到 Facebook!

有關bcb webcam錄影儲存方式

尚未結案
IVAN4
一般會員


發表:2
回覆:0
積分:0
註冊:2004-02-29

發送簡訊給我
#1 引用回覆 回覆 發表時間:2007-08-09 23:09:22 IP:140.125.xxx.xxx 訂閱
目前我已寫好webcam錄影程式

但是只能先存在buffer,按下關閉才會存到硬碟裡

我想問可不可以一邊錄就一邊存到硬碟裡面,而不是存到buffer裡面

希望好心人幫我解決問題,謝謝了~

以下是我寫的程式

<textarea class="cpp" rows="10" cols="60" name="code"> void __fastcall TForm1::Record1Click(TObject *Sender) { SaveDialog1->DefaultExt = "avi"; //檔案格式 SaveDialog1->FileName = "./video.avi"; //儲存 預設檔名 if(!SaveDialog1->Execute()) { return ; } AnsiString current_time,current_date; IplImage *frame = NULL; IplImage *current_frame = NULL; CvVideoWriter *Video_Record = NULL; CvCapture *capture = NULL; capture = cvCaptureFromCAM(0); IplImage *tmp = cvQueryFrame(capture); int Width = (int)cvGetCaptureProperty(capture,CV_CAP_PROP_FRAME_WIDTH); int Height = (int)cvGetCaptureProperty(capture,CV_CAP_PROP_FRAME_HEIGHT); //Video_Record = cvCreateVideoWriter(SaveDialog1->FileName.c_str() ,CV_FOURCC('M','J','P','G'),20.0,cvSize(640,480)); Video_Record = cvCreateVideoWriter(SaveDialog1->FileName.c_str() ,-1,10.0,cvSize(Width,Height)); if(capture) { for(;;) { if(!cvGrabFrame(capture)) break; frame = cvRetrieveFrame(capture); if(!frame) break; if(!current_frame) current_frame = cvCreateImage(cvSize(frame->width ,frame->height ), IPL_DEPTH_8U,frame->nChannels); if(frame->origin == IPL_ORIGIN_TL) cvCopy(frame, current_frame, 0); else cvFlip(frame, current_frame, 0); //current_time = DateToStr(Now()) TimeToStr(Now()); Word hour,Minute,second,msec; DecodeTime(Now(),hour,Minute,second,msec); current_time = DateToStr(Now()) " " IntToStr(hour) ":" IntToStr(Minute) ":" IntToStr(second); //TimeToStr(Now()); CvPoint point ; point.x = 10; point.y = 450; CvFont font; cvInitFont(&font,CV_FONT_VECTOR0,0.5,0.5,0.0,1.0); cvPutText(current_frame,current_time.c_str(),point, &font , CV_RGB(255,255,255)); IplImageToTBitmap(current_frame,Image1->Picture->Bitmap); Image1->Repaint(); cvWriteFrame(Video_Record,current_frame); if(cvWaitKey(10)>=0) break; if(Stop) break; Application->ProcessMessages(); } cvReleaseImage(¤t_frame); cvReleaseCapture(&capture); cvReleaseVideoWriter(&Video_Record); Image1->Picture->Bitmap = NULL; Image1->Repaint(); }else{ ShowMessage("找不到 Camera"); } } //--------------------------------------------------------------------------- void __fastcall TForm1::Stop1Click(TObject *Sender) { Stop = true; } //--------------------------------------------------------------------------- bool 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 ;yScanLine[y]; for(x=0 ;x imageData temp->widthStep*y))[x]; } } } catch(...) { ShowMessage("Error while converting ..."); } cvReleaseImage(&temp); return true; } </textarea>
系統時間:2024-11-22 11:39:33
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!