📄 opencv_wrapper.c
字号:
/***************************************************************************** * opencv_wrapper.c : OpenCV wrapper video filter ***************************************************************************** * Copyright (C) 2006 the VideoLAN team * * Authors: Dugal Harris <dugalh@protoclea.co.za> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************//***************************************************************************** * Preamble *****************************************************************************/#include <cxcore.h>#include <cv.h>#include <highgui.h>#ifdef HAVE_CONFIG_H# include "config.h"#endif#include <vlc_common.h>#include <vlc_plugin.h>#include <vlc_vout.h>#include <math.h>#include <time.h>#include "vlc_filter.h"#include "filter_common.h"#include <vlc_charset.h>#include "vlc_image.h"#include "vlc_input.h"#include "vlc_playlist.h"/***************************************************************************** * Local prototypes *****************************************************************************/static int Create ( vlc_object_t * );static void Destroy ( vlc_object_t * );static int Init ( vout_thread_t * );static void End ( vout_thread_t * );static void Render ( vout_thread_t *, picture_t * );static int SendEvents( vlc_object_t *, char const *, vlc_value_t, vlc_value_t, void * );static void ReleaseImages( vout_thread_t *p_vout );static void VlcPictureToIplImage( vout_thread_t *p_vout, picture_t *p_in );/***************************************************************************** * Module descriptor *****************************************************************************/static const char *const chroma_list[] = { "input", "I420", "RGB32"};static const char *const chroma_list_text[] = { N_("Use input chroma unaltered"), N_("I420 - first plane is greyscale"), N_("RGB32")};static const char *const output_list[] = { "none", "input", "processed"};static const char *const output_list_text[] = { N_("Don't display any video"), N_("Display the input video"), N_("Display the processed video")};static const char *const verbosity_list[] = { "error", "warning", "debug"};static const char *const verbosity_list_text[] = { N_("Show only errors"), N_("Show errors and warnings"), N_("Show everything including debug messages")};vlc_module_begin(); set_description( N_("OpenCV video filter wrapper") ); set_shortname( N_("OpenCV" )); set_category( CAT_VIDEO ); set_subcategory( SUBCAT_VIDEO_VFILTER ); set_capability( "video filter", 0 ); add_shortcut( "opencv_wrapper" ); set_callbacks( Create, Destroy ); add_float_with_range( "opencv-scale", 1.0, 0.1, 2.0, NULL, N_("Scale factor (0.1-2.0)"), N_("Ammount by which to scale the picture before sending it to the internal OpenCV filter"), false ); add_string( "opencv-chroma", "input", NULL, N_("OpenCV filter chroma"), N_("Chroma to convert picture to before sending it to the internal OpenCV filter"), false); change_string_list( chroma_list, chroma_list_text, 0); add_string( "opencv-output", "input", NULL, N_("Wrapper filter output"), N_("Determines what (if any) video is displayed by the wrapper filter"), false); change_string_list( output_list, output_list_text, 0); add_string( "opencv-verbosity", "error", NULL, N_("Wrapper filter verbosity"), N_("Determines wrapper filter verbosity level"), false); change_string_list( verbosity_list, verbosity_list_text, 0); add_string( "opencv-filter-name", "none", NULL, N_("OpenCV internal filter name"), N_("Name of internal OpenCV plugin filter to use"), false);vlc_module_end();/***************************************************************************** * wrapper_output_t: what video is output *****************************************************************************/enum wrapper_output_t{ NONE, //not working yet VINPUT, PROCESSED};/***************************************************************************** * internal_chroma_t: what chroma is sent to the internal opencv filter *****************************************************************************/enum internal_chroma_t{ CINPUT, GREY, RGB};/***************************************************************************** * verbosity_t: *****************************************************************************/enum verbosity_t{ VERB_ERROR, VERB_WARN, VERB_DEBUG};/***************************************************************************** * vout_sys_t: opencv_wrapper video output method descriptor ***************************************************************************** * This structure is part of the video output thread descriptor. * It describes the opencv_wrapper specific properties of an output thread. *****************************************************************************/struct vout_sys_t{ vout_thread_t *p_vout; image_handler_t *p_image; int i_cv_image_size; picture_t *p_proc_image; picture_t *p_to_be_freed; float f_scale; int i_wrapper_output; int i_internal_chroma; int i_verbosity; IplImage *p_cv_image[VOUT_MAX_PLANES]; filter_t *p_opencv; char* psz_inner_name; picture_t hacked_pic;};/***************************************************************************** * Control: control facility for the vout (forwards to child vout) *****************************************************************************/static int Control( vout_thread_t *p_vout, int i_query, va_list args ){ return vout_vaControl( p_vout->p_sys->p_vout, i_query, args );}/***************************************************************************** * Create: allocates opencv_wrapper video thread output method ***************************************************************************** * This function allocates and initializes a opencv_wrapper vout method. *****************************************************************************/static int Create( vlc_object_t *p_this ){ vout_thread_t *p_vout = (vout_thread_t *)p_this; char *psz_chroma, *psz_output, *psz_verbosity; int i = 0; /* Allocate structure */ p_vout->p_sys = malloc( sizeof( vout_sys_t ) ); if( p_vout->p_sys == NULL ) return VLC_ENOMEM; /* Init structure */ p_vout->p_sys->p_image = image_HandlerCreate( p_vout ); for (i = 0; i < VOUT_MAX_PLANES; i++) p_vout->p_sys->p_cv_image[i] = NULL; p_vout->p_sys->p_proc_image = NULL; p_vout->p_sys->p_to_be_freed = NULL; p_vout->p_sys->i_cv_image_size = 0; p_vout->pf_init = Init; p_vout->pf_end = End; p_vout->pf_manage = NULL; p_vout->pf_render = Render; p_vout->pf_display = NULL; p_vout->pf_control = Control; /* Retrieve and apply config */ if( !(psz_chroma = config_GetPsz( p_vout, "opencv-chroma" )) ) { msg_Err( p_vout, "configuration variable %s empty, using 'grey'", "opencv-chroma" ); p_vout->p_sys->i_internal_chroma = GREY; } else { if( !strcmp( psz_chroma, "input" ) ) p_vout->p_sys->i_internal_chroma = CINPUT; else if( !strcmp( psz_chroma, "I420" ) ) p_vout->p_sys->i_internal_chroma = GREY; else if( !strcmp( psz_chroma, "RGB32" ) ) p_vout->p_sys->i_internal_chroma = RGB; else { msg_Err( p_vout, "no valid opencv-chroma provided, using 'grey'" ); p_vout->p_sys->i_internal_chroma = GREY; } } free( psz_chroma); if( !(psz_output = config_GetPsz( p_vout, "opencv-output" )) ) { msg_Err( p_vout, "configuration variable %s empty, using 'input'", "opencv-output" ); p_vout->p_sys->i_wrapper_output = VINPUT; } else { if( !strcmp( psz_output, "none" ) ) p_vout->p_sys->i_wrapper_output = NONE; else if( !strcmp( psz_output, "input" ) ) p_vout->p_sys->i_wrapper_output = VINPUT; else if( !strcmp( psz_output, "processed" ) ) p_vout->p_sys->i_wrapper_output = PROCESSED; else { msg_Err( p_vout, "no valid opencv-output provided, using 'input'" ); p_vout->p_sys->i_wrapper_output = VINPUT; } } free( psz_output); if( !(psz_verbosity = config_GetPsz( p_vout, "opencv-verbosity" )) ) { msg_Err( p_vout, "configuration variable %s empty, using 'input'", "opencv-verbosity" ); p_vout->p_sys->i_verbosity = VERB_ERROR; } else { if( !strcmp( psz_verbosity, "error" ) ) p_vout->p_sys->i_verbosity = VERB_ERROR; else if( !strcmp( psz_verbosity, "warning" ) ) p_vout->p_sys->i_verbosity = VERB_WARN; else if( !strcmp( psz_verbosity, "debug" ) ) p_vout->p_sys->i_verbosity = VERB_DEBUG; else { msg_Err( p_vout, "no valid opencv-verbosity provided, using 'error'" ); p_vout->p_sys->i_verbosity = VERB_ERROR; } } free( psz_verbosity); p_vout->p_sys->psz_inner_name = config_GetPsz( p_vout, "opencv-filter-name" ); p_vout->p_sys->f_scale = config_GetFloat( p_vout, "opencv-scale" ); if (p_vout->p_sys->i_verbosity > VERB_WARN) msg_Info(p_vout, "Configuration: opencv-scale: %f, opencv-chroma: %d, " "opencv-output: %d, opencv-verbosity %d, opencv-filter %s", p_vout->p_sys->f_scale, p_vout->p_sys->i_internal_chroma, p_vout->p_sys->i_wrapper_output, p_vout->p_sys->i_verbosity, p_vout->p_sys->psz_inner_name); return VLC_SUCCESS;}/***************************************************************************** * Init: initialize opencv_wrapper video thread output method *****************************************************************************/static int Init( vout_thread_t *p_vout ){ int i_index; picture_t *p_pic; video_format_t fmt; vout_sys_t *p_sys = p_vout->p_sys; I_OUTPUTPICTURES = 0; /* Initialize the output video format */ memset( &fmt, 0, sizeof(video_format_t) ); p_vout->output.i_chroma = p_vout->render.i_chroma; p_vout->output.i_width = p_vout->render.i_width; p_vout->output.i_height = p_vout->render.i_height;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -