|
我只能将灰度图像保存成AVI文件,不能将彩色图像保存成AVI文件。当保存彩色图像时,抛出异常:
cvWriteFrame() needs images with depth = IPL_DEPTH_8U and nChannels = 1.
附程序: Capture camera = new Capture("E:\\music\\avril.avi");
if (camera == null)
{
MessageBox.Show("can't find a camera", "error");
}
double fps= camera.GetCaptureProperty(CAP_PROP.CV_CAP_PROP_FPS);
double cpHeight=camera.GetCaptureProperty(CAP_PROP.CV_CAP_PROP_FRAME_HEIGHT);
double cpWidth = camera.GetCaptureProperty(CAP_PROP.CV_CAP_PROP_FRAME_WIDTH);
double fourcc=camera.GetCaptureProperty(CAP_PROP.CV_CAP_PROP_FOURCC);
CvInvoke.cvNamedWindow("camera");
Image<Bgr, byte> temp = camera.QueryFrame();
VideoWriter video = new VideoWriter("video.avi",(int)fourcc,20, 800, 480,false);
while (temp != null)
{
CvInvoke.cvShowImage("camera", temp.Ptr);
temp = camera.QueryFrame();
int c = CvInvoke.cvWaitKey(20);
video.WriteFrame<Bgr,byte>(temp);//如果用Gray就不会报错,可以保存,现在这样出现上述错误
if (c == 27) break;
}
video.Dispose();
camera.Dispose();
CvInvoke.cvDestroyWindow("camera"); |
|