本文介绍了C ++ VIDEOHDR到capVideoStreamCallback中的图像文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在研究网络摄像机录像机,但是我对这个主题的所有内容感兴趣,但是这个问题我无法解决。



你可能想知道的一切都可以在这里找到此处



现在,在此代码中

I've been working on a Webcam video recorder and I got interested in trying everything when it comes to this topic but there's this problem that I can't solve.

Everything that you might wonder about can be found here https://msdn.microsoft.com/en-us/library/windows/desktop/dd757677%28v=vs.85%29.aspx and here https://msdn.microsoft.com/en-us/library/windows/desktop/dd757694%28v=vs.85%29.aspx

Now, in this code

if (capSetCallbackOnVideoStream(hCapWnd, capVideoStreamCallback))
{
    capCaptureSequenceNoFile(hCapWnd); //Capture
}



我确保捕获的每个帧都被发送到capVideoStreamCallback。



现在我要做的是将帧转换为图像和把它保存到某个地方,这可能没用,但它很有意思,肯定是可能的。




这是我的capVideoStreamCallback函数(已注释):


I make sure that every frame that gets captured is sent to capVideoStreamCallback.

Now what I'm trying to do is transform a frame to an image and save it somewhere, this might be useless but it's interesting and it is surely possible.


Here is my capVideoStreamCallback function (it's commented):

LRESULT CALLBACK capVideoStreamCallback(HWND hWnd, LPVIDEOHDR lpVHdr)
{
    BYTE *Image;
    BITMAPINFO * TempBitmapInfo = new BITMAPINFO;
    ULONG Size;

    // First we need to get the full size of the image
    Size = capGetVideoFormat(hWnd, TempBitmapInfo, sizeof(BITMAPINFO)); //header size
    Size += lpVHdr->dwBytesUsed; //bytes used

    Image = new BYTE[Size];
    memcpy(Image, TempBitmapInfo, sizeof(BITMAPINFO)); //copy the header to Image

    // lpVHdr is LPVIDEOHER passed into callback function.
    memcpy(Image + sizeof(BITMAPINFO), lpVHdr->lpData, lpVHdr->dwBytesUsed); //copy the data to Image

    //write the image
    ofstream output("image.dib", ios::binary);
    output.write((char*)Image, Size);
    output.close();

    return (LRESULT)TRUE;
}



因此,有关发送到capVideoStreamCallback的每一帧的信息都可以在lpVHdr中找到,这是一个结构()我在这里要做的就是获取信息并将其转换为图像。



我首先通过检索标题的大小和数据的大小来获取图像的完整大小,然后我动态地声明一个名为Image的BYTE数组,并使用memcpy将标题和数据复制到Image。我最后使用ofstream将字节写入文件,这就是它。



问题是一切正常但图像却以某种方式损坏了因为它无法打开。



我在做什么有什么问题?这似乎是合乎逻辑的,但它不起作用。请分享您的想法并感谢您阅读。


So, the information about every frame that gets sent to capVideoStreamCallback can be found in lpVHdr which is a structure (https://msdn.microsoft.com/en-us/library/windows/desktop/dd757688%28v=vs.85%29.aspx) and what I'm trying to do here is to take that information and transform it to an image.

I first start by getting the full size of the image by retrieving the size of the header and the size of the data and then I dynamically declared a BYTE Array called Image and copied the header and the data to Image using memcpy. I finally used ofstream to write the bytes to a file and that's pretty much it.

The problem is that everything works just fine but the image is somehow corrupted because it cannot be opened.

What is wrong in what I'm doing? It seems so logical but it's not working. Please share your ideas and thanks for reading.

推荐答案


这篇关于C ++ VIDEOHDR到capVideoStreamCallback中的图像文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 01:59