Beastbdog Member
Posts : 4 Join date : 2011-05-20
| Subject: OpenCV Segfaulting Thu Jul 14, 2011 12:25 am | |
| Hi, I've just got cracking with OpenCV- I got basic single frame capture and image writing to work no problem. What I'm trying to do now is sort of like a logger- capture frame by frame and record in files. My code segfaults with the saving line in, but seems to run with it commented.. Here's the code: - Code:
-
#include <stdio.h> #include <iostream> #include <time.h> //OpenCV #include <cv.h> #include <cvaux.h> #include <highgui.h> #include <cxcore.h>
char* image_name (const int cam_number) { char* filestamp; struct tm *current; time_t now; time(&now); current = localtime(&now); sprintf(filestamp, "images/%i-%i-%i-%i-Cam%i.png", current->tm_yday, current->tm_hour, current->tm_min, current->tm_sec, cam_number); return filestamp; }
class camera { public: int cam_number; //x where /dev/videox is camera CvCapture *capture; IplImage *image; CvCapture* init(); IplImage* image_grab(); }camera1;
CvCapture* camera::init(){ capture = cvCaptureFromCAM(cam_number); return capture; }
IplImage* camera::image_grab(){ image = cvQueryFrame(capture); cvSaveImage(image_name(cam_number), image); return image; } int main (int argc, char *argv[]) { bool run = true; char input; camera1.cam_number = 3;
camera1.init(); while(run){ camera1.image_grab(); printf("Iteration \n"); } return 0; }
Thanks for any ideas. |
|
Zoe_Baby Member
Posts : 17 Join date : 2011-06-05
| Subject: Re: OpenCV Segfaulting Thu Jul 14, 2011 12:26 am | |
| In your image_name function you never allocate any memory for filestamp. That is why it is crashing. |
|
Beastbdog Member
Posts : 4 Join date : 2011-05-20
| Subject: Re: OpenCV Segfaulting Thu Jul 14, 2011 12:27 am | |
| Oh great, thanks a lot All working now. :D |
|
Sponsored content
| Subject: Re: OpenCV Segfaulting | |
| |
|