如何将数组转换为视频并显示它 [英] how to convert an array into a video and show it

查看:103
本文介绍了如何将数组转换为视频并显示它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从TOF相机中获取一个浮点数组,我想以Windows形式显示它.

相机提供了很多数据.重要的是包含行和列数(以像素为单位)的描述符,最大值为200行X 200列.
相机会给出一些大小相同的浮点数组:距离,强度(灰度图像),幅度以及每个像素的x,y和z坐标.还有一个无符号数组,其中包含每个像素的标记.
用于构建图像的数组是"float Intensities [200 * 200]"(按行排序)(0-199首行,200-299第二行...).每个像素的值从0到32000不等,这是我用来生成图像的像素.
我已经将此数组转换为bmp,我使用的转换为bmp的函数为:

Hi I am getting a float array from a TOF camera and i want to show it in a windows form.

the camera gives a lot of data. the important ones are the descriptor who contains the number of rows and columns (in pixels) the max value is 200 row X 200 columns.
Them the camera gives some float arrays of same size: distance , intensities(gray scale image), amplitude, and x, y and z coordenates for each pixel. There is also an unsigned array who contains falgs of each pixel.
The array for building the image is a "float Intensities[200*200]" sort by rows (0-199 fist row , 200-299 second row ... ). the value of each pixel vary from 0 to 32000 and is the one I use to build the image.
I already convert this array to bmp, the function to convert to bmp I used is:

bool CameraClass::GreyImage(float *Array,float max,float min, int width, int height,LPCTSTR bmpfile){
	//Mediante la recta y=Ax+B donde x es un valor de Array
	//Variando min y max se logra modificar el contraste

	float B=min*255/(min-max);
	float A=(255-B)/max;


	//BYTE *Buffer;
	//Buffer= new BYTE [3*width*height];
	BYTE Buffer[3*200*200]; //deberia asignarse dinamicamente pero da error! 

	for (int i=0;i<height;i++){
		for(int j=0;j<width;j++){
		Buffer[3*(width*((height-1)-i)+j)]=(BYTE)(A*Array[width*i+j]+B);
		Buffer[3*(width*((height-1)-i)+j)+1]=(BYTE)(A*Array[width*i+j]+B);
		Buffer[3*(width*((height-1)-i)+j)+2]=(BYTE)(A*Array[width*i+j]+B);
		}
	}
	
	long paddedsize=width*height*3;

	// 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 );

	//delete [] Buffer;

	return true;
}//OK



它非常棒,但是现在我想显示视频以避免bmp,直接显示在视频窗口中.

最简单的方法是什么?
谢谢你的帮助! </b



Its warks great but now i want to show the data avoiding the bmp, Driectly to a video window.

what is the easiest way?
Thanks for your help! </b

推荐答案

最简单的方法是使用功能BitBlt.

MSDN上的BitBlt

更快的方法是使用OpenGL.这样您将享受到更高的帧速率和更少的处理器时间,但是学习曲线更高.

如果使用OpenGL,则将利用的技术是纹理贴图".

OpenGL纹理映射:简介

该示例中的肉是以下行:
The easiest way to do this is to use the function BitBlt.

BitBlt On MSDN

The faster way is to use OpenGL. You''ll enjoy higher frame rates with less processor time doing that, but the learning curve is higher.

If you use OpenGL, then the technology you''ll be leveraging is Texture Mapping.

OpenGL Texture Mapping: An Introduction

The meat in that sample is the line:
glTexImage2D (GL_TEXTURE_2D, 0, GL_RGB, imageWidth, imageHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, imageData);



元素GL_RGB是您要更改的元素,以反映24位,位图使用的BGR颜色映射.因此,如果您的编译器不喜欢第一个,则将GL_RGB更改为GL_BGR或GL_BGR_EXT.然后,您可以将代码中的缓冲区作为图像数据进行传递.

*********************

关于图像创建的一些注意事项...

您传递宽度和高度,然后硬编码缓冲区大小...
试试



The element GL_RGB is one you''ll want to change, to reflect the BGR color mapping that 24 bit, bitmaps use. So change the GL_RGB to GL_BGR or GL_BGR_EXT if your compiler doesn''t like the first one. Then you can pass the buffer in your code as the image data.

*********************

A couple of notes on your image creation...

You pass width and height, then hard code your buffer size...
Try

BYTE  * Buffer = new BYTE[3*Width*Height];


然后在功能结束之前...


Then before your function ends...

delete buffer;




还有......
您在像素代码中使用了很多乘法.

这样的事情执行起来会更快...




Also....
You use a lot of multiplies in your pixel code.

Something like this will execute faster...

for (int i=height-1;i>=0;i--)
{
    BYTE * pDestLine = Buffer + (i*width);

    for(int j=0;j<width;j++)>
    {
        *(pDestLine++) = (BYTE)(A*Array[width*i+j]+B);
        *(pDestLine++) = (BYTE)(A*Array[width*i+j]+B);
        *(pDestLine++) = (BYTE)(A*Array[width*i+j]+B);
    }
}



优化源数据访问,留给读者练习...



Optimizing the source data access, is left as an exercise for the reader...


在Borland c ++中,我使用BitMap-> Canvas-> Pixels [x] [y] = array将数组值转换为0到255之间的值后的[x] [y].这忽略了数据中可能包含的所有标头.我可以以高达740 x 576像素的图像以良好的帧频(60fps)显示图像数据.

我处理的某些文件格式是ARF,FTS和FITS.如果您愿意,我可以给您发送一些示例代码...

凯文
In Borland c++ I use BitMap->Canvas->Pixels[x][y] = array[x][y] after converting the array values to values between 0 and 255. This disregards any header(s) you may have in your data. I can display image data at good frame rates (60fps) with images up to 740 x 576 pixels.

Some file formats I deal with are ARF, FTS and FITS. I could send you some sample code if you like...

Kevin


这篇关于如何将数组转换为视频并显示它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆