@ -96,7 +96,7 @@ void XimeaImager::openImger()
}
float gain , offset ; //用于生成头文件中的波长信息
ret = m_configfile . getGainOffsetOfSpectralBin1 ( gain , offset ) ;
ret = m_configfile . getGainOffset ( gain , offset ) ;
if ( ret )
{
m_imager . setGainOffset ( gain , offset ) ;
@ -509,25 +509,10 @@ double XimeaImager::geWavelengthAtBand(int x)
void XimeaImager : : getRgbBandNumber ( int & redBandNumber , int & greenBandNumber , int & blueBandNumber )
{
vector < double > wavelengths ;
if ( m_imager . getSpectralBin ( ) = = 1 )
{
for ( int i = getWindowStartBand ( ) ; i < getWindowEndBand ( ) ; i + + )
{
wavelengths . push_back ( geWavelengthAtBand ( i ) ) ;
}
}
else if ( m_imager . getSpectralBin ( ) = = 2 )
{
for ( int i = m_iOffsetyOfSpectralBin2 ; i < m_iOffsetyOfSpectralBin2 + m_iHeightOfSpectralBin2 ; i + + )
{
if ( i * 2 + 1 > m_iOffsetyOfSpectralBin1 + m_iHeightOfSpectralBin1 )
{
printf ( " XimeaImager::writeHdr 出现错误:窗口中,光谱 bin1 波段数小于 bin2 的 2 倍。 \n " ) ;
break ;
}
wavelengths . push_back ( ( geWavelengthAtBand ( i * 2 ) + geWavelengthAtBand ( i * 2 + 1 ) ) / 2 ) ;
}
}
//envi打开文件时的红绿蓝波长( nm)
int r_envi = 640 ;
@ -801,8 +786,6 @@ void XimeaImager::writeHdr()
hdrFileHandle < < " wavelength = { " ;
//hdrFileHandle << std::setprecision(5);
if ( m_imager . getSpectralBin ( ) = = 1 )
{
for ( int i = getWindowStartBand ( ) ; i < getWindowEndBand ( ) ; i + + )
{
hdrFileHandle < < geWavelengthAtBand ( i ) ;
@ -813,29 +796,6 @@ void XimeaImager::writeHdr()
printf ( " 头文件中写入了多少个波段:%d \n " , i - getWindowStartBand ( ) + 1 ) ; //???????????????
}
}
}
else if ( m_imager . getSpectralBin ( ) = = 2 )
{
int counter = 0 ;
for ( int i = m_iOffsetyOfSpectralBin2 ; i < m_iOffsetyOfSpectralBin2 + m_iHeightOfSpectralBin2 ; i + + )
{
if ( i * 2 + 1 > m_iOffsetyOfSpectralBin1 + m_iHeightOfSpectralBin1 )
{
printf ( " XimeaImager::writeHdr 出现错误:窗口中,光谱 bin1 波段数小于 bin2 的 2 倍。 \n " ) ;
break ;
}
hdrFileHandle < < ( geWavelengthAtBand ( i * 2 ) + geWavelengthAtBand ( i * 2 + 1 ) ) / 2 ;
counter + + ;
if ( i < m_iOffsetyOfSpectralBin2 + m_iHeightOfSpectralBin2 - 1 )
hdrFileHandle < < " , " ;
else
{
printf ( " 头文件中写入了多少个波段:%d \n " , counter ) ;
}
}
}
hdrFileHandle < < " } \n " ;
hdrFileHandle . close ( ) ;
@ -1232,8 +1192,8 @@ void PushFlow::encodePushFlow()
codecContext - > height = m_iHeight ;
codecContext - > time_base = { 1 , m_iFramerateVideo } ;
codecContext - > pix_fmt = AV_PIX_FMT_YUV420P ; // 设置为YUV420P格式
codecContext - > gop_size = 1 ; //多少帧产生一组关键帧
codecContext - > max_b_frames = 1 ; //b帧, 参考帧
codecContext - > gop_size = 50 ; //多少帧产生一组关键帧
codecContext - > max_b_frames = 0 ; //b帧, 参考帧: 设置为1会导致视频回退的现象
// codecContext->bit_rate = 1000000; // 设置比特率为 1000000
// 打开视频编码器
@ -1246,17 +1206,17 @@ void PushFlow::encodePushFlow()
}
// 打开输出文件
if ( avio_open( & formatContext- > pb , outputVideoPath, AVIO_FLAG_WRITE) < 0 )
{
qDebug( ) < < " Error: Failed to open output file" ;
avcodec_close( codecContext) ;
avcodec_free_context( & codecContext) ;
avformat_free_context( formatContext) ;
return;
}
// if ( avio_open(& formatContext->pb, outputVideoPath, AVIO_FLAG_WRITE) < 0)
// {
// qDebug() << " Error: Failed to open output file";
// avcodec_close( codecContext);
// avcodec_free_context(& codecContext);
// avformat_free_context( formatContext);
// return;
// }
// 写入文件头
avformat_write_header( formatContext, nullptr) ;
// avformat_write_header( formatContext, nullptr);
// 使用sws_scale进行颜色空间转换
SwsContext * swsContext = sws_getContext ( m_iWidth , m_iHeight , AV_PIX_FMT_BGR24 ,
@ -1345,7 +1305,7 @@ void PushFlow::encodePushFlow()
fclose ( fp ) ;
// 写入文件尾
av_write_trailer( formatContext) ;
// av_write_trailer( formatContext);
// 释放AVFrame和相关资源
av_freep ( & frame - > data [ 0 ] ) ;