Easy A
Would you like to react to this message? Create an account in a few clicks or log in to continue.


 
HomeHome  Latest imagesLatest images  SearchSearch  RegisterRegister  Log inLog in  

Share
 

 OpenCV Segfaulting

View previous topic View next topic Go down 
AuthorMessage
Beastbdog
Member
Member
Beastbdog

Posts : 4
Join date : 2011-05-20

OpenCV Segfaulting Empty
PostSubject: OpenCV Segfaulting   OpenCV Segfaulting EmptyThu 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.
Back to top Go down
Zoe_Baby
Member
Member
Zoe_Baby

Posts : 17
Join date : 2011-06-05

OpenCV Segfaulting Empty
PostSubject: Re: OpenCV Segfaulting   OpenCV Segfaulting EmptyThu Jul 14, 2011 12:26 am

In your image_name function you never allocate any memory for filestamp. That is why it is crashing.
Back to top Go down
Beastbdog
Member
Member
Beastbdog

Posts : 4
Join date : 2011-05-20

OpenCV Segfaulting Empty
PostSubject: Re: OpenCV Segfaulting   OpenCV Segfaulting EmptyThu Jul 14, 2011 12:27 am

Oh great, thanks a lot All working now. :D
Back to top Go down
Sponsored content




OpenCV Segfaulting Empty
PostSubject: Re: OpenCV Segfaulting   OpenCV Segfaulting Empty

Back to top Go down
 

OpenCV Segfaulting

View previous topic View next topic Back to top 
Page 1 of 1

Permissions in this forum:You cannot reply to topics in this forum
Easy A :: OpenCV Segfaulting Edit-trash Useless :: Trash-