@ -86,8 +86,8 @@ extern "C" {
// ====================================================================
// ====================================================================
image mat_to_image ( cv : : Mat mat ) ;
image mat_to_image ( cv : : Mat mat ) ;
cv : : Mat image_to_mat ( image img ) ;
cv : : Mat image_to_mat ( image img ) ;
image ipl_to_image ( mat_cv * src ) ;
// image ipl_to_image(mat_cv* src);
mat_cv * image_to_ipl ( image img ) ;
// mat_cv *image_to_ipl(image img);
// cv::Mat ipl_to_mat(IplImage *ipl);
// cv::Mat ipl_to_mat(IplImage *ipl);
// IplImage *mat_to_ipl(cv::Mat mat);
// IplImage *mat_to_ipl(cv::Mat mat);
@ -850,6 +850,7 @@ void save_cv_jpg(mat_cv *img_src, const char *name)
// ====================================================================
// ====================================================================
void draw_detections_cv_v3 ( mat_cv * mat , detection * dets , int num , float thresh , char * * names , image * * alphabet , int classes , int ext_output )
void draw_detections_cv_v3 ( mat_cv * mat , detection * dets , int num , float thresh , char * * names , image * * alphabet , int classes , int ext_output )
{
{
try {
cv : : Mat * show_img = mat ;
cv : : Mat * show_img = mat ;
int i , j ;
int i , j ;
if ( ! show_img ) return ;
if ( ! show_img ) return ;
@ -866,7 +867,7 @@ void draw_detections_cv_v3(mat_cv* mat, detection *dets, int num, float thresh,
strcat ( labelstr , names [ j ] ) ;
strcat ( labelstr , names [ j ] ) ;
class_id = j ;
class_id = j ;
char buff [ 10 ] ;
char buff [ 10 ] ;
sprintf ( buff , " (%2.0f%%) " , dets [ i ] . prob [ j ] * 100 ) ;
sprintf ( buff , " (%2.0f%%) " , dets [ i ] . prob [ j ] * 100 ) ;
strcat ( labelstr , buff ) ;
strcat ( labelstr , buff ) ;
}
}
else {
else {
@ -933,7 +934,7 @@ void draw_detections_cv_v3(mat_cv* mat, detection *dets, int num, float thresh,
pt_text . x = left ;
pt_text . x = left ;
pt_text . y = top - 4 ; // 12;
pt_text . y = top - 4 ; // 12;
pt_text_bg1 . x = left ;
pt_text_bg1 . x = left ;
pt_text_bg1 . y = top - ( 1 + 18 * font_size ) ;
pt_text_bg1 . y = top - ( 3 + 18 * font_size ) ;
pt_text_bg2 . x = right ;
pt_text_bg2 . x = right ;
if ( ( right - left ) < text_size . width ) pt_text_bg2 . x = left + text_size . width ;
if ( ( right - left ) < text_size . width ) pt_text_bg2 . x = left + text_size . width ;
pt_text_bg2 . y = top ;
pt_text_bg2 . y = top ;
@ -968,14 +969,18 @@ void draw_detections_cv_v3(mat_cv* mat, detection *dets, int num, float thresh,
cv : : rectangle ( * show_img , pt_text_bg1 , pt_text_bg2 , color , width , 8 , 0 ) ;
cv : : rectangle ( * show_img , pt_text_bg1 , pt_text_bg2 , color , width , 8 , 0 ) ;
cv : : rectangle ( * show_img , pt_text_bg1 , pt_text_bg2 , color , CV_FILLED , 8 , 0 ) ; // filled
cv : : rectangle ( * show_img , pt_text_bg1 , pt_text_bg2 , color , CV_FILLED , 8 , 0 ) ; // filled
cv : : Scalar black_color = CV_RGB ( 0 , 0 , 0 ) ;
cv : : Scalar black_color = CV_RGB ( 0 , 0 , 0 ) ;
cv : : putText ( * show_img , labelstr , pt_text , cv : : FONT_HERSHEY_COMPLEX_SMALL , font_size , black_color , 2 * font_size , CV_AA ) ;
cv : : putText ( * show_img , labelstr , pt_text , cv : : FONT_HERSHEY_COMPLEX_SMALL , font_size , black_color , 2 * font_size , CV_AA ) ;
// cv::FONT_HERSHEY_COMPLEX_SMALL, cv::FONT_HERSHEY_SIMPLEX
// cv::FONT_HERSHEY_COMPLEX_SMALL, cv::FONT_HERSHEY_SIMPLEX
}
}
}
}
if ( ext_output ) {
if ( ext_output ) {
fflush ( stdout ) ;
fflush ( stdout ) ;
}
}
}
catch ( . . . ) {
cerr < < " OpenCV exception: draw_detections_cv_v3() \n " ;
}
}
}
// ----------------------------------------
// ----------------------------------------
@ -984,22 +989,23 @@ void draw_detections_cv_v3(mat_cv* mat, detection *dets, int num, float thresh,
// ====================================================================
// ====================================================================
mat_cv * draw_train_chart ( float max_img_loss , int max_batches , int number_of_lines , int img_size , int dont_show )
mat_cv * draw_train_chart ( float max_img_loss , int max_batches , int number_of_lines , int img_size , int dont_show )
{
{
int img_offset = 5 0;
int img_offset = 6 0;
int draw_size = img_size - img_offset ;
int draw_size = img_size - img_offset ;
cv : : Mat * img_ptr = new cv : : Mat ( img_size , img_size , CV_8UC3 , CV_RGB ( 255 , 255 , 255 ) ) ;
cv : : Mat * img_ptr = new cv : : Mat ( img_size , img_size , CV_8UC3 , CV_RGB ( 255 , 255 , 255 ) ) ;
cv : : Mat & img = * img_ptr ;
cv : : Mat & img = * img_ptr ;
cv : : Point pt1 , pt2 , pt_text ;
cv : : Point pt1 , pt2 , pt_text ;
try {
char char_buff [ 100 ] ;
char char_buff [ 100 ] ;
int i ;
int i ;
// vertical lines
// vertical lines
pt1 . x = img_offset ; pt2 . x = img_size , pt_text . x = 1 0;
pt1 . x = img_offset ; pt2 . x = img_size , pt_text . x = 3 0;
for ( i = 1 ; i < = number_of_lines ; + + i ) {
for ( i = 1 ; i < = number_of_lines ; + + i ) {
pt1 . y = pt2 . y = ( float ) i * draw_size / number_of_lines ;
pt1 . y = pt2 . y = ( float ) i * draw_size / number_of_lines ;
cv : : line ( img , pt1 , pt2 , CV_RGB ( 224 , 224 , 224 ) , 1 , 8 , 0 ) ;
cv : : line ( img , pt1 , pt2 , CV_RGB ( 224 , 224 , 224 ) , 1 , 8 , 0 ) ;
if ( i % 10 = = 0 ) {
if ( i % 10 = = 0 ) {
sprintf ( char_buff , " %2.1f " , max_img_loss * ( number_of_lines - i ) / number_of_lines ) ;
sprintf ( char_buff , " %2.1f " , max_img_loss * ( number_of_lines - i ) / number_of_lines ) ;
pt_text . y = pt1 . y + 5 ;
pt_text . y = pt1 . y + 3 ;
cv : : putText ( img , char_buff , pt_text , cv : : FONT_HERSHEY_COMPLEX_SMALL , 0.7 , CV_RGB ( 0 , 0 , 0 ) , 1 , CV_AA ) ;
cv : : putText ( img , char_buff , pt_text , cv : : FONT_HERSHEY_COMPLEX_SMALL , 0.7 , CV_RGB ( 0 , 0 , 0 ) , 1 , CV_AA ) ;
cv : : line ( img , pt1 , pt2 , CV_RGB ( 128 , 128 , 128 ) , 1 , 8 , 0 ) ;
cv : : line ( img , pt1 , pt2 , CV_RGB ( 128 , 128 , 128 ) , 1 , 8 , 0 ) ;
@ -1018,7 +1024,7 @@ mat_cv* draw_train_chart(float max_img_loss, int max_batches, int number_of_line
}
}
}
}
cv : : putText ( img , " Loss " , cv : : Point ( 0 , 3 5) , cv : : FONT_HERSHEY_COMPLEX_SMALL , 0.7 , CV_RGB ( 0 , 0 , 0 ) , 1 , CV_AA ) ;
cv : : putText ( img , " Loss " , cv : : Point ( 1 0, 5 5) , cv : : FONT_HERSHEY_COMPLEX_SMALL , 0.7 , CV_RGB ( 0 , 0 , 255 ) , 1 , CV_AA ) ;
cv : : putText ( img , " Iteration number " , cv : : Point ( draw_size / 2 , img_size - 10 ) , cv : : FONT_HERSHEY_COMPLEX_SMALL , 0.7 , CV_RGB ( 0 , 0 , 0 ) , 1 , CV_AA ) ;
cv : : putText ( img , " Iteration number " , cv : : Point ( draw_size / 2 , img_size - 10 ) , cv : : FONT_HERSHEY_COMPLEX_SMALL , 0.7 , CV_RGB ( 0 , 0 , 0 ) , 1 , CV_AA ) ;
char max_batches_buff [ 100 ] ;
char max_batches_buff [ 100 ] ;
sprintf ( max_batches_buff , " in cfg max_batches=%d " , max_batches ) ;
sprintf ( max_batches_buff , " in cfg max_batches=%d " , max_batches ) ;
@ -1032,6 +1038,10 @@ mat_cv* draw_train_chart(float max_img_loss, int max_batches, int number_of_line
cv : : imshow ( " average loss " , img ) ;
cv : : imshow ( " average loss " , img ) ;
cv : : waitKey ( 20 ) ;
cv : : waitKey ( 20 ) ;
}
}
}
catch ( . . . ) {
cerr < < " OpenCV exception: draw_train_chart() \n " ;
}
return ( mat_cv * ) img_ptr ;
return ( mat_cv * ) img_ptr ;
}
}
// ----------------------------------------
// ----------------------------------------
@ -1039,8 +1049,9 @@ mat_cv* draw_train_chart(float max_img_loss, int max_batches, int number_of_line
void draw_train_loss ( mat_cv * img_src , int img_size , float avg_loss , float max_img_loss , int current_batch , int max_batches ,
void draw_train_loss ( mat_cv * img_src , int img_size , float avg_loss , float max_img_loss , int current_batch , int max_batches ,
float precision , int draw_precision , char * accuracy_name , int dont_show , int mjpeg_port )
float precision , int draw_precision , char * accuracy_name , int dont_show , int mjpeg_port )
{
{
try {
cv : : Mat & img = * ( cv : : Mat * ) img_src ;
cv : : Mat & img = * ( cv : : Mat * ) img_src ;
int img_offset = 5 0;
int img_offset = 6 0;
int draw_size = img_size - img_offset ;
int draw_size = img_size - img_offset ;
char char_buff [ 100 ] ;
char char_buff [ 100 ] ;
cv : : Point pt1 , pt2 ;
cv : : Point pt1 , pt2 ;
@ -1055,18 +1066,20 @@ void draw_train_loss(mat_cv* img_src, int img_size, float avg_loss, float max_im
static int iteration_old = 0 ;
static int iteration_old = 0 ;
static int text_iteration_old = 0 ;
static int text_iteration_old = 0 ;
if ( iteration_old = = 0 )
if ( iteration_old = = 0 )
cv : : putText ( img , accuracy_name , cv : : Point ( 0 , 12 ) , cv : : FONT_HERSHEY_COMPLEX_SMALL , 0.7 , CV_RGB ( 255 , 0 , 0 ) , 1 , CV_AA ) ;
cv : : putText ( img , accuracy_name , cv : : Point ( 1 0, 12 ) , cv : : FONT_HERSHEY_COMPLEX_SMALL , 0.7 , CV_RGB ( 255 , 0 , 0 ) , 1 , CV_AA ) ;
cv : : line ( img ,
cv : : line ( img ,
cv : : Point ( img_offset + draw_size * ( float ) iteration_old / max_batches , draw_size * ( 1 - old_precision ) ) ,
cv : : Point ( img_offset + draw_size * ( float ) iteration_old / max_batches , draw_size * ( 1 - old_precision ) ) ,
cv : : Point ( img_offset + draw_size * ( float ) current_batch / max_batches , draw_size * ( 1 - precision ) ) ,
cv : : Point ( img_offset + draw_size * ( float ) current_batch / max_batches , draw_size * ( 1 - precision ) ) ,
CV_RGB ( 255 , 0 , 0 ) , 1 , 8 , 0 ) ;
CV_RGB ( 255 , 0 , 0 ) , 1 , 8 , 0 ) ;
sprintf ( char_buff , " %2.0f%% " , precision * 100 ) ;
cv : : putText ( img , char_buff , cv : : Point ( 10 , 28 ) , cv : : FONT_HERSHEY_COMPLEX_SMALL , 0.7 , CV_RGB ( 255 , 255 , 255 ) , 5 , CV_AA ) ;
cv : : putText ( img , char_buff , cv : : Point ( 10 , 28 ) , cv : : FONT_HERSHEY_COMPLEX_SMALL , 0.7 , CV_RGB ( 200 , 0 , 0 ) , 1 , CV_AA ) ;
if ( ( ( int ) ( old_precision * 10 ) ! = ( int ) ( precision * 10 ) ) | | ( current_batch - text_iteration_old ) > = max_batches / 10 ) {
if ( ( ( int ) ( old_precision * 10 ) ! = ( int ) ( precision * 10 ) ) | | ( current_batch - text_iteration_old ) > = max_batches / 10 ) {
text_iteration_old = current_batch ;
text_iteration_old = current_batch ;
sprintf ( char_buff , " %2.0f%% " , precision * 100 ) ;
cv : : putText ( img , char_buff , cv : : Point ( pt1 . x - 30 , draw_size * ( 1 - precision ) + 15 ) , cv : : FONT_HERSHEY_COMPLEX_SMALL , 0.7 , CV_RGB ( 255 , 255 , 255 ) , 5 , CV_AA ) ;
cv : : putText ( img , char_buff , cv : : Point ( pt1 . x - 30 , draw_size * ( 1 - precision ) + 15 ) , cv : : FONT_HERSHEY_COMPLEX_SMALL , 0.7 , CV_RGB ( 255 , 255 , 255 ) , 5 , CV_AA ) ;
cv : : putText ( img , char_buff , cv : : Point ( pt1 . x - 30 , draw_size * ( 1 - precision ) + 15 ) , cv : : FONT_HERSHEY_COMPLEX_SMALL , 0.7 , CV_RGB ( 200 , 0 , 0 ) , 1 , CV_AA ) ;
cv : : putText ( img , char_buff , cv : : Point ( pt1 . x - 30 , draw_size * ( 1 - precision ) + 15 ) , cv : : FONT_HERSHEY_COMPLEX_SMALL , 0.7 , CV_RGB ( 200 , 0 , 0 ) , 1 , CV_AA ) ;
}
}
old_precision = precision ;
old_precision = precision ;
@ -1074,11 +1087,11 @@ void draw_train_loss(mat_cv* img_src, int img_size, float avg_loss, float max_im
}
}
sprintf ( char_buff , " current avg loss = %2.4f iteration = %d " , avg_loss , current_batch ) ;
sprintf ( char_buff , " current avg loss = %2.4f iteration = %d " , avg_loss , current_batch ) ;
pt1 . x = 5 5, pt1 . y = 10 ;
pt1 . x = 1 5, pt1 . y = draw_size + 18 ;
pt2 . x = pt1 . x + 460 , pt2 . y = pt1 . y + 20 ;
pt2 . x = pt1 . x + 460 , pt2 . y = pt1 . y + 20 ;
cv : : rectangle ( img , pt1 , pt2 , CV_RGB ( 255 , 255 , 255 ) , CV_FILLED , 8 , 0 ) ;
cv : : rectangle ( img , pt1 , pt2 , CV_RGB ( 255 , 255 , 255 ) , CV_FILLED , 8 , 0 ) ;
pt1 . y + = 15 ;
pt1 . y + = 15 ;
cv : : putText ( img , char_buff , pt1 , cv : : FONT_HERSHEY_COMPLEX_SMALL , 0.7 , CV_RGB ( 0 , 0 , 0 ) , 1 , CV_AA ) ;
cv : : putText ( img , char_buff , pt1 , cv : : FONT_HERSHEY_COMPLEX_SMALL , 0.7 , CV_RGB ( 0 , 0 , 10 0) , 1 , CV_AA ) ;
int k = 0 ;
int k = 0 ;
if ( ! dont_show ) {
if ( ! dont_show ) {
@ -1093,6 +1106,10 @@ void draw_train_loss(mat_cv* img_src, int img_size, float avg_loss, float max_im
cv : : putText ( img , " - Saved " , cv : : Point ( 260 , img_size - 10 ) , cv : : FONT_HERSHEY_COMPLEX_SMALL , 0.7 , CV_RGB ( 255 , 255 , 255 ) , 1 , CV_AA ) ;
cv : : putText ( img , " - Saved " , cv : : Point ( 260 , img_size - 10 ) , cv : : FONT_HERSHEY_COMPLEX_SMALL , 0.7 , CV_RGB ( 255 , 255 , 255 ) , 1 , CV_AA ) ;
if ( mjpeg_port > 0 ) send_mjpeg ( ( mat_cv * ) & img , mjpeg_port , 500000 , 100 ) ;
if ( mjpeg_port > 0 ) send_mjpeg ( ( mat_cv * ) & img , mjpeg_port , 500000 , 100 ) ;
}
catch ( . . . ) {
cerr < < " OpenCV exception: draw_train_loss() \n " ;
}
}
}
// ----------------------------------------
// ----------------------------------------