DirectShow设置摄像头的分辨率和图像格式代码如下所示:
|------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| // 设置参数,width=宽,height=高,fps=帧率 AM_MEDIA_TYPE *p = NULL; IAMStreamConfig *pSC = NULL; pCGB2->FindInterface(&PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video, pVCap, IID_IAMStreamConfig, (void **)&pSC); pSC->GetFormat(&p); VIDEOINFOHEADER *pHd = (VIDEOINFOHEADER *)p->pbFormat; // 单位为100ns,所以每帧(10^7/fps)*100ns pHd->AvgTimePerFrame = 10000000 / fps; // I420格式 pHd->bmiHeader.biCompression = MAKEFOURCC('I', '4', '2', '0'); pHd->bmiHeader.biWidth = width; pHd->bmiHeader.biHeight = height; // 一个像素点12位 pHd->bmiHeader.biBitCount = 12; // 图像大小 pHd->bmiHeader.biSizeImage = width * height * 3 / 2; // 图像传输率,单位bps pHd->dwBitRate = pHd->bmiHeader.biSizeImage * 8 * fps; // defined in wmsdkidl.h p->subtype = WMMEDIASUBTYPE_I420; p->lSampleSize = pHd->bmiHeader.biSizeImage; pSC->SetFormat(p); // free p FreeAM_MEDIA_TYPE(p); pSC->Release();
|