Salut,

j'utilise openCv pour capturer le flux video(cf mon autre post) et lors du callback pour le traitement de chaque image je souhaite moyenné sur 3 images puis soustraire l'image traité et moyenné a l'image precedement traité(c'est clair? ) mais lorsque je lance le programme j'ai le droit a une OpenCV GUI error handler:

NULL Pointer (NULL array pointer is passed) in function cvGetMat

Abort, Retry, Continue?
j'ai du mal a comprendre le probleme, j'ai lu pas mal de post(sur le newsgroup d'opencv) a ce sujet et aucune solution n'est clairement expliquée! le probleme vient de la declaration et/ou de l'initialisation des IplImage semble t'il mais j'ai beau tester pleins de truc pas moyen...

si par hasard un habitué d'openCV passe par la...

Je laisse mon code au cas ou:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include "cvcam.h"
#include "highgui.h"
#include <iostream>
 
 
static int index;
 
static IplImage* backImage =0;
static IplImage* previousImage =0;   //buffer for the previous image
static IplImage* previousImage2 =0;  //buffer for the previous image of previousImage
/**************************************************************************\
            How to set video resolution programatically
\**************************************************************************/ 
void callback(IplImage* image)
{
   IplImage* image1 = image;
   IplImage* averageImage = 0;   //Resulting image of the average 
   IplImage* sumImage = 0;       //Resulting image of the addition
   IplImage* subImage = 0;       //Resulting image of the substraction
   int i,j;
   int iheight,iwidth;
   assert (image);
 
   iheight = image1->height;
   iwidth = image1->width;
 
   /* Print the original image in the window */   
   cvShowImage("Original window",image1);
 
 
   /* Initialize image */
   averageImage = cvCreateImage(cvSize(iwidth,iheight),IPL_DEPTH_8U,image1->nChannels);
   subImage = cvCreateImage(cvSize(iwidth,iheight),IPL_DEPTH_8U,image1->nChannels);
   subImage = cvCreateImage(cvSize(iwidth,iheight),IPL_DEPTH_8U,image1->nChannels);
 
   index++;               //count the number of frame
 
   /*the two first Frame need to be saved in the buffer */
   if (index < 3)
   {
       if(index == 1)
       {
          backImage = cvCreateImage(cvSize(iwidth,iheight),IPL_DEPTH_8U,image1->nChannels);
          previousImage = cvCreateImage(cvSize(iwidth,iheight),IPL_DEPTH_8U,image1->nChannels);
          previousImage2 = cvCreateImage(cvSize(iwidth,iheight),IPL_DEPTH_8U,image1->nChannels);
          backImage = image1;
       }   
       previousImage = image1;
       previousImage2 = image1;
   }
 
   /*************************************/
   /************* Treatment *************/
   /*************************************/
 
   /* AVERAGE */
   cvAdd(previousImage, image1, sumImage , NULL);
   cvAdd(sumImage, previousImage, sumImage , NULL);
   for( i=0 ; i<sumImage->widthStep ; i++ )
   {
      averageImage->imageData[i] = sumImage->imageData[i]/3;
   }
 
   /* SUB */
   cvSub (backImage, averageImage, subImage, NULL);
 
   //save the treated frames in the previous frame for the average
   previousImage2 = previousImage;
   previousImage = image1;  
}
 
 
 
int ShowCamVideo(HWND hwnd, int width, int height)
{
    VidFormat vidFmt={ width, height, 30.0};
 
    int ncams = cvcamGetCamerasCount( );
    cvcamSetProperty(0, CVCAM_PROP_ENABLE, CVCAMTRUE);
    cvcamSetProperty(0, CVCAM_PROP_CALLBACK,(void*)callback);
    cvcamSetProperty(0, CVCAM_PROP_WINDOW, &hwnd);   
 
    //Set Video Format Property
    cvcamSetProperty( 0, CVCAM_PROP_SETFORMAT, &vidFmt);
 
    if( !cvcamInit() )
        return 0;
    cvcamStart();
    return 1;
}
 
 
int main( int argc, char** argv )
{
    index = 0;
    cvNamedWindow("Original window", CV_WINDOW_AUTOSIZE);
 
    cvNamedWindow("Treated window", CV_WINDOW_AUTOSIZE);
 
    if( ShowCamVideo((HWND)cvGetWindowHandle("Treated window"), 640, 480) )
    {
        cvWaitKey(0);
        cvcamStop();
    }
    cvcamExit();
}