关于PixelFormat(200分)

  • 主题发起人 主题发起人 eliuliu
  • 开始时间 开始时间
E

eliuliu

Unregistered / Unconfirmed
GUEST, unregistred user!
由于程序要在视频播放的同时进行图像质量的分析,而设置PixelFormat属性确实比较慢而且资源占用比较多,我想请教能取代PixelFormat属性而且速度和资源占用都比较小的方法。
程序部分代码,虽然是C++,但是VCL是相同的:
capGrabFrameNoStop(hCapture);
capEditCopy(hCapture);
Graphics::TBitmap *bmTest = new Graphics::TBitmap;
bmTest->Assign(Clipboard());
bmTest->PixelFormat = pf24bit;// 该设置导致了视频的停顿,但是不设置该项会导致数据的失真。
 
这个东西确实比较紧急,所以分数可以大量供应,但是一定要解决问题,呵呵。
通过设置capSetCallbackOnFrame回调函数来实现也可以,关键是要解决在进行图像分析不能影响视频流的播放,不能产生停顿感。
另,我使用了多线程来处理,可以效果还是不好,照样会产生停顿,我的图像分析是每间隔0.1s分析一次,这个算法不会占用太多资源(曾经测试过),最主要的还是
bmTest->PixelFormat = pf24bit会占用太多资源。
 
1 视频卡本身和桌面的颜色深度都设为 24位
2 建议用回调来处理,10 帧的速度没问题,剪贴板有诸多不便。
 
给cqbaobao
1、其实只需要将视频卡的颜色设为24位即可。
2、你那有回调函数的具体例子吗?譬如将获得的桢数据保存为BMP图像。
 
http://www.delphibbs.com/delphibbs/dispq.asp?lid=1035658

这个问题有 N 个人回答了 N 次了:)
 
给cqbaobao,你的N次的回答对我好像并不适用
这是我的回调函数
LRESULT CALLBACK FrameCallBack(HWND hwnd, Longint lpvhdr)
{
static BITMAPINFOHEADER BitmapHead;
static BITMAPINFO BitmapInfo;
static BITMAPFILEHEADER BitmapFileHead;
CAPSTATUS status;
int BIHsize, byte;
Byte *ptr;
LPVIDEOHDR VideoStr;
TMemoryStream *stream = new TMemoryStream;
// 取得圖片資料
VideoStr = LPVIDEOHDR(lpvhdr);
// 取得CAP訊息
capGetStatus(hwnd, &status, sizeof(status))
// 取得圖片格式容量大小
BIHsize = capGetVideoFormatSize(hwnd);
// 取得圖片格式 代入 bitmapinfohead 內
capGetVideoFormat(hwnd, &BitmapHead, BIHsize);
// 設定 BITMAPINFO
BitmapInfo.bmiHeader = BitmapHead;
// 取得圖檔總容量
stream->Size = sizeof(BitmapFileHead) + sizeof(BitmapHead) + BitmapHead.biSizeImage;
// 設定 BITMAPFILEHEAD
BitmapFileHead.bfType = 0x4D42;
//總是 BM
BitmapFileHead.bfSize = stream->Size;
//該圖檔總大小
BitmapFileHead.bfOffBits = sizeof(BitmapFileHead) + sizeof(BitmapHead);
// 偏移至imagedata大小
// 將資料存入 memorystream
stream->Position=0;
stream->WriteBuffer(&BitmapFileHead, sizeof(BitmapFileHead));
stream->WriteBuffer(&BitmapInfo, sizeof(BitmapInfo));
(void*)ptr = stream->Memory;
ptr += BitmapFileHead.bfOffBits;
Move(VideoStr->lpData, ptr, BitmapHead.biSizeImage);
// 存入完成
stream->Position=0;
if(bmTest)
bmTest->LoadFromStream(stream);
delete(stream);
bAssigned = true;
capSetCallbackOnFrame(hwnd, NULL);
//停止callbackonframe
return(0);
}
 
不要用vcl来实现,直接操作抓到的buffer,进行处理。vcl本来就比较慢。
 
怎么个“不适合”法?

我不太懂 BCB,但其中
1. capSetCallbackOnFrame(hwnd, NULL);
//停止callbackonframe 是为什么?
2. 为什么不用我那里提供的 FrameToBitmap 过程呢? (SetDIBits)

 
给cqbaobao
1、因为并不需要处理所有的桢数据,而是采用定时触发的形式选取并分析。
2、 with Bitmapdo

setDiBits(canvas.handle, handle, 0, BitmapInfo.bmiHeader.biheight,
FrameBuffer, BitmapInfo, DIB_RGB_COLORS);
这一句在BCB的开发环境中编译通不过,该方法setDiBits找不到。
 
那是一个 API,

Requirements
Windows NT/2000: Requires Windows NT 3.1 or later.
Windows 95/98: Requires Windows 95 or later.
Header: Declared in Wingdi.h;
include Windows.h.
Library: Use Gdi32.lib.

SetDIBits
The SetDIBits function sets the pixels in a bitmap using the color data found in the specified DIB .

int SetDIBits(
HDC hdc, // handle to DC
HBITMAP hbmp, // handle to bitmap
UINT uStartScan, // starting scan line
UINT cScanLines, // number of scan lines
CONST VOID *lpvBits, // array of bitmap bits
CONST BITMAPINFO *lpbmi, // bitmap data
UINT fuColorUse // type of color indexes to use
);
Parameters
hdc
[in] Handle to a device context.
hbmp
[in] Handle to the bitmap that is to be altered using the color data from the specified DIB.
uStartScan
[in] Specifies the starting scan line for the device-independent color data in the array pointed to by the lpvBits parameter.
cScanLines
[in] Specifies the number of scan lines found in the array containing device-independent color data.
lpvBits
[in] Pointer to the DIB color data, stored as an array of bytes. The format of the bitmap values depends on the biBitCount member of the BITMAPINFO structure pointed to by the lpbmi parameter.
lpbmi
[in] Pointer to a BITMAPINFO structure that contains information about the DIB.
fuColorUse
[in] Specifies whether the bmiColors member of the BITMAPINFO structure was provided and, if so, whether bmiColors contains explicit red, green, blue (RGB) values or palette indexes. The fuColorUse parameter must be one of the following values. Value Meaning
DIB_PAL_COLORS The color table consists of an array of 16-bit indexes into the logical palette of the device context identified by the hdc parameter.
DIB_RGB_COLORS The color table is provided and contains literal RGB values.


Return Values
If the function succeeds, the return value is the number of scan lines copied.

If the function fails, the return value is zero.

Windows NT/ 2000: To get extended error information, call GetLastError. This can be the following value.

Value Meaning
ERROR_INVALID_PARAMETER One or more input parameters are invalid.


Remarks
Optimal bitmap drawing speed is obtained when the bitmap bits are indexes into the system palette.

Applications can retrieve the system palette colors and indexes by calling the GetSystemPaletteEntries function. After the colors and indexes are retrieved, the application can create the DIB. For more information, see System Palette.

The device context identified by the hdc parameter is used only if the DIB_PAL_COLORS constant is set for the fuColorUse parameter;
otherwise it is ignored.

The bitmap identified by the hbmp parameter must not be selected into a device context when the application calls this function.

The scan lines must be aligned on a DWORD except for RLE-compressed bitmaps.

The origin for bottom-up DIBs is the lower-left corner of the bitmap;
the origin for top-down DIBs is the upper-left corner of the bitmap.

ICM: Color management is performed. The color profile of the current device context is used as the source color space profile and the sRGB color space is used.

See Also
Bitmaps Overview, Bitmap Functions, GetDIBits, GetSystemPaletteEntries, BITMAPINFO
 
问题已经解决,是采用我自己的回调函数,还是很感谢cqbaobao的热情参与,分都给你好了,呵呵。
cqbaobao:你的回调函数转换格式还是不行,我在调用scanline方法时报越界错误!
 
后退
顶部