Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何在Intel RealSense(Visual C+;+;)中保存映像_C++_Visual Studio 2012_Realsense - Fatal编程技术网

C++ 如何在Intel RealSense(Visual C+;+;)中保存映像

C++ 如何在Intel RealSense(Visual C+;+;)中保存映像,c++,visual-studio-2012,realsense,C++,Visual Studio 2012,Realsense,我正在开发Intel RealSense SDK(R2)。我想从Camera_viewer保存图像。我一直工作到将帧保存到特定缓冲区并从中检索。我想知道如何将这些帧/图像保存到指定的位置/文件夹 这是我的密码: PXCImage *colorIm, *depthIm; for (int i=0; i<MAX_FRAMES; i++) { // This function blocks until all streams are ready (depth and color)

我正在开发Intel RealSense SDK(R2)。我想从Camera_viewer保存图像。我一直工作到将帧保存到特定缓冲区并从中检索。我想知道如何将这些帧/图像保存到指定的位置/文件夹

这是我的密码:

PXCImage *colorIm, *depthIm;
for (int i=0; i<MAX_FRAMES; i++) {

    // This function blocks until all streams are ready (depth and color)
    // if false streams will be unaligned
    if (psm->AcquireFrame(true)<PXC_STATUS_NO_ERROR) break; 

    // retrieve all available image samples
    PXCCapture::Sample *sample = psm->QuerySample();

    // retrieve the image or frame by type from the sample
    colorIm = sample->color;
    depthIm = sample->depth;

    // render the frame
    if (!renderColor->RenderFrame(colorIm)) break;
    if (!renderDepth->RenderFrame(depthIm)) break;

    // release or unlock the current frame to fetch the next frame
    psm->ReleaseFrame();
}
PXCImage*colorIm,*depthIm;
对于(int i=0;iAcquireFrame(true)QuerySample();
//从示例中按类型检索图像或帧
colorIm=样本->颜色;
深度=样品->深度;
//渲染帧
如果(!renderColor->RenderFrame(colorIm))中断;
如果(!renderDepth->RenderFrame(depthIm))中断;
//释放或解锁当前帧以获取下一帧
psm->释放框架();
}
我能够成功地检索帧/图像,但我想保存这些文件以供进一步使用。因此,我想知道如何将这些文件保存到文件夹中

提前感谢

提出了相同的问题,发布的答案解决了最初的问题。但是,还有一个关于如何将图像保存到特定文件夹的后续问题


如果您有这个特定的问题,那么答案将是相同的
SetFileName()
仅限。根据,
pxcCHAR*文件是要播放或要录制的文件的完整路径。
。也就是说,您可以创建一个自定义文件夹,并将路径指向该
自定义文件夹,后跟一个有效的文件名以保存图像。

要保存数据,我将根据图像数据创建一个位图,如下所示:dSO说并使用来自的代码保存它-

#include <windows.h>
#include <stdio.h>       // for memset

bool SaveBMP ( BYTE* Buffer, int width, int height, long paddedsize, LPCTSTR bmpfile )
{
    // declare bmp structures 
    BITMAPFILEHEADER bmfh;
    BITMAPINFOHEADER info;

    // andinitialize them to zero
    memset ( &bmfh, 0, sizeof (BITMAPFILEHEADER ) );
    memset ( &info, 0, sizeof (BITMAPINFOHEADER ) );

    // fill the fileheader with data
    bmfh.bfType = 0x4d42;       // 0x4d42 = 'BM'
    bmfh.bfReserved1 = 0;
    bmfh.bfReserved2 = 0;
    bmfh.bfSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + paddedsize;
    bmfh.bfOffBits = 0x36;      // number of bytes to start of bitmap bits

    // fill the infoheader

    info.biSize = sizeof(BITMAPINFOHEADER);
    info.biWidth = width;
    info.biHeight = height;
    info.biPlanes = 1;          // we only have one bitplane
    info.biBitCount = 24;       // RGB mode is 24 bits
    info.biCompression = BI_RGB;    
    info.biSizeImage = 0;       // can be 0 for 24 bit images
    info.biXPelsPerMeter = 0x0ec4;     // paint and PSP use this values
    info.biYPelsPerMeter = 0x0ec4;     
    info.biClrUsed = 0;         // we are in RGB mode and have no palette
    info.biClrImportant = 0;    // all colors are important

    // now we open the file to write to
    HANDLE file = CreateFile ( bmpfile , GENERIC_WRITE, FILE_SHARE_READ,
         NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
    if ( file == NULL )
    {
        CloseHandle ( file );
        return false;
    }

    // write file header
    unsigned long bwritten;
    if ( WriteFile ( file, &bmfh, sizeof ( BITMAPFILEHEADER ), &bwritten, NULL ) == false )
    {   
        CloseHandle ( file );
        return false;
    }
    // write infoheader
    if ( WriteFile ( file, &info, sizeof ( BITMAPINFOHEADER ), &bwritten, NULL ) == false )
    {   
        CloseHandle ( file );
        return false;
    }
    // write image data
    if ( WriteFile ( file, Buffer, paddedsize, &bwritten, NULL ) == false )
    {   
        CloseHandle ( file );
        return false;
    }

    // and close file
    CloseHandle ( file );

    return true;
}
使用这三组代码,您应该能够轻松地使用WriteFile将位图保存在任何指定的文件夹中,然后,一旦加载,您就可以将位图转换回ImageData


让我知道它是如何运行的。

你能解决你的问题吗?这个问题的答案在上。简而言之:使用
PXCImage::AcquireAccess()
获取图像数据,然后用该数据设置(例如)一个
Gdiplus::Bitmap
实例,并将其保存到磁盘。你如何加载外部图像(BMP、JPG、PNG等)进入PXCImage?看起来很好!我可以看出你在这方面做得很好:D,你能帮我一下吗?恐怕我没有使用英特尔图像处理套件,所以我只能引用其他人编写的代码。步骤应该是1.使用最终链接中的PXCImage工具转换为位图2.一旦你有了位图rmat使用runicsoft方法将其保存到所需的文件中。(作为位图,其他程序也可以访问它)3.以后您可以使用第二个runicsoft代码将其加载回。4.使用引用的Intel代码将位图数据加载回ImageInfo。我希望能提供更多帮助!这是我第一次听说runicsoft方法。您有关于该方法的链接吗?谢谢!它将在任何可以打开文本文件的浏览器中打开。@Alexan你写了一些有用的东西吗?我看到这个问题受到了积极的关注,我敢打赌很多人都很想看到你最终完成的产品。
/*******************************************************************
BYTE* LoadBMP ( int* width, int* height, long* size 
        LPCTSTR bmpfile )

The function loads a 24 bit bitmap from bmpfile, 
stores it's width and height in the supplied variables
and the whole size of the data (padded) in <size>
and returns a buffer of the image data 

On error the return value is NULL. 

  NOTE: make sure you [] delete the returned array at end of 
        program!!!
*******************************************************************/

BYTE* LoadBMP ( int* width, int* height, long* size, LPCTSTR bmpfile )
{
    // declare bitmap structures
    BITMAPFILEHEADER bmpheader;
    BITMAPINFOHEADER bmpinfo;
    // value to be used in ReadFile funcs
    DWORD bytesread;
    // open file to read from
    HANDLE file = CreateFile ( bmpfile , GENERIC_READ, FILE_SHARE_READ,
         NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL );
    if ( NULL == file )
        return NULL; // coudn't open file


    // read file header
    if ( ReadFile ( file, &bmpheader, sizeof ( BITMAPFILEHEADER ), &bytesread, NULL ) == false )
    {
        CloseHandle ( file );
        return NULL;
    }

    //read bitmap info

    if ( ReadFile ( file, &bmpinfo, sizeof ( BITMAPINFOHEADER ), &bytesread, NULL ) == false )
    {
        CloseHandle ( file );
        return NULL;
    }

    // check if file is actually a bmp
    if ( bmpheader.bfType != 'MB' )
    {
        CloseHandle ( file );
        return NULL;
    }

    // get image measurements
    *width   = bmpinfo.biWidth;
    *height  = abs ( bmpinfo.biHeight );

    // check if bmp is uncompressed
    if ( bmpinfo.biCompression != BI_RGB )
    {
        CloseHandle ( file );
        return NULL;
    }

    // check if we have 24 bit bmp
    if ( bmpinfo.biBitCount != 24 )
    {
        CloseHandle ( file );
        return NULL;
    }


    // create buffer to hold the data
    *size = bmpheader.bfSize - bmpheader.bfOffBits;
    BYTE* Buffer = new BYTE[ *size ];
    // move file pointer to start of bitmap data
    SetFilePointer ( file, bmpheader.bfOffBits, NULL, FILE_BEGIN );
    // read bmp data
    if ( ReadFile ( file, Buffer, *size, &bytesread, NULL ) == false )
    {
        delete [] Buffer;
        CloseHandle ( file );
        return NULL;
    }

    // everything successful here: close file and return buffer

    CloseHandle ( file );

    return Buffer;
}
// Image info
PXCImage::ImageInfo info={};
info.format=PXCImage::PIXEL_FORMAT_RGB32;
info.width=image_width;
info.height=image_height;

// Create the image instance
PXCImage image=session->CreateImage(&info);

// Write data
PXCImage::ImageData data;
image->AcquireAccess(PXCImage::ACCESS_WRITE,&data);
... // copy the imported image to data.planes[0]
image->ReleaseAccess(&data);