사용환경: 리눅스 우분투 9.10
커널: 2.6.31
openCV: 2.0
Learning openCV 제대로 배우기 예제 2-10를 예를 들자면
//usage: ex2-10
// argv[1]: input video file name
// argv[2]: output video file name
#include "cv.h"
#include "highgui.h"
int main(int argc, char* argv[])
{
CvCapture* capture = cvCreateFileCapture( argv[1]);
if(!capture)
return -1;
IplImage* bgr_frame = cvQueryFrame(capture); //video initialize
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(argv[2], -1, 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);
return 0;
}
소스는 다음과 같이 간단하게 구현하고
컴 파일은
#! /bin/sh
g++ -o test $1 -I/usr/local/include/opencv -L/usr/local/lib -lcv -lhighgui -lcvaux
다음과 같이 간단하게 쉘 명령어로 정상적으로 컴파일을 끝낸다음
./test tree.avi test.avi
로 실행하면
다음과 같이 뜹니다.
OpenCVError: Unsupported format or combination of formats (FFMPEG could notfind a codec matching the given FOURCC code. Usefourcc=CV_FOURCC_DEFAULT for auto selection.) inCvVideoWriter_FFMPEG::open, file/usr/local/OpenCV-2.0.0/src/highgui/cvcap_ffmpeg.cpp, line 1234
terminate called after throwing an instance of 'cv::Exception'
Aborted
근대 리눅스에 이미 ffmpeg를 깔아서 ffmpeg를 실행해보고 정상 설치된 것이 확인되면
FFmpeg version SVN-r19352-4:0.5+svn20090706-2ubuntu2, Copyright (c) 2000-2009 Fabrice Bellard, et al.
configuration: --extra-version=4:0.5+svn20090706-2ubuntu2 --prefix=/usr--enable-avfilter --enable-avfilter-lavf --enable-vdpau --enable-bzlib--enable-libgsm --enable-libschroedinger --enable-libspeex--enable-libtheora --enable-libvorbis --enable-pthreads --enable-zlib--disable-stripping --disable-vhook --enable-gpl --enable-postproc--enable-swscale --enable-x11grab --enable-libdc1394--extra-cflags=-I/build/buildd/ffmpeg-0.5+svn20090706/debian/include--enable-shared --disable-static
libavutil 49.15. 0 / 49.15. 0
libavcodec 52.20. 0 / 52.20. 0
libavformat 52.31. 0 / 52.31. 0
libavdevice 52. 1. 0 / 52. 1. 0
libavfilter 0. 4. 0 / 0. 4. 0
libswscale 0. 7. 1 / 0. 7. 1
libpostproc 51. 2. 0 / 51. 2. 0
built on Oct 13 2009 22:15:16, gcc: 4.4.1
At least one output file must be specified
다음과 같은 문제점이 발견되는 이유는
CvVideoWriter* writer = cvCreateVideoWriter(argv[2], -1, fps, size);
CV_FOURCC 부분에서 -1은 윈도우사용시에만 사용하는 거라고
highgui.h 에 정의 되어 있기 때문에
CV_FORCE('D','X','5','0') 로 해서 ffmpeg를 사용하거나 CV_FOURCC_DEFAULT로 해줘야 리눅스에서
정상 작동합니다.
커널: 2.6.31
openCV: 2.0
Learning openCV 제대로 배우기 예제 2-10를 예를 들자면
//usage: ex2-10
// argv[1]: input video file name
// argv[2]: output video file name
#include "cv.h"
#include "highgui.h"
int main(int argc, char* argv[])
{
CvCapture* capture = cvCreateFileCapture( argv[1]);
if(!capture)
return -1;
IplImage* bgr_frame = cvQueryFrame(capture); //video initialize
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(argv[2], -1, 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);
return 0;
}
소스는 다음과 같이 간단하게 구현하고
컴 파일은
#! /bin/sh
g++ -o test $1 -I/usr/local/include/opencv -L/usr/local/lib -lcv -lhighgui -lcvaux
다음과 같이 간단하게 쉘 명령어로 정상적으로 컴파일을 끝낸다음
./test tree.avi test.avi
로 실행하면
다음과 같이 뜹니다.
OpenCVError: Unsupported format or combination of formats (FFMPEG could notfind a codec matching the given FOURCC code. Usefourcc=CV_FOURCC_DEFAULT for auto selection.) inCvVideoWriter_FFMPEG::open, file/usr/local/OpenCV-2.0.0/src/highgui/cvcap_ffmpeg.cpp, line 1234
terminate called after throwing an instance of 'cv::Exception'
Aborted
근대 리눅스에 이미 ffmpeg를 깔아서 ffmpeg를 실행해보고 정상 설치된 것이 확인되면
FFmpeg version SVN-r19352-4:0.5+svn20090706-2ubuntu2, Copyright (c) 2000-2009 Fabrice Bellard, et al.
configuration: --extra-version=4:0.5+svn20090706-2ubuntu2 --prefix=/usr--enable-avfilter --enable-avfilter-lavf --enable-vdpau --enable-bzlib--enable-libgsm --enable-libschroedinger --enable-libspeex--enable-libtheora --enable-libvorbis --enable-pthreads --enable-zlib--disable-stripping --disable-vhook --enable-gpl --enable-postproc--enable-swscale --enable-x11grab --enable-libdc1394--extra-cflags=-I/build/buildd/ffmpeg-0.5+svn20090706/debian/include--enable-shared --disable-static
libavutil 49.15. 0 / 49.15. 0
libavcodec 52.20. 0 / 52.20. 0
libavformat 52.31. 0 / 52.31. 0
libavdevice 52. 1. 0 / 52. 1. 0
libavfilter 0. 4. 0 / 0. 4. 0
libswscale 0. 7. 1 / 0. 7. 1
libpostproc 51. 2. 0 / 51. 2. 0
built on Oct 13 2009 22:15:16, gcc: 4.4.1
At least one output file must be specified
다음과 같은 문제점이 발견되는 이유는
CvVideoWriter* writer = cvCreateVideoWriter(argv[2], -1, fps, size);
CV_FOURCC 부분에서 -1은 윈도우사용시에만 사용하는 거라고
highgui.h 에 정의 되어 있기 때문에
CV_FORCE('D','X','5','0') 로 해서 ffmpeg를 사용하거나 CV_FOURCC_DEFAULT로 해줘야 리눅스에서
정상 작동합니다.
'Programming > image processing' 카테고리의 다른 글
Install ubuntu on asus tuf a15 fa506qm (0) | 2021.05.05 |
---|---|
nvidia-smi has failed (0) | 2021.01.04 |
openCV 동영상/카메라 관련내용 정리 (0) | 2010.03.03 |
opencv 에러 HIGHGUI ERROR: V4L2 문제에 관해 (0) | 2010.02.25 |
우분투(리눅스) ubuntu 8.10 openCV 2.0 설치하기 (0) | 2010.02.21 |