opencv and c++ visual studio 2012 -


i have code work good.

when video length less 1 minute , video size 165 kb when change video other length 2 minute , size 15 mb or 1 same length size 5 mb show me

project has stop working

this code

# include "windows.h"  # ifdef _ch_  # pragma package < opencv >  # endif  # include "windows.h"  # ifndef _eic  # include "cv.h"  # include "cvaux.h"  # include "highgui.h"  # include "cxcore.h"  # include < stdio.h >  # include < ctype.h >  # endif    // x?y?  int getpixel ( iplimage * image , int x , int y , int * h , int * s , int * v ) {  * h = ( uchar ) image -> imagedata [ y * image -> widthstep + x * image -> nchannels ] ;  * s = ( uchar ) image -> imagedata [ y * image -> widthstep + x * image -> nchannels + 1 ] ;  * v = ( uchar ) image -> imagedata [ y * image -> widthstep + x * image -> nchannels + 2 ] ;  return 0 ;  }  //--------------------------------------------------------------------------------     int main ( int argc , char * * argv ) {  cvcapture * capture = cvcapturefromavi("a.avi") ;  iplimage * image = 0;  iplimage * hsv = 0 ;   /* iplimage* img = cvloadimage("greatwave.png", 1); mat mtx(img); // convert iplimage* -> mat */ if ( argc == 1 || ( argc == 2 && strlen ( argv [ 1 ] ) == 1 && isdigit ( argv [ 1 ] [ 0 ] ) ) ) {  //capture = cvcapturefromcam ( argc == 2 ? argv [ 1 ] [ 0 ] - '0' : 0 ) ;  }  else if ( argc == 2 ) {  //capture = cvcapturefromavi ( argv [ 1 ] ) ;  }   if ( !capture ) {  fprintf ( stderr , "could not initialize capturing.../n" ) ;  return - 1 ;  }   printf ( "hot keys: /n" "/tesc - quit program/n" ) ;   //normal  cvnamedwindow ( "normal" , cv_window_autosize ) ;    //condensation-------------------------------------------------   int dp = 2 ; //   int mp = 2 ; //   int samplesnum = 300 ; //    cvcondensation * condens = cvcreatecondensation ( dp , mp , samplesnum ) ;  //-----------------------------------------------------------------------    //condensation-----------------------------------   cvmat * lowerbound ; //   cvmat * upperbound ; //   lowerbound = cvcreatemat ( 2 , 1 , cv_32f ) ;  upperbound = cvcreatemat ( 2 , 1 , cv_32f ) ;  //640*480   cvmset ( lowerbound , 0 , 0 , 0.0 ) ;  cvmset ( upperbound , 0 , 0 , 640.0 );  cvmset ( lowerbound , 1 , 0 , 0.0 ) ;  cvmset ( upperbound , 1 , 0 , 480.0 ) ;   cvcondensinitsampleset ( condens , lowerbound , upperbound ) ;  //-----------------------------------------------------------------------    //------------------------------   ( int = 0 ; < samplesnum ; i++ ) {  condens -> flsamples [ ] [ 0 ] += 320.0 ;  condens -> flsamples [ ] [ 1 ] += 240.0 ;  }  //-----------------------------------------------------------------------    //----------------------------   condens -> dynammatr [ 0 ] = 1.0 ; condens->dynammatr [ 1 ] = 0.0 ;  condens -> dynammatr [ 2 ] = 0.0 ; condens->dynammatr [ 3 ] = 1.0 ;  //-----------------------------------------------------------------------    ( ;; ) {  iplimage* frame = 0 ;  int c ;  int x , y , xx , yy ;  int h , s , v ;   frame = cvqueryframe ( capture ) ;  if ( !frame ) {  break ;  }   if ( !image ) {  image = cvcreateimage ( cvgetsize ( frame ) , 8 , 3 ) ;  image -> origin = frame -> origin ;  hsv = cvcreateimage ( cvgetsize ( frame ) , 8 , 3 ) ;  hsv -> origin = frame -> origin ;  }   cvcopy ( frame , image , 0 ) ;  cvcvtcolor ( image , hsv , cv_bgr2hsv ) ;   //?---------------------------------------------------   ( int = 0 ; < samplesnum ; i++ ) {   x = ( int ) condens -> flsamples [ ] [ 0 ] ;  y = ( int ) condens -> flsamples [ ] [ 1 ] ;   if ( x >= 0 && x <= 640 && y >= 0 && y <= 480 ) { //  getpixel ( hsv , x , y , &h , &s , & v ) ;  if ( h <= 19 && s >= 48 ) { // //h<=19 s>=48   cvcircle ( image , cvpoint ( x , y ) , 4 , cv_rgb ( 255 , 0 , 0 ) , 1 ) ;  condens -> flconfidence [ ] = 1.0 ;  }  else {  condens -> flconfidence [ ] = 0.0 ;  }  }  else {  condens -> flconfidence [ ] = 0.0 ;  }  }   //--------------------------------------------------------------------------    //  cvcondensupdatebytime ( condens ) ;   cvshowimage ( "normal" , image ) ;  c = cvwaitkey ( 20 ) ;   if ( c == 27 ) {  break ;  }  }   //------------------------------------   cvreleaseimage ( &image ) ;  cvreleaseimage ( &hsv ) ;  cvreleasecondensation ( &condens ) ;  cvreleasemat ( &lowerbound ) ;  cvreleasemat ( &upperbound ) ;  cvreleasecapture ( &capture ) ;  cvdestroywindow ( "normal" ) ;   //---------------------------------------------    return 0 ;  }   # ifdef _eic  main ( 1 , "condensation.cpp" ) ;  # endif  

also when o comment

  ( int = 0 ; < samplesnum ; i++ ) {       x = ( int ) condens -> flsamples [ ] [ 0 ] ;      y = ( int ) condens -> flsamples [ ] [ 1 ] ;       if ( x >= 0 && x <= 640 && y >= 0 && y <= 480 ) { //      getpixel ( hsv , x , y , &h , &s , & v ) ;      if ( h <= 19 && s >= 48 ) { // //h<=19 s>=48       cvcircle ( image , cvpoint ( x , y ) , 4 , cv_rgb ( 255 , 0 , 0 ) , 1 ) ;      condens -> flconfidence [ ] = 1.0 ;      }      else {      condens -> flconfidence [ ] = 0.0 ;      }      }      else {      condens -> flconfidence [ ] = 0.0 ;      }      }  

program work without idea of track object

i have windows 8

please comment if u dont understand thing

i think problem related declaration of iplimage *frame inside for loop. when size of video length increases then, memory gets full. because continuously creating new frames inside for loop without freeing memory allocated them.

you should declare iplimage *frame outside for loop , release memory allocated outside for loop.

advice: not use old c-standards of opencv. use new c++ standards have declare image mat image. then, don't need think freeing memory because stuff itself.


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -