1 | #include "opencv2/video/video.hpp"
|
2 | #include "opencv2/highgui/highgui.hpp"
|
3 | #include <opencv2/imgproc/imgproc.hpp>
|
4 | #include <stdio.h>
|
5 | #include <iostream>
|
6 | using namespace cv;
|
7 | using namespace std;
|
8 | int main(int argc, char* argv[])
|
9 | {
|
10 | CvCapture* pCap = NULL;
|
11 | char* avi_name = argv[1];
|
12 | printf("Video name = %s\n", avi_name);
|
13 |
|
14 | if(avi_name)
|
15 | pCap = cvCaptureFromFile(avi_name);
|
16 |
|
17 | if(pCap==NULL)
|
18 | {
|
19 | printf("\nCan't open %s file\n",avi_name);
|
20 | return -1;
|
21 | }
|
22 |
|
23 | cvNamedWindow("gray");
|
24 |
|
25 | CvVideoWriter* pFGAvi = NULL;
|
26 |
|
27 | while(pCap)
|
28 | {
|
29 | IplImage* pImg = NULL;
|
30 | pImg = cvQueryFrame(pCap);
|
31 | if(pImg == NULL) break;
|
32 |
|
33 | if (pFGAvi == NULL)
|
34 | pFGAvi=cvCreateVideoWriter(
|
35 | argv[2],
|
36 | CV_FOURCC_DEFAULT,
|
37 | 25,
|
38 | cvSize(pImg->width, pImg->height),1);
|
39 |
|
40 | IplImage* gray = cvCreateImage(cvSize(pImg->width, pImg->height),pImg->depth,1);
|
41 | cvCvtColor(pImg, gray, CV_BGR2GRAY);
|
42 |
|
43 | IplImage* gray3 = cvCreateImage(cvSize(pImg->width, pImg->height),pImg->depth,3);
|
44 | cvCvtColor(gray, gray3, CV_GRAY2BGR);
|
45 |
|
46 | cvWriteFrame(pFGAvi, gray3);
|
47 |
|
48 | cvShowImage("gray", gray);
|
49 | cvWaitKey(1);
|
50 |
|
51 | if (gray)
|
52 | cvReleaseImage(&gray);
|
53 | if (gray3)
|
54 | cvReleaseImage(&gray3);
|
55 | }
|
56 |
|
57 | if (pFGAvi)
|
58 | cvReleaseVideoWriter(&pFGAvi);
|
59 |
|
60 | if(pCap)
|
61 | cvReleaseCapture(&pCap);
|
62 |
|
63 | pCap = cvCaptureFromFile(argv[2]);
|
64 |
|
65 | if(pCap==NULL)
|
66 | {
|
67 | printf("\nCan't open %s file\n",avi_name);
|
68 | return -1;
|
69 | }
|
70 |
|
71 | while(pCap)
|
72 | {
|
73 | IplImage* pImg = NULL;
|
74 | pImg = cvQueryFrame(pCap);
|
75 | if(pImg == NULL) break;
|
76 | cvShowImage("gray", pImg);
|
77 | cvWaitKey(1);
|
78 | }
|
79 |
|
80 | if(pCap)
|
81 | cvReleaseCapture(&pCap);
|
82 | return 0;
|
83 | }
|