@ -597,6 +597,7 @@ bool argusModuleEmbedVideo::reloadSettings(){
} ;
bool argusModuleEmbedVideo : : validate ( ) {
return true ;
} ;
@ -614,9 +615,6 @@ void argusModuleEmbedVideo::pushFrame( cv::Mat &Frame, void* src ){
cv : : Rect ROI ;
//if( !m_mPictureProtector.try_lock() ) return;
m_mPictureProtector . lock ( ) ;
oK = ( ( float ) m_sEmbedVideoData . height ) / ( ( float ) m_sEmbedVideoData . width ) ;
mK = ( ( float ) Frame . rows ) / ( ( float ) Frame . cols ) ;
//sprintf( tBuffer, "INP: [%dx%d] IK:%0.3f OK:%0.3f", Frame.cols, Frame.rows, mK, oK );
if ( m_mapMATS [ tMD - > mediaStreamId ] . cols = = 0 ) {
LOG ( " First Frame Enqueued " ) ;
sprintf ( tBuffer , " INP: [%dx%d] SrcID:%d StreamID:%d " , Frame . cols , Frame . rows , tMD - > mediaSourceId , tMD - > mediaStreamId ) ;
@ -625,6 +623,10 @@ void argusModuleEmbedVideo::pushFrame( cv::Mat &Frame, void* src ){
m_mapMATS [ tMD - > mediaStreamId ] . create ( m_sEmbedVideoData . height , m_sEmbedVideoData . width , CV_8UC3 ) ;
cv : : rectangle ( m_mapMATS [ tMD - > mediaStreamId ] , cv : : Point ( 0 , 0 ) , cv : : Point ( m_sEmbedVideoData . height , m_sEmbedVideoData . width ) , cv : : Scalar ( 0 , 0 , 0 ) , cv : : FILLED ) ;
} ;
# ifdef USE_SCALING_IN
oK = ( ( float ) m_sEmbedVideoData . height ) / ( ( float ) m_sEmbedVideoData . width ) ;
mK = ( ( float ) Frame . rows ) / ( ( float ) Frame . cols ) ;
//sprintf( tBuffer, "INP: [%dx%d] IK:%0.3f OK:%0.3f", Frame.cols, Frame.rows, mK, oK );
if ( ( fabsf ( mK - oK ) < 0.1f ) | | ( fabsf ( oK - mK ) < 0.1f ) ) {
ROI . width = ( int ) m_sEmbedVideoData . width ;
ROI . height = ( int ) m_sEmbedVideoData . height ;
@ -642,32 +644,126 @@ void argusModuleEmbedVideo::pushFrame( cv::Mat &Frame, void* src ){
ROI . y = ( int ) 0 ;
ROI . x = ( int ) ( m_sEmbedVideoData . width - ROI . width ) > > 1 ;
} ;
}
} ;
cv : : Mat mROI = m_mapMATS [ tMD - > mediaStreamId ] ( ROI ) ;
cv : : resize ( Frame , mROI , mROI . size ( ) , 0 , 0 , cv : : INTER_LINEAR ) ;
/*
cv : : putText ( m_mapMATS [ tMD - > mediaStreamId ] , tBuffer , cv : : Point ( 30 , 45 ) ,
( cv : : HersheyFonts ) m_sEmbedVideoData . ts_font_face ,
m_sEmbedVideoData . ts_font_scale , cv : : Scalar ( 0 , 255 , 255 ) ,
m_sEmbedVideoData . ts_font_thickness ,
m_sEmbedVideoData . ts_line_type
) ;
*/
if ( m_sEmbedVideoData . show_ts ) {
char DateStr [ 200 ] ;
# else
if ( ( m_sEmbedVideoData . height = = Frame . rows ) & & ( m_sEmbedVideoData . width = = Frame . cols ) ) {
Frame . copyTo ( m_mapMATS [ tMD - > mediaStreamId ] ) ;
} else {
if ( m_sEmbedVideoData . height < Frame . rows ) {
ROI . x = 0 ;
ROI . width = m_sEmbedVideoData . width ;
ROI . y = ( Frame . rows - m_sEmbedVideoData . height ) > > 1 ;
ROI . height = m_sEmbedVideoData . height ;
cv : : Mat mROI = Frame ( ROI ) ;
mROI . copyTo ( m_mapMATS [ tMD - > mediaStreamId ] ) ;
} else {
ROI . x = 0 ;
ROI . width = m_sEmbedVideoData . width ;
ROI . y = ( m_sEmbedVideoData . height - Frame . rows ) > > 1 ;
ROI . height = Frame . rows ;
cv : : Mat mROI = m_mapMATS [ tMD - > mediaStreamId ] ( ROI ) ;
Frame . copyTo ( mROI ) ;
} ;
} ;
# endif
if ( m_sEmbedVideoData . show_label ) {
time_t t = time ( NULL ) ;
struct tm * tmp = gmtime ( & t ) ;
if ( tmp ) {
if ( strftime ( DateStr , sizeof ( DateStr ) , " %F %T GMT " , tmp ) ! = 0 ) {
cv : : rectangle ( m_mapMATS [ tMD - > mediaStreamId ] , cv : : Point ( 10 , 10 ) , cv : : Point ( 490 , 60 ) , cv : : Scalar ( 0 , 0 , 0 ) , cv : : FILLED ) ;
cv : : putText ( m_mapMATS [ tMD - > mediaStreamId ] , DateStr , cv : : Point ( 30 , 45 ) ,
( cv : : HersheyFonts ) m_sEmbedVideoData . ts_font_face ,
m_sEmbedVideoData . ts_font_scale , cv : : Scalar ( 0 , 255 , 255 ) ,
m_sEmbedVideoData . ts_font_thickness ,
m_sEmbedVideoData . ts_line_type
char tsb [ 64 ] ;
if ( strftime ( tsb , sizeof ( tsb ) , " %F %T GMT " , tmp ) ! = 0 ) {
sprintf ( tBuffer , " >>%d>%d>%s>%s> " , tMD - > mediaSourceId , tMD - > mediaStreamId , tMD - > mediaName , tsb ) ;
int baseline = 0 ;
cv : : Size textSize = cv : : getTextSize ( tBuffer ,
m_sEmbedVideoData . label_font_face ,
m_sEmbedVideoData . label_font_scale ,
m_sEmbedVideoData . label_font_thickness ,
& baseline
) ;
int x = m_sEmbedVideoData . label_x ;
int y = m_sEmbedVideoData . label_y ;
if ( x < 0 ) {
x = m_sEmbedVideoData . width + x - textSize . width ;
} ;
if ( y < 0 ) {
y = m_sEmbedVideoData . height + y - baseline ; //
} ;
if ( ! m_sEmbedVideoData . label_transperant ) {
cv : : rectangle ( m_mapMATS [ tMD - > mediaStreamId ] , cv : : Rect ( x , y - textSize . height - 4 , textSize . width , textSize . height + baseline + 4 ) , cv : : Scalar ( 0 , 0 , 0 ) , cv : : FILLED ) ;
} ;
cv : : putText ( m_mapMATS [ tMD - > mediaStreamId ] , tBuffer , cv : : Point ( x , y ) ,
( cv : : HersheyFonts ) m_sEmbedVideoData . label_font_face ,
m_sEmbedVideoData . label_font_scale , cv : : Scalar ( 0 , 255 , 0 ) ,
m_sEmbedVideoData . label_font_thickness ,
m_sEmbedVideoData . label_line_type
) ;
} ;
} ;
} else {
if ( m_sEmbedVideoData . show_ts ) {
time_t t = time ( NULL ) ;
struct tm * tmp = gmtime ( & t ) ;
if ( tmp ) {
if ( strftime ( tBuffer , sizeof ( tBuffer ) , " %F %T GMT " , tmp ) ! = 0 ) {
uint8_t shift_x = 0 ;
uint8_t shift_y = 15 ;
if ( ! m_sEmbedVideoData . ts_transperant ) {
if ( m_sEmbedVideoData . ts_font_face ) {
shift_y = 15 ;
cv : : rectangle ( m_mapMATS [ tMD - > mediaStreamId ] , cv : : Point ( m_sEmbedVideoData . ts_x , m_sEmbedVideoData . ts_y ) , cv : : Point ( 490 , 60 ) , cv : : Scalar ( 0 , 0 , 0 ) , cv : : FILLED ) ;
} else {
shift_y = 23 ;
cv : : rectangle ( m_mapMATS [ tMD - > mediaStreamId ] , cv : : Point ( m_sEmbedVideoData . ts_x , m_sEmbedVideoData . ts_y ) , cv : : Point ( 490 , 60 ) , cv : : Scalar ( 0 , 0 , 0 ) , cv : : FILLED ) ;
} ;
cv : : putText ( m_mapMATS [ tMD - > mediaStreamId ] , tBuffer , cv : : Point ( m_sEmbedVideoData . ts_x + shift_x , m_sEmbedVideoData . ts_y + shift_y ) ,
( cv : : HersheyFonts ) m_sEmbedVideoData . ts_font_face ,
m_sEmbedVideoData . ts_font_scale , cv : : Scalar ( 0 , 255 , 255 ) ,
m_sEmbedVideoData . ts_font_thickness ,
m_sEmbedVideoData . ts_line_type
) ;
} else {
if ( m_sEmbedVideoData . ts_font_face ) {
shift_y = 15 ;
} else {
shift_y = 23 ;
} ;
cv : : putText ( m_mapMATS [ tMD - > mediaStreamId ] , tBuffer , cv : : Point ( m_sEmbedVideoData . ts_x + shift_x - 1 , m_sEmbedVideoData . ts_y + shift_y - 1 ) ,
( cv : : HersheyFonts ) m_sEmbedVideoData . ts_font_face ,
m_sEmbedVideoData . ts_font_scale , cv : : Scalar ( 0 , 0 , 0 ) ,
m_sEmbedVideoData . ts_font_thickness ,
m_sEmbedVideoData . ts_line_type
) ;
cv : : putText ( m_mapMATS [ tMD - > mediaStreamId ] , tBuffer , cv : : Point ( m_sEmbedVideoData . ts_x + shift_x + 1 , m_sEmbedVideoData . ts_y + shift_y - 1 ) ,
( cv : : HersheyFonts ) m_sEmbedVideoData . ts_font_face ,
m_sEmbedVideoData . ts_font_scale , cv : : Scalar ( 0 , 0 , 0 ) ,
m_sEmbedVideoData . ts_font_thickness ,
m_sEmbedVideoData . ts_line_type
) ;
cv : : putText ( m_mapMATS [ tMD - > mediaStreamId ] , tBuffer , cv : : Point ( m_sEmbedVideoData . ts_x + shift_x - 1 , m_sEmbedVideoData . ts_y + shift_y + 1 ) ,
( cv : : HersheyFonts ) m_sEmbedVideoData . ts_font_face ,
m_sEmbedVideoData . ts_font_scale , cv : : Scalar ( 0 , 0 , 0 ) ,
m_sEmbedVideoData . ts_font_thickness ,
m_sEmbedVideoData . ts_line_type
) ;
cv : : putText ( m_mapMATS [ tMD - > mediaStreamId ] , tBuffer , cv : : Point ( m_sEmbedVideoData . ts_x + shift_x - 1 , m_sEmbedVideoData . ts_y + shift_y + 2 ) ,
( cv : : HersheyFonts ) m_sEmbedVideoData . ts_font_face ,
m_sEmbedVideoData . ts_font_scale , cv : : Scalar ( 0 , 0 , 0 ) ,
m_sEmbedVideoData . ts_font_thickness ,
m_sEmbedVideoData . ts_line_type
) ;
cv : : putText ( m_mapMATS [ tMD - > mediaStreamId ] , tBuffer , cv : : Point ( m_sEmbedVideoData . ts_x + shift_x , m_sEmbedVideoData . ts_y + shift_y ) ,
( cv : : HersheyFonts ) m_sEmbedVideoData . ts_font_face ,
m_sEmbedVideoData . ts_font_scale , cv : : Scalar ( 0 , 255 , 255 ) ,
m_sEmbedVideoData . ts_font_thickness ,
m_sEmbedVideoData . ts_line_type
) ;
}
} ;
} ;
} ;
} ;
if ( m_sEmbedVideoData . show_logo ) {
cv : : Rect roi ( cv : : Point ( m_sEmbedVideoData . logo_x , m_sEmbedVideoData . logo_y ) , cv : : Size ( m_sEmbedVideoData . logo_w , m_sEmbedVideoData . logo_h ) ) ;
@ -683,9 +779,13 @@ void argusModuleEmbedVideo::pushFrame( cv::Mat &Frame, void* src ){
//vector<uchar> buf;
uint32_t DataSize ;
//m_mPictureProtector.lock();
m_mEncodedProtector . lock ( ) ;
m_mapCAPTURES [ tMD - > mediaStreamId ] . clear ( ) ;
cv : : imencode ( " .jpg " , m_mapMATS [ tMD - > mediaStreamId ] , m_mapCAPTURES [ tMD - > mediaStreamId ] , compression_params ) ;
m_mEncodedProtector . unlock ( ) ;
/*ToDo: Move Broadcast Pic From Push Frame Procedure */
DataSize = m_mapCAPTURES [ tMD - > mediaStreamId ] . size ( ) ; //buf.size();
if ( DataSize ) {
uint8_t * pData = m_mapCAPTURES [ tMD - > mediaStreamId ] . data ( ) ; //buf.data();
if ( m_vHandlersPool . size ( ) ) {
@ -763,6 +863,19 @@ bool argusModuleEmbedVideo::saveStreamPicture( uint32_t id, CSTR *MD5 ){
} ;
return false ;
} ;
int argusModuleEmbedVideo : : getWidh ( void ) {
if ( m_sEmbedVideoData . width ) {
return m_sEmbedVideoData . width ;
} ;
return - 1 ;
} ;
int argusModuleEmbedVideo : : getHeight ( void ) {
if ( m_sEmbedVideoData . height ) {
return m_sEmbedVideoData . height ;
} ;
return - 1 ;
} ;
# undef LOG
# undef LOG_ERROR