Implement read into a color video file and output this video file in grayscale format, learn OpenCV example 2-10

Source: Internet
Author: User

#include "Cv.h"
#include "highgui.h"
int main (int argc,char* argv[]) {//The main in the book is not defined as an int return type, error: C + + does not support int by default
cvcapture* capture = 0;
Capture = Cvcreatefilecapture ("P.avi"),//p.avi stored directly in the folder where the current CPP file is located, all without the write path, otherwise such as: D:\\sandy\\visual studio 2010\\ Projects\\video\\video\\p.avi
if (!capture) return-1;
Iplimage *bgr_frame = cvqueryframe (capture);

Double fps = cvgetcaptureproperty (capture, Cv_cap_prop_fps);
Cvsize size =cvsize (
(int) Cvgetcaptureproperty (capture,cv_cap_prop_frame_width),
(int) Cvgetcaptureproperty (capture,cv_cap_prop_frame_height)
);
Cvvideowriter *writer=cvcreatevideowriter ("D:\\shengcheng.avi", CV_FOURCC (' M ', ' J ', ' P ', ' G '), fps,size);//Cv_ FOURCC (' M ', ' J ', ' P ', ' G ') instead of-1, just generate a Shengcheng.avi file in D, and I don't understand why.
iplimage* logpolar_frame =cvcreateimage (size,ipl_depth_8u,3);

while ((Bgr_frame = Cvqueryframe (capture))!=null) {
Cvlogpolar (Bgr_frame,logpolar_frame,
cvpoint2d32f (BGR_FRAME->WIDTH/2,
BGR_FRAME->HEIGHT/2),
40,cv_inter_linear+cv_warp_fill_outliers);
Cvwriteframe (Writer,logpolar_frame);
}
Cvreleasevideowriter (&writer);
Cvreleaseimage (&logpolar_frame);
Cvreleasecapture (&capture);
return (0);
}

Original video:

Generate Video:

Implement read into a color video file and output this video file in grayscale format, learn OpenCV example 2-10

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.