将原始mono8数据转换为PNG时,加快PNG++的速度
Speed up PNG++ when converting raw mono8 data to PNG
我需要使用PNG++来执行相机缓冲区图像(在原始mono8数据中(到无PNG压缩文件的优化转换的帮助。下面的行得通,但太慢了。我将在ARM中执行它。我需要一个非常快速的过程。
sprintf(mBuffer, "%lu.png", pFrame->FrameCount);
try
{
//Take the image from my camera buffer and put it into vector i can
//work with
images = (const unsigned char*)pFrame->ImageBuffer;
//create the png profile to be used
png::image< png::gray_pixel > image(1024,1024);
//Take every byte from the vector and put in the determined position on
//the image matrix
for(int i=0;i<1024;i++)
{
for(int j=0;j<1024;j++)
{
png::gray_pixel pix = images[i*1024+j];
image[i][j] = pix;
}
}
image.write(mBuffer);
}
catch (std::exception const& error)
{
std::cerr << "Teste: " << error.what() << std::endl;
}
这可能有帮助,也可能没有帮助——这只是一个建议。如果您的帧缓冲区是8位无符号像素的顺序加载,则其格式与此处记录的P5类型的NetPBM Portable Greymap(PGM(完全相同。这可以写得很快,可以直接在网页中使用,也可以很容易地使用ImageMagick(此处(转换为png
,如下所示:
convert image.pgm image.png
然后你的图像写作可以很简单:
#include <stdio.h>
#include <stdlib.h>
#define HEIGHT 100
#define WIDTH 256
int main(){
FILE *imageFile;
uint8_t image[HEIGHT][WIDTH];
int x,y,pixel;
/* Create a greyscale ramp - you don't need this, you would use your framebuffer */
for(x=0;x<HEIGHT;x++){
for(y=0;y<WIDTH;y++){
image[x][y]=y;
}
}
/* Now write to a file */
imageFile=fopen("image.pgm","wb");
if(imageFile==NULL){
perror("ERROR: Cannot open output file");
exit(EXIT_FAILURE);
}
/* You could coalesce the next 3 lines into a single fprintf() if you wanted */
fprintf(imageFile,"P5n"); // P5 filetype
fprintf(imageFile,"%d %dn",WIDTH,HEIGHT); // dimensions
fprintf(imageFile,"255n"); // Max pixel
fwrite(image,HEIGHT,WIDTH,imageFile);
fclose(imageFile);
}
根据您实际想要对图像进行的处理,您可以在完成高速采集运行后对其进行批量转换,或者稍后在后台进行转换,或者完全在另一台机器上的其他地方进行转换。
在我的例子中,我创建了图像,但你已经在帧缓冲区中有了你的图像,所以你的图像写作将变成:
imageFile=fopen("image.pgm","wb");
fprintf(imageFile,"P5n%d %dn255n",WIDTH,HEIGHT);
fwrite(images,HEIGHT,WIDTH,imageFile);
close(imageFile);
相关文章:
- 在CToolBar对象中使用PNG时出现问题
- 从存储为 Windows 资源 (c++) 的 png 中获取 png 文件数据
- 使用 stbi_write_png,如何将 0 和 1 的矩形字节数组转换为单色 png 文件?
- 加快在C++中读取/处理日志文件的速度
- 如何加快本征C++中的LU分解?
- 如何加快大字符串的解析速度?
- 使用 Unity 构建加快C++构建速度,并减少标头依赖项
- 将 FFMPEG 帧写入 png/jpeg 文件
- 将位图 (bmp) 转换为具有透明度的 png (Windows c++)
- 重新执行C++程序会加快速度
- 如何启用libMagick++以保存.png文件格式
- Qt-png图像未显示在部署应用程序中
- 无法在CLion(macOS)上打开带有CImg的.png文件
- 加快一个长python代码的速度,因为只有一个块,所以速度很慢
- C++gdi::内存中的位图到PNG图像
- 将浮点数转换为字符串时如何加快此代码的速度?
- 当我调用它来解码 Blob 对象中的 png 图像时,"Magick++::readImages"引发警告
- 如何将 2d 数组转换为 svg 或 png 格式的数独图像?
- GUID variable for JPEG,BMP,PNG
- 将原始mono8数据转换为PNG时,加快PNG++的速度