OpenCV中文网站

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 安装 配置
查看: 1443|回复: 0

为何只输出2个灰色窗口?

[复制链接]
发表于 2017-1-22 16:25:12 | 显示全部楼层 |阅读模式
下面程序,教材上说将彩色视频变成灰色视频输出,但只出来2个灰色窗口,恳请哪位大侠指点一下是什么问题?
#include "cv.h"
#include "highgui.h"
#include <stdio.h>

// Convert a video to grayscale
// argv[1]: input video file
// argv[2]: name of new output file
//

//#define NOWRITE 1;   //Turn this on (removed the first comment out "//" if you can't write on linux

int main(int argc, char* argv[]) {
        cvNamedWindow("Example2_10", CV_WINDOW_AUTOSIZE);
        cvNamedWindow("Log_Polar", CV_WINDOW_AUTOSIZE);
        CvCapture* capture = cvCreateFileCapture("E:\\desney.avi");
        if (!capture) {
                return -1;
        }
        IplImage* bgr_frame;
        double fps = cvGetCaptureProperty(
                capture,
                CV_CAP_PROP_FPS
                );
        printf("fps=%d\n", (int)fps);

        CvSize size = cvSize(
                (int)cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH),
                (int)cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT)
                );

        printf("frame (w, h) = (%d, %d)\n", size.width, size.height);
#ifndef NOWRITE
        CvVideoWriter* writer = cvCreateVideoWriter(  // On linux Will only work if you've installed ffmpeg development files correctly,
                argv[2],                               // otherwise segmentation fault.  Windows probably better.
                CV_FOURCC('D', 'X', '5', '0'),
                fps,
                size
                );
#endif
        IplImage* logpolar_frame = cvCreateImage(
                size,
                IPL_DEPTH_8U,
                3
                );

        IplImage* gray_frame = cvCreateImage(
                size,
                IPL_DEPTH_8U,
                1
                );

        while ((bgr_frame = cvQueryFrame(capture)) != NULL) {
                cvShowImage("Example2_10", bgr_frame);
                cvConvertImage(   //We never make use of this gray image
                        bgr_frame,
                        gray_frame,
                        CV_RGB2GRAY
                        );
                cvLogPolar(bgr_frame, logpolar_frame,  //This is just a fun conversion the mimic's the human visual system
                        cvPoint2D32f(bgr_frame->width / 2,
                                bgr_frame->height / 2),
                        40,
                        CV_INTER_LINEAR + CV_WARP_FILL_OUTLIERS);
                cvShowImage("Log_Polar", logpolar_frame);
                //Sigh, on linux, depending on your ffmpeg, this often won't work ...
#ifndef NOWRITE
                cvWriteToAVI(writer, logpolar_frame);
#endif
                char c = cvWaitKey(10);
                if (c == 27) break;
        }
#ifndef NOWRITE
        cvReleaseVideoWriter(&writer);
#endif
        cvReleaseImage(&gray_frame);
        cvReleaseImage(&logpolar_frame);
        cvReleaseCapture(&capture);
}


回复

使用道具 举报

*滑动验证:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|blog|OpenCV中文网站 ( 粤ICP备13079875号-2

GMT+8, 2019-3-23 09:05 , Processed in 0.060019 second(s), 21 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表