我尝试使用openCV编写VLC视频滤镜来规范化视频。
我在VLC picture_t
转换为IplImage
并返回picture_t
时遇到了麻烦。需要IplImage才能转换为Mat并继续使用openCV工具。无法在其他地方找到解决方案,所以在这里寻求帮助。
转换图像的主要功能是:
static picture_t *FilterNormalizeOpenCV( filter_t *p_filter, picture_t *p_pic )
{
Mat frame1;
IplImage* p_img1;
video_format_t fmt_out, fmt_in;
int i_planes = p_pic->i_planes;
CvSize sz = cvSize(abs(p_pic->format.i_width), abs(p_pic->format.i_height));
CvPoint pt1, pt2;
filter_sys_t *p_sys = p_filter->p_sys;
if ((!p_pic)) {
msg_Err( p_filter, "no image array" );
printf ("\n\n %s \n\n", "No p pic!!!");
return NULL;
}
i_planes = p_pic->i_planes;
if (i_planes<1) {
printf ("\n\n %s \n\n", "No image planes!!!");
msg_Err( p_filter, "no image planes" );
return NULL;
}
fmt_in = p_pic->format;
fmt_out = p_pic->format;
fmt_out.i_width = p_pic->format.i_width * p_sys->f_scale;
fmt_out.i_height = p_pic->format.i_height * p_sys->f_scale;
fmt_out.i_chroma = VLC_CODEC_BGRA;
p_sys->p_proc_image = image_Convert( p_sys->p_image, p_pic,
&(p_pic->format), &fmt_out );
p_sys->p_to_be_freed = p_sys->p_proc_image;
i_planes = p_sys->p_proc_image->i_planes;
for( int i = 0; i < i_planes; i++ )
{
sz = cvSize(abs(p_sys->p_proc_image->p[i].i_visible_pitch /
p_sys->p_proc_image->p[i].i_pixel_pitch),
abs(p_sys->p_proc_image->p[i].i_visible_lines));
p_sys->p_cv_image[i] = cvCreateImageHeader(sz, IPL_DEPTH_8U,
p_sys->p_proc_image->p[i].i_pixel_pitch);
cvSetData( p_sys->p_cv_image[i],
(char*)(p_sys->p_proc_image->p[i].p_pixels), p_sys->p_proc_image->p[i].i_pitch );
}
p_img1 = p_sys->p_cv_image[0];
frame1 = cvarrToMat(p_img1);
//Here we'll proceed Mat frame with openCV
//and convert it back ti IplImage
//p_img1 = new IplImage(frame1);
cvGetRawData(p_img1, (uchar **) & p_pic->p[0].p_pixels, NULL, &sz);
return p_pic;
}
所以,现在,它只接收VLC picture_t,将其转换为BGRA(用于openCV),将其转换为IplImage并返回picture_t。 但是,结果来得很麻烦,我无法在这里下载低信誉的原因(screenshot)。非常感谢任何帮助。