将视频从彩色转换为灰度
convert video from colour to grayscale
我想读入彩色视频,并将其输出为灰度视频。下面是我的代码,运行得很好,但输出的是我的同色视频。有人能发现问题吗?
//Convert a video to grayscale
//argv[1]: input video file
//argv[2]: name of new output file
#include "cv.h"
#include "highgui.h"
int main( int argc, char* argv ) {
CvCapture* capture = cvCaptureFromAVI("C:\walking\lady walking.avi");
if(!capture){
return -1;
}
IplImage *bgr_frame=cvQueryFrame(capture);//Init the video read
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(
"Output video",//filename for new file
CV_FOURCC('M','J','P','G'),//video codec to compress video stream
fps,
size
);
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 );
IplImage*image;
CvCapture*recorder = cvCaptureFromAVI("C:\walking\lady walking.avi");
cvNamedWindow("Output video",1);
while(1) {
image=cvQueryFrame(recorder);
if(image==NULL)
{
break;
}
cvShowImage("Output video",image);
char c= cvWaitKey(30);
if(c==27)
{
break;
}
}
cvReleaseCapture( &capture );
cvDestroyWindow( "Output video" );
return 0;
}
在我看来,您的问题只是您在"输出视频"窗口中显示的视频实际上是您的"lady walking.avi"输入视频,而不是您输出的视频。
相关文章:
- OpenCV - 如何将灰度转换为彩色(CV_8UC3)?
- C++ Gdi+将图像转换为灰度
- 将 BMP 图像转换为灰度
- 颜色到灰度转换
- 如何将图像转换为灰度 opengl c++
- 如何正确将位图转换为 OpenCV 灰度垫
- 将 YUV420p QVideoFrame 转换为灰度 OpenCV 垫
- Qmage:使用颜色表从灰度转换为RGB
- 在OpenCV中将灰度图像转换为单色
- Mat的convertTo函数在OpenCV中将灰度图像的类型转换为CV_32F时抱怨断言错误
- 使用某些系数将图像转换为灰度的最快方法
- OPENCV:从RGB转换为灰度只有蓝色
- 在C++中将彩色位图转换为灰度
- 如何将灰度/二进制垫子转换为qimage
- 使用libpng将转换设置为灰度
- 使用煤渣转换为灰度
- 将颜色图像转换为OpenCV中的灰度问题
- 在open cv中,我如何将灰度图像转换回RGB图像(颜色)
- 我正在尝试将灰度转换为更大的黑色图像.我得到这个错误OpenCV错误:断言失败
- 将图像颜色从灰度转换为RGB OpenCV C++