OpenCV中文网站

 找回密码
 立即注册
搜索
热搜: 安装 配置
查看: 4137|回复: 1

为何只输出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);
}


回复

使用道具 举报

发表于 2019-4-26 18:00:18 | 显示全部楼层
bgr_frame 没有createimage?
是这个原因吗
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|OpenCV中文网站

GMT+8, 2024-3-19 13:32 , Processed in 0.017260 second(s), 16 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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