views:

31

answers:

1

Hi, I'm a math undergrad and have little programming experience. I'm interested in computer vision however. Tried to follow the Learning OpenCV book but its slightly outdated. How do i save the resulting video file in my linux home directory? for eg "/home/user/..", thanks in advance, this is my first post and i know i won't be disappointed. I'm compiling on eclipse btw, and i'm not too familiar with the arguments setting.

#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <cv.h>
#include <highgui.h>


int main(int argc, char *argv[]) {

 int isColor = 1;
 int frameW  = 640;
 int frameH  = 480;
 int fps     = 25;

 CvCapture* capture = cvCaptureFromCAM(0);
 assert( capture != NULL );

 cvNamedWindow( "Webcam", CV_WINDOW_AUTOSIZE);

 CvVideoWriter *writer = cvCreateVideoWriter(
   "out.avi",
   CV_FOURCC('M','J','P','G'),
   fps,
   cvSize(frameW,frameH),
   isColor
  );

 IplImage* frame = cvQueryFrame( capture );

 while( (frame = cvQueryFrame( capture )) != NULL ) {
  cvWriteFrame(writer, frame);
  cvShowImage("Webcam", frame);
  char c = cvWaitKey( 33 );
  if ( c == 27 ) break;
 }

 cvReleaseVideoWriter( &writer );
 cvReleaseCapture( &capture );
 return(0);

}
A: 

Have you tried passing the full path to cvCreateVideoWriter?

 CvVideoWriter *writer = cvCreateVideoWriter(
   "/home/user/out.avi",
   CV_FOURCC('M','J','P','G'),
   fps,
   cvSize(frameW,frameH),
   isColor
  );
bde
Hey, thanks for replying. I've reinstalled OpenCV with ffmpeg installed properly. but now i get this error. any idea?===================================================================relocation error: /usr/local/lib/libhighgui.so.2.1: symbol sws_getContext, version LIBAVCODEC_52 not defined in file libavcodec.so.52 with link time reference
Edwin
I'm not totally sure, that maybe sounds like an issue with how ffmpeg was compiled. Are you building it yourself or installing it as a package? I'm not very familiar with doing this, but from googling around [here](http://www.rainsoft.de/projects/ffmpeg_opencv.html) it looks like you may need to build ffmpeg with the `--enable-shared` option.
bde