"Espace insuffisant pour traiter cette commande"
* Bonjour *
Citation:
Espace insuffisant pour traiter cette commande
Voilà l'erreur qui apparait après quelques minutes pendant lesquelles mon programme delphi tourne avec un algorithme qui sert à détecter des mouvements sur une caméra.
Code:
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
| function detecter_mouvement_camera(image_camera_actuelle,image_camera_precedente:TBitmap):Integer;
var i,j,difference,noise:integer;
var pixelPointer1,pixelPointer2:PByteArray;
begin
difference:=0;
i:=0; j:=0;
MaFeuille := MonClasseur.GetByName('Feuille6');
Cellule := Mafeuille.getCellByPosition(1,262);
noise:=Cellule.GetValue;
while (image_camera_actuelle.Height-1>i) do
begin
pixelPointer1:=image_camera_actuelle.ScanLine[i];
pixelPointer2:=image_camera_precedente.ScanLine[i];
while (image_camera_actuelle.Width-1>j) do
begin
if (ABS(pixelPointer1[3*j]-pixelPointer2[3*j])>=noise) AND (ABS(pixelPointer1[2*j]-pixelPointer2[2*j])>=noise) AND (ABS(pixelPointer1[1*j]-pixelPointer2[1*j])>=noise) then difference:=difference+1;
j:=j+5;
end;
i:=i+5;
end;
Cellule := Mafeuille.getCellByPosition(1,263);
Cellule.SetValue(difference);
result:=difference;
end;
procedure TForm1.Timer2Timer(Sender: TObject);
var SPS: TSystemPowerStatus;
var val:Integer;
var seuil1,seuil2:Integer;
var image_camera_actuelle:Tbitmap;
begin
if webcam_initialisation=True then
begin
if camera_affichage=False then Form1.Image29.Visible:=False;
if (camera_affichage=True) and (Edit1.Text='') then
begin
image_camera_actuelle:=Tbitmap.Create;
MaFeuille := MonClasseur.GetByName('Feuille6');
Cellule := Mafeuille.getCellByPosition(1,260);
seuil1:=Cellule.GetValue;
Cellule := Mafeuille.getCellByPosition(1,261);
seuil2:=Cellule.GetValue;
sendmessage(hcam,1084,0,0);
sendmessage(hcam,1054,0,0);
Form1.image29.Picture.LoadFromClipboardFormat(cf_bitmap,clipboard.GetAsHandle(cf_bitmap),0);
image_camera_actuelle.FreeImage;
FreeAndNil(image_camera_actuelle);
image_camera_actuelle:=TBitmap.Create;
image_camera_actuelle.Assign(Form1.image29.Picture.Bitmap);
if bascule=True then begin image_camera_precedente.Assign(image_camera_actuelle); bascule:=False; end;
if (detecter_mouvement_camera(image_camera_actuelle,image_camera_precedente)>=seuil2) and (mouvement_devant_camera=False) then begin mouvement_devant_camera:=True; affiche_6(256); image_camera_precedente.FreeImage; FreeAndNil(image_camera_precedente); image_camera_precedente:=TBitmap.Create; image_camera_precedente.Assign(image_camera_actuelle); exit; end;
if (detecter_mouvement_camera(image_camera_actuelle,image_camera_precedente)<seuil1) and (mouvement_devant_camera=True) then begin mouvement_devant_camera:=False; affiche_6(257); image_camera_precedente.FreeImage; FreeAndNil(image_camera_precedente); image_camera_precedente:=TBitmap.Create; image_camera_precedente.Assign(image_camera_actuelle); exit; end;
image_camera_precedente.FreeImage;
FreeAndNil(image_camera_precedente);
image_camera_precedente:=TBitmap.Create;
image_camera_precedente.Assign(Form1.image29.Picture.Bitmap);
end;
end;
end; |
C'est la fonction TForm1.Timer2Timer(Sender: TObject); qui à intervalles réguliers (1/2 seconde) prend une image de la webcam et la compare à l'image précédente.
Le programme fonctionne très bien pendant quelques minutes. Et puis ça plante, l'erreur "Espace insuffisant pour traiter cette commande" se répète en boucle...
J'ai pourtant mis des FreeImage et FreeAndNil mais il n'y a rien à faire...