How to execute some shell script after opencv detect circle - c++

How to execute some shell script (e.g 1.sh) after opencv detect circle?
I have used exec, it works but opencv program close after circle detected, and what I want is that the program didn't close until I press "q" key.
Here is my code:
#include<cv.h>
#include<highgui.h>
#include <math.h>
#include <stdlib.h>
#include <unistd.h>
using namespace std;
int main( int argc, char **argv )
{
CvCapture *capture = 0;
IplImage *img = 0;
int key = 0;
CvFont font;
cvInitFont(&font, CV_FONT_HERSHEY_PLAIN,1.0,1.0,0,1,CV_AA);
capture = cvCaptureFromCAM( 0 );
if ( !capture ) {
fprintf( stderr, "Cannot open initialize webcam!\n" );
return 1;
}
cvNamedWindow( "result", CV_WINDOW_AUTOSIZE );
img = cvQueryFrame( capture );
if (!img)
exit(1);
IplImage* gray = cvCreateImage( cvGetSize(img), 8, 1 );
CvMemStorage* storage = cvCreateMemStorage(0);
while( key != 'q' ) {
img = cvQueryFrame( capture );
if( !img ) break;
cvCvtColor( img, gray, CV_BGR2GRAY );
cvSmooth( gray, gray, CV_GAUSSIAN, 5, 5 );
CvSeq* circles = cvHoughCircles( gray, storage, CV_HOUGH_GRADIENT, 2, >gray->height/40, 200, 100/*, 20, 100*/ );
int i;
for( i = 0; i < circles->total; i++ )
{
float* p = (float*)cvGetSeqElem( circles, i );
cvCircle( img, cvPoint(cvRound(p[0]),cvRound(p[1])), cvRound(p[2]), >CV_RGB(50,255,30), 5, 8, 0 );
cvPutText(img, "CIRCLE",cvPoint(cvRound(p[0]+45),cvRound(p[1]+45)), &font, >CV_RGB(50,10,255));
if ( circles ) {
execl("./1.sh", (char *)0);
}
}
cvShowImage( "result", img );
cvShowImage("gray", gray);
key = cvWaitKey( 1 );
}
// cvReleaseMemStorage(storage);
// cvReleaseImage(gray);
cvDestroyAllWindows();
cvDestroyWindow( "result" );
cvReleaseCapture( &capture );
return 0;
}
I used codeblocks on ubuntu.

After exec*, none of the code (in that process) will be reached. You can fork, exec if you want the program to continue without waiting for the script to complete, otherwise add a wait. Alternatively, you could use system or popen.
Examples:
example function to fork a command and wait:
#include <unistd.h>
/*as a macro*/
#define FORK_EXEC_WAIT(a) ({int s,p;if((p=fork())==0) \
{execvp(a[0],a);}else{while(wait(&s)!= p);}})
/*as a function*/
void fork_exec_wait(char** a) {
int s,p;
if((p=fork())==0){
execvp(a[0],a);
}else{
while(wait(&s)!= p);
}
}
to fork a command and continue
#include <unistd.h>
/*as a macro*/
#define FORK_EXEC(a) ({if((fork())==0) execvp(a[0],a);})
/*as a function*/
void fork_exec(char** a) {
int s,p;
if((p=fork())==0)
execvp(a[0],a);
}
the system command is ~ fork-exec-wait of "sh -c command args"
#include <stdlib.h>
system("command args");
the popen command is similar without the sh -c and will give you the output as a stream (think pipes, fifo, etc)
#include <stdio.h>
FILE *fp;
fp = popen("command args", "r");
...
pclose(fp);

Related

Fail to Load .xml file when trying to run OpenCv objectDetection

I was trying to run the facial detection with OpenCV3.0 sample c++ code under macOS Sierria version 10.12.5. However, I failed the load the ".xml" file. I tried using relative path as well as absolute path to "haarcascade_frontalface_alt.xml" and "haarcascade_eye_tree_eyeglasses.xml" run it, but it did not solve the problem for me. I compiled the code successfully but got error message:
--(!)Error loading face cascade
I think there's some problem to do with the load method of the CascadeClassifier. I read about some threads. But none gives specific instructions on solving this matter. I beg for specific instructions on solving this. Thank you all so much!
Here is the sample code:
#include "opencv2/objdetect.hpp"
#include "opencv2/videoio.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"
#include <iostream>
#include <stdio.h>
using namespace std;
using namespace cv;
/** Function Headers */
void detectAndDisplay( Mat frame );
/** Global variables */
String face_cascade_name = "/my/path/to/haarcascade_frontalface_alt.xml";
String eyes_cascade_name = "/my/path/to/haarcascade_eye_tree_eyeglasses.xml";
CascadeClassifier face_cascade;
CascadeClassifier eyes_cascade;
String window_name = "Capture - Face detection";
/** #function main */
int main( int argc, const char** argv )
{
// CommandLineParser parser(argc, argv,
// "{help h||}"
// "{face_cascade|../../data/haarcascades/haarcascade_frontalface_alt.xml|}"
// "{eyes_cascade|../../data/haarcascades/haarcascade_eye_tree_eyeglasses.xml|}");
// cout << "\nThis program demonstrates using the cv::CascadeClassifier class to detect objects (Face + eyes) in a video stream.\n"
// "You can use Haar or LBP features.\n\n";
// parser.printMessage();
// face_cascade_name = parser.get<string>("face_cascade");
// eyes_cascade_name = parser.get<string>("eyes_cascade");
VideoCapture capture;
Mat frame;
//-- 1. Load the cascades
if( !face_cascade.load( face_cascade_name ) ){ printf("--(!)Error loading face cascade\n"); return -1; };
if( !eyes_cascade.load( eyes_cascade_name ) ){ printf("--(!)Error loading eyes cascade\n"); return -1; };
//-- 2. Read the video stream
capture.open( 0 );
if ( ! capture.isOpened() ) { printf("--(!)Error opening video capture\n"); return -1; }
while ( capture.read(frame) )
{
if( frame.empty() )
{
printf(" --(!) No captured frame -- Break!");
break;
}
//-- 3. Apply the classifier to the frame
detectAndDisplay( frame );
char c = (char)waitKey(10);
if( c == 27 ) { break; } // escape
}
return 0;
}
/** #function detectAndDisplay */
void detectAndDisplay( Mat frame )
{
std::vector<Rect> faces;
Mat frame_gray;
cvtColor( frame, frame_gray, COLOR_BGR2GRAY );
equalizeHist( frame_gray, frame_gray );
//-- Detect faces
face_cascade.detectMultiScale( frame_gray, faces, 1.1, 2, 0|CASCADE_SCALE_IMAGE, Size(30, 30) );
for ( size_t i = 0; i < faces.size(); i++ )
{
Point center( faces[i].x + faces[i].width/2, faces[i].y + faces[i].height/2 );
ellipse( frame, center, Size( faces[i].width/2, faces[i].height/2 ), 0, 0, 360, Scalar( 255, 0, 255 ), 4, 8, 0 );
Mat faceROI = frame_gray( faces[i] );
std::vector<Rect> eyes;
//-- In each face, detect eyes
eyes_cascade.detectMultiScale( faceROI, eyes, 1.1, 2, 0 |CASCADE_SCALE_IMAGE, Size(30, 30) );
for ( size_t j = 0; j < eyes.size(); j++ )
{
Point eye_center( faces[i].x + eyes[j].x + eyes[j].width/2, faces[i].y + eyes[j].y + eyes[j].height/2 );
int radius = cvRound( (eyes[j].width + eyes[j].height)*0.25 );
circle( frame, eye_center, radius, Scalar( 255, 0, 0 ), 4, 8, 0 );
}
}
//-- Show what you got
imshow( window_name, frame );
}

OpenCV Help - Error: no operator "=" Matches these operands. operand types are cv::Mat = IplImage*

I have recently started learning how to use OpenCV and i have been following the tutorials hosted by their website. I am using OpenCV 3.0, however, it seems some of the tutorial information is out of date.
I and on the tutorial "Cascade Classifier" link:
http://www.docs.opencv.org/doc/tutorials/objdetect/cascade_classifier/cascade_classifier.html
They provided example code is not running for me and I cannot understand why. I have provided the code example below:
#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include <stdio.h>
using namespace std;
using namespace cv;
/** Function Headers */
void detectAndDisplay( Mat frame );
/** Global variables */
String face_cascade_name = "haarcascade_frontalface_alt.xml";
String eyes_cascade_name = "haarcascade_eye_tree_eyeglasses.xml";
CascadeClassifier face_cascade;
CascadeClassifier eyes_cascade;
string window_name = "Capture - Face detection";
RNG rng(12345);
/** #function main */
int main( int argc, const char** argv )
{
CvCapture* capture;
Mat frame;
//-- 1. Load the cascades
if( !face_cascade.load( face_cascade_name ) ){ printf("--(!)Error loading\n"); return -1; };
if( !eyes_cascade.load( eyes_cascade_name ) ){ printf("--(!)Error loading\n"); return -1; };
//-- 2. Read the video stream
capture = cvCaptureFromCAM( -1 );
if( capture )
{
while( true )
{
frame = cvQueryFrame( capture );
//-- 3. Apply the classifier to the frame
if( !frame.empty() )
{ detectAndDisplay( frame ); }
else
{ printf(" --(!) No captured frame -- Break!"); break; }
int c = waitKey(10);
if( (char)c == 'c' ) { break; }
}
}
return 0;
}
/** #function detectAndDisplay */
void detectAndDisplay( Mat frame )
{
std::vector<Rect> faces;
Mat frame_gray;
cvtColor( frame, frame_gray, CV_BGR2GRAY );
equalizeHist( frame_gray, frame_gray );
//-- Detect faces
face_cascade.detectMultiScale( frame_gray, faces, 1.1, 2, 0|CV_HAAR_SCALE_IMAGE, Size(30, 30) );
for( size_t i = 0; i < faces.size(); i++ )
{
Point center( faces[i].x + faces[i].width*0.5, faces[i].y + faces[i].height*0.5 );
ellipse( frame, center, Size( faces[i].width*0.5, faces[i].height*0.5), 0, 0, 360, Scalar( 255, 0, 255 ), 4, 8, 0 );
Mat faceROI = frame_gray( faces[i] );
std::vector<Rect> eyes;
//-- In each face, detect eyes
eyes_cascade.detectMultiScale( faceROI, eyes, 1.1, 2, 0 |CV_HAAR_SCALE_IMAGE, Size(30, 30) );
for( size_t j = 0; j < eyes.size(); j++ )
{
Point center( faces[i].x + eyes[j].x + eyes[j].width*0.5, faces[i].y + eyes[j].y + eyes[j].height*0.5 );
int radius = cvRound( (eyes[j].width + eyes[j].height)*0.25 );
circle( frame, center, radius, Scalar( 255, 0, 0 ), 4, 8, 0 );
}
}
//-- Show what you got
imshow( window_name, frame );
}
The error for me arises on line 38 "frame = cvQueryFrame( capture );"
the "=" is underlined red and gives the error message displayed in the title of the question
I'm sorry if the code is not displayed correctly, this is my first time asking a question.
no fear, it's not exactly your fault, - you stumbled over outdated tutorial code, the arcane c-api is no more adequate today(and won't work with 3.0).
please replace :
CvCapture* capture;
capture = cvCaptureFromCAM( -1 );
if( capture )
{
with:
VideoCapture capture(-1);
if (capture.isOpened())
{
and:
frame = cvQueryFrame( capture );
with:
capture.read(frame);
also, opencv3.0 docs: http://docs.opencv.org/ref/master/
(your sample code is from 2.4.x)

Visual C++ express 2010 The procedure entry point ??1task_group_context#tbb##QAE#XZ could not be located in the dynamic link library tbb.dll

Can someone help me out with this error?
I tried researching on the internet and tried the different methods to resolve the problem (eg: uninstalling other versions of visual c++, adding codes, etc), but none of them seem to work :(
What I have done:
under c/c++-->general-->additional include directories-->C:\OpenCV2.3\build\include;C:\OpenCV2.3\build\include\opencv2;C:\OpenCV2.3\build\include\opencv;C:\OpenCV2.3\opencv\data\haarcascades
under linker-->general-->additional library directories-->C:\OpenCV2.3\build\x86\vc9\lib;C:\OpenCV2.3\opencv\data\haarcascades;%(AdditionalLibraryDirectories)
under linker-->input-->additional dependencies--> added opencv_core230.lib;opencv_highgui230.lib;opencv_objdetect230.lib
under debugging-->command arguments -->added --cascade="C:/Program Files/OpenCV/data/haarcascades/haarcascade_frontalface_alt.xml"testimg.jpg
The code:
#include <cv.h>
#include <highgui.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <math.h>
#include <float.h>
#include <limits.h>
#include <time.h>
#include <ctype.h>
// Create memory for calculations
static CvMemStorage* storage = 0;
// Create a new Haar classifier
static CvHaarClassifierCascade* cascade = 0;
// Function prototype for detecting and drawing an object from an image
void detect_and_draw( IplImage* image );
// Create a string that contains the cascade name
const char* cascade_name = "haarcascade_frontalface_alt.xml";
/* "haarcascade_profileface.xml";*/
// Main function, defines the entry point for the program.
int main( int argc, char** argv )
{
// Structure for getting video from camera or avi
CvCapture* capture = 0;
// Images to capture the frame from video or camera or from file
IplImage *frame, *frame_copy = 0;
/* IplImage* img = cvLoadImage( "testimg.jpg" );
cvNamedWindow( "MyJPG", CV_WINDOW_AUTOSIZE );
cvShowImage("MyJPG", img);
cvWaitKey(0);
cvReleaseImage( &img );
cvDestroyWindow( "MyJPG" );
*/
// Used for calculations
int optlen = strlen("--cascade=");
// Input file name for avi or image file.
const char* input_name;
// Check for the correct usage of the command line
if( argc > 1 && strncmp( argv[1], "--cascade=", optlen ) == 0 )
{
cascade_name = argv[1] + optlen;
input_name = argc > 2 ? argv[2] : 0;
}
else
{
fprintf( stderr,
"Usage: facedetect --cascade=\"<cascade_path>\" [filename|camera_index]\n" );
return -1;
/*input_name = argc > 1 ? argv[1] : 0;*/
}
// Load the HaarClassifierCascade
cascade = (CvHaarClassifierCascade*)cvLoad( cascade_name, 0, 0, 0 );
// Check whether the cascade has loaded successfully. Else report and error and quit
if( !cascade )
{
fprintf( stderr, "ERROR: Could not load classifier cascade\n" );
return -1;
}
// Allocate the memory storage
storage = cvCreateMemStorage(0);
// Find whether to detect the object from file or from camera.
if( !input_name || (isdigit(input_name[0]) && input_name[1] == '\0') )
capture = cvCaptureFromCAM( !input_name ? 0 : input_name[0] - '0' );
else
capture = cvCaptureFromAVI( input_name );
// Create a new named window with title: result
cvNamedWindow( "result", 1 );
// Find if the capture is loaded successfully or not.
// If loaded succesfully, then:
if( capture )
{
// Capture from the camera.
for(;;)
{
// Capture the frame and load it in IplImage
if( !cvGrabFrame( capture ))
break;
frame = cvRetrieveFrame( capture );
// If the frame does not exist, quit the loop
if( !frame )
break;
// Allocate framecopy as the same size of the frame
if( !frame_copy )
frame_copy = cvCreateImage( cvSize(frame->width,frame->height),
IPL_DEPTH_8U, frame->nChannels );
// Check the origin of image. If top left, copy the image frame to frame_copy.
if( frame->origin == IPL_ORIGIN_TL )
cvCopy( frame, frame_copy, 0 );
// Else flip and copy the image
else
cvFlip( frame, frame_copy, 0 );
// Call the function to detect and draw the face
detect_and_draw( frame_copy );
// Wait for a while before proceeding to the next frame
if( cvWaitKey( 10 ) >= 0 )
break;
}
// Release the images, and capture memory
cvReleaseImage( &frame_copy );
cvReleaseCapture( &capture );
}
// If the capture is not loaded succesfully, then:
else
{
// Assume the image to be lena.jpg, or the input_name specified
const char* filename = input_name ? input_name : (char*)"testimg.jpg";
// Load the image from that filename
IplImage* image = cvLoadImage( filename, 1 );
// If Image is loaded succesfully, then:
if( image )
{
// Detect and draw the face
detect_and_draw( image );
// Wait for user input
cvWaitKey(0);
// Release the image memory
cvReleaseImage( &image );
}
else
{
/* assume it is a text file containing the
list of the image filenames to be processed - one per line */
FILE* f = fopen( filename, "rt" );
if( f )
{
char buf[1000+1];
// Get the line from the file
while( fgets( buf, 1000, f ) )
{
// Remove the spaces if any, and clean up the name
int len = (int)strlen(buf);
while( len > 0 && isspace(buf[len-1]) )
len--;
buf[len] = '\0';
// Load the image from the filename present in the buffer
image = cvLoadImage( buf, 1 );
// If the image was loaded succesfully, then:
if( image )
{
// Detect and draw the face from the image
detect_and_draw( image );
// Wait for the user input, and release the memory
cvWaitKey(0);
cvReleaseImage( &image );
}
}
// Close the file
fclose(f);
}
}
}
// Destroy the window previously created with filename: "result"
cvDestroyWindow("result");
// return 0 to indicate successfull execution of the program
return 0;
}
// Function to detect and draw any faces that is present in an image
void detect_and_draw( IplImage* img )
{
int scale = 1;
// Create a new image based on the input image
IplImage* temp = cvCreateImage( cvSize(img->width/scale,img->height/scale), 8, 3 );
// Create two points to represent the face locations
CvPoint pt1, pt2;
int i;
// Clear the memory storage which was used before
cvClearMemStorage( storage );
// Find whether the cascade is loaded, to find the faces. If yes, then:
if( cascade )
{
// There can be more than one face in an image. So create a growable sequence of faces.
// Detect the objects and store them in the sequence
CvSeq* faces = cvHaarDetectObjects( img, cascade, storage,
1.1, 2, CV_HAAR_DO_CANNY_PRUNING,
cvSize(40, 40) );
// Loop the number of faces found.
for( i = 0; i < (faces ? faces->total : 0); i++ )
{
// Create a new rectangle for drawing the face
CvRect* r = (CvRect*)cvGetSeqElem( faces, i );
// Find the dimensions of the face,and scale it if necessary
pt1.x = r->x*scale;
pt2.x = (r->x+r->width)*scale;
pt1.y = r->y*scale;
pt2.y = (r->y+r->height)*scale;
// Draw the rectangle in the input image
cvRectangle( img, pt1, pt2, CV_RGB(255,0,0), 3, 8, 0 );
}
}
// Show the image in the window named "result"
cvShowImage( "result", img );
// Release the temp image created.
cvReleaseImage( &temp );
}
The error message says, that a certain symbol could not be found in an external library, tbb.dll. The library (the dll) itself seems to be found.
The library is Threading building blocks and your error message hints to a mismatch between header and the used dll, for example because of multiple versions installed etc. You should find out, if the correct dll is used at runtime (check the modules window in VS, or use Dependency Walker for that).
To point the runtime application to the correct path of tbb.dll, you might put the directory in your PATH environment variable, or put the tbb.dll side by side to the Executable.

Opencv 2.4 compilation error with objectdetect.hpp

I have installed OpenCV using the instructions provided on the wiki using cmake. I have built the files on my desktop. The first program that I tried to run was a simple capture from camera program. Its source is
#include "cv.h"
#include "highgui.h"
#include <stdio.h>
int main() {
CvCapture* capture = cvCaptureFromCAM( CV_CAP_ANY );
if ( !capture ) {
fprintf( stderr, "ERROR: capture is NULL \n" );
getchar();
return -1;
}
cvNamedWindow( "mywindow", CV_WINDOW_AUTOSIZE );
while ( 1 ) {
IplImage* frame = cvQueryFrame( capture );
if ( !frame ) {
fprintf( stderr, "ERROR: frame is null...\n" );
getchar();
break;
}
cvShowImage( "Cam WIndow", frame );
if ( (cvWaitKey(10) & 255) == 27 ) break;
}
cvReleaseCapture( &capture );
cvDestroyWindow( "Cam WIndow" );
return 0;
}
It is compiling properly with the g++ command with pkg-config provided below:
g++ -o cam Camera.cpp pkg-config opencv --cflags --libs
The second program that I have tried to run is also fom there wiki, the face recognition program, its source is given below.
#include <opencv2/objdetect/objdetect.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
#include <stdio.h>
using namespace std;
using namespace cv;
void detectAndDisplay( Mat frame );
String face_cascade_name = "lbpcascade_frontalface.xml";
String eyes_cascade_name = "haarcascade_eye_tree_eyeglasses.xml";
CascadeClassifier face_cascade;
CascadeClassifier eyes_cascade;
string window_name = "Capture - Face detection";
RNG rng(12345);
int main( int argc, const char** argv )
{
CvCapture* capture;
Mat frame;
if( !face_cascade.load( face_cascade_name ))
{
printf("--(!)Error loading\n");
return -1;
};
if( !eyes_cascade.load( eyes_cascade_name ))
{
printf("--(!)Error loading\n");
return -1;
};
capture = cvCaptureFromCAM( -1 );
if( capture )
{
while( true )
{
frame = cvQueryFrame( capture );
if( !frame.empty() )
{ detectAndDisplay( frame ); }
else
{ printf(" --(!) No captured frame -- Break!"); break; }
int c = waitKey(10);
if( (char)c == 'c' ) { break; }
}
}
return 0;
}
void detectAndDisplay( Mat frame )
{
std::vector<Rect> faces;
Mat frame_gray;
cvtColor( frame, frame_gray, CV_BGR2GRAY );
equalizeHist( frame_gray, frame_gray );
face_cascade.detectMultiScale( frame_gray, faces, 1.1, 2, 0, Size(80, 80) );
for( int i = 0; i < faces.size(); i++ )
{
Mat faceROI = frame_gray( faces[i] );
std::vector<Rect> eyes;
eyes_cascade.detectMultiScale(faceROI,eyes,1.1,2,0|CV_HAAR_SCALE_IMAGE,Size(30, 30));
if( eyes.size() == 2)
{
Point center( faces[i].x + faces[i].width*0.5, faces[i].y + faces[i].height*0.5 );
ellipse(frame,center,Size(faces[i].width*0.5,faces[i].height*0.5),0,0,360,Scalar(255,0,0),2,8,0);
for( int j = 0; j < eyes.size(); j++ )
{ \
Point center( faces[i].x + eyes[j].x + eyes[j].width*0.5, faces[i].y + eyes[j].y + eyes[j].height*0.5 );
int radius = cvRound( (eyes[j].width + eyes[j].height)*0.25 );
circle( frame, center, radius, Scalar( 255, 0, 255 ), 3, 8, 0 );
}
}
}
imshow( window_name, frame );
}
Now this program I compiled using the command given below:
g++ -o cam Cam1.cpp -lopencv_core -lopencv_imgproc -lopencv_calib3d -lopencv_video -lopencv_features2d -lopencv_ml -lopencv_highgui -lopencv_objdetect -lopencv_contrib -lopencv_legacyD
This compilation command gives the error
fatal error: opencv2/objdetect/objdetect.hpp: No such file or directory
What to do?
The error is because of the compiler couldn't find the file "objdetect.hpp". There might be two reasons for that.
1)The file "objdetect.hpp" will be generated during the installation process of the opencv, so if there any problem at this step the file might haven't created, so first check for that file.
2)If you could find that file, then the problem will be due to the compiler couldn't get the path to the file, so you have to fix it. It can be done by either include the exact path to the list of included paths in the make file for the objectdetcet module using -I/path/to/the/file.
If you don't have such a make file then you can specify the path through command line using the above -I/ Option.
It can also be done in another way by exporting the path to some flag(I don't know the name of the flag),so that the compiler will look into that path exported , during the compile time,I am not sure about this method ,Please check it in internet.
Hope that you can fix the problem with this ..

trouble with output directory for OpenCV VideoWriters

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);
}
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
);