因為 emgu 2.0的某個 bug 必須改寫cvCreateVideoWriter
存檔若有問題可參考我的範例如下:
string today;
double fourcc ;
private bool RecordInProgress;
public double GetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP index)
{
return CvInvoke.cvGetCaptureProperty(_ptr, index);
}
private void Recordbutton_Click(object sender, EventArgs e)
{//("試用版不提供錄影功能,請電****-393*32 *茂松")--PMC精密機械研發中心
if (_captureInProgress)
{
DateTime savetoday = DateTime.Now;
today = string.Format("{0:yyyyMMdd}", savetoday);
saveFileDialog1.FileName = "切削錄影"+ today;
fourcc = GetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FOURCC);
saveFileDialog1.ShowDialog();
}
}
VideoWriter Videowriter;
[DllImport("highgui200.dll")]
public static extern IntPtr cvCreateVideoWriter(
[MarshalAs(UnmanagedType.LPStr)] String filename,
int fourcc,
double fps,
int frame_size,
[MarshalAs(UnmanagedType.I1)] bool is_color);
private delegate void del_ProcessFileFram(object sender, EventArgs e);
private void saveFileDialog1_FileOk(object sender, CancelEventArgs e)
{
RecordInProgress = true;
captureButton.Enabled = false;
Recordbutton.Enabled = false ;
STOP_button.Enabled = true;
IntPtr ptr_capture = cvCreateVideoWriter(saveFileDialog1.FileName,(int) fourcc, 20, 640 * 480, true);
Videowriter = new VideoWriter(saveFileDialog1.FileName, 20, captureImageBox.Size.Width, captureImageBox.Size.Height, true);
IntPtr writer = Videowriter;
del_ProcessFileFram P_F_R=ProcessFileFrame;
Application.Idle += new EventHandler(P_F_R);
}
private void ProcessFileFrame(object sender, EventArgs arg)
{
if (RecordInProgress == false) return;
frame = _capture.QueryFrame();
captureImageBox.Image = frame;
Videowriter.WriteFrame(frame);
}
private void STOP_button_Click(object sender, EventArgs e)
{
RecordInProgress = false;
captureButton.Enabled = true;
STOP_button.Enabled = false;
del_ProcessFileFram P_F_R = ProcessFileFrame;
Application.Idle -= new EventHandler(P_F_R);
Videowriter.Dispose();
}
private void btn_flip_Click(object sender, EventArgs e)
{
_capture_flip = !_capture_flip;
if (_capture_flip)
{ //stop the capture
_capture.FlipHorizontal = true;
}
else
{ //start the capture
_capture.FlipHorizontal = false ;
}
} |