Kinect test v1

Description

Driver et function de base de Kinect de microsoft contrôlé par windows
le fichier d'install avec le driver et le fichier DLL et a cette adresse
http://codelaboratories.com/get/nui/
j'utilise pas la dernier version qu'il y a car je la trouve moins stable
il met un peut de temps à se lancer et ce couper mai il fonctionne très bien
tout critique ou aide ou autre sera la bien venu
j'utilise delphi 2010 pro
j'ai mi aussi les 2 fichier texte qui son les emplacement de Z en fonction de la couleur il son pas encore trop précis et il me manque certain point il son plus précis quand limage du depth et en RAW
j'ai mit le fichier dll mai j'ai pas trouver les source et il a été écrit en C si je me trompe pas
vila ^^
cordialement FFcast

Source / Exemple :


unit kinect;

interface

uses Windows, Graphics;

type
  CLNUIMotor = record
    Handle: ^integer;
  end;

type
  CLNUICamera = record
    Handle: ^integer;
  end;

type
  pLigScan = ^tLigScan;
  tLigScan = array [Word] of TRGBTriple;

type
  CLNUIDepth = record
    tableau: array [0 .. 640, 0 .. 480] of ^byte;
  end;

type
  CLNUIcolor = record
    tableau: array [0 .. 640, 0 .. 480] of ^byte;
  end;

function CreateNUIMotor(): CLNUIMotor; cdecl; external 'CLNUIDevice.dll';
function CreateNUICamera(): CLNUICamera; cdecl; external 'CLNUIDevice.dll';
function DestroyNUIMotor(Pointe: CLNUIMotor): Boolean; cdecl;
external 'CLNUIDevice.dll';
function DestroyNUICamera(Pointe: CLNUICamera): Boolean; cdecl;
external 'CLNUIDevice.dll';
function GetNUIMotorSerial(Pointe: CLNUIMotor): Pansichar; cdecl;
external 'CLNUIDevice.dll';
function SetNUIMotorPosition(Pointe: CLNUIMotor; Valeur: integer): Boolean;
  cdecl; external 'CLNUIDevice.dll';
function GetNUIMotorAccelerometer(Pointe: CLNUIMotor; var Valeur_X: short;
  var Valeur_Y: short; var Valeur_Z: short): Boolean; cdecl;
external 'CLNUIDevice.dll';
function SetNUIMotorLED(Pointe: CLNUIMotor; Valeur_Led: byte): Boolean; cdecl;
external 'CLNUIDevice.dll';
function StartNUICamera(Pointe: CLNUICamera): Boolean; cdecl;
external 'CLNUIDevice.dll';
function StopNUICamera(Pointe: CLNUICamera): Boolean; cdecl;
external 'CLNUIDevice.dll';
function GetNUICameraDepthFrameRAW(Pointe: CLNUICamera; var pData: CLNUIDepth;
  waitTimeout: integer = 2000): Boolean; cdecl; external 'CLNUIDevice.dll';
function GetNUICameraDepthFrameRGB32(Pointe: CLNUICamera;
  var pData: CLNUIDepth; waitTimeout: integer = 2000): Boolean; cdecl;
external 'CLNUIDevice.dll';
function GetNUICameraColorFrameRAW(Pointe: CLNUICamera; var pData: CLNUIcolor;
  waitTimeout: integer = 2000): Boolean; cdecl; external 'CLNUIDevice.dll';
function GetNUICameraColorFrameRGB24(Pointe: CLNUICamera;
  var pData: CLNUIcolor; waitTimeout: integer = 2000): Boolean; cdecl;
external 'CLNUIDevice.dll';
function GetNUICameraColorFrameRGB32(Pointe: CLNUICamera;
  var pData: CLNUIcolor; waitTimeout: integer = 2000): Boolean; cdecl;
external 'CLNUIDevice.dll';

procedure BytesArrayToBitmapDepth(const BytesArray: CLNUIDepth;
  const w, h: integer; Bitmap: TBitmap);
procedure BytesArrayToBitmapColor(const BytesArray: CLNUIcolor;
  const w, h: integer; const PixelFormat: TPixelFormat; Bitmap: TBitmap);
procedure RotationPicture(PictureSource, PictureCible: TPicture);
procedure BmpCopierSauf(const bmpSrc: TPicture; Seuil: integer;
  bmpfinal: TPicture);

implementation

procedure BmpCopierSauf(const bmpSrc: TPicture; Seuil: integer;
  bmpfinal: TPicture);
var
  X, Y: integer;
  LigS, LigD: pLigScan;
  Coleur: Tcolor;
  imgtempon: TBitmap;
begin
  if bmpSrc = nil then
    EXIT;
  imgtempon := TBitmap.Create;
  with imgtempon do
  begin
    PixelFormat := pf24Bit;
    width := bmpSrc.width;
    height := bmpSrc.height;
  end;
  try
    for Y := 0 to bmpSrc.height - 1 do
    begin
      LigS := bmpSrc.Bitmap.ScanLine[Y];
      LigD := imgtempon.ScanLine[Y];
      for X := 0 to bmpSrc.width - 1 do
      begin
        Coleur := RGB(LigS[X].rgbtRed, LigS[X].rgbtGreen, LigS[X].rgbtBlue);
        LigD[X].rgbtBlue := 0;
        LigD[X].rgbtGreen := 0;
        LigD[X].rgbtRed := 0;
        if (Coleur >= Seuil) then
          LigD[X] := LigS[X];
        if (Coleur >= Seuil + 1) then
        begin
          LigD[X].rgbtBlue := 255;
          LigD[X].rgbtGreen := 0;
          LigD[X].rgbtRed := 0;
        end;
      end;
    end;
    bmpfinal.Assign(imgtempon);
  finally
    imgtempon.Free;
  end;
end;

procedure RotationPicture(PictureSource, PictureCible: TPicture);
type
  TRGBArray = ARRAY [0 .. 10000] of TRGBTriple;
  pTRGBArray = ^TRGBArray;
  TArrayLigneCible = Array [0 .. 10000] of pTRGBArray;
var
  BmpTempSource, BmpTemCible: TBitmap;
  X, Y: integer;
  LigneSource, LigneCible: pTRGBArray;
begin
  BmpTempSource := TBitmap.Create;
  BmpTemCible := TBitmap.Create;
  try
    BmpTempSource.Assign(PictureSource.Graphic);
    BmpTempSource.PixelFormat := pf24Bit;
    BmpTemCible.PixelFormat := pf24Bit;
    BmpTemCible.height := BmpTempSource.height;
    BmpTemCible.width := BmpTempSource.width;
    for Y := 0 to BmpTempSource.height - 1 do
    begin
      LigneSource := BmpTempSource.ScanLine[Y];
      LigneCible := BmpTemCible.ScanLine[BmpTempSource.height - Y - 1];
      for X := 0 to BmpTempSource.width - 1 do
      begin
        LigneCible[X] := LigneSource[BmpTempSource.width - 1 - X];
      end;
    end;
    PictureCible.Assign(BmpTemCible);
  finally
    BmpTempSource.Free;
    BmpTemCible.Free;
  end;
end;

procedure BytesArrayToBitmapColor(const BytesArray: CLNUIcolor;
  const w, h: integer; const PixelFormat: TPixelFormat; Bitmap: TBitmap);
var
  TBmp: TBitmap;
  pX: ^byte;
  LZ: integer;
begin
  TBmp := TBitmap.Create;
  try
    case PixelFormat of
      pf8bit:
        LZ := (Bitmap.width * Bitmap.height);
      pf16bit:
        LZ := (Bitmap.width * Bitmap.height) * 2;
      pf24Bit:
        LZ := (Bitmap.width * Bitmap.height) * 3;
      pf32Bit:
        LZ := (Bitmap.width * Bitmap.height) * 4;
    end;
    TBmp.PixelFormat := PixelFormat;
    TBmp.width := w;
    TBmp.height := h;
    pX := TBmp.ScanLine[TBmp.height - 1];
    CopyMemory(pX, @BytesArray.tableau[0], LZ);
    Bitmap.Assign(TBmp);
  finally
    TBmp.Free;
  end;
end;

procedure BytesArrayToBitmapDepth(const BytesArray: CLNUIDepth;
  const w, h: integer; Bitmap: TBitmap);
var
  TBmp: TBitmap;
  pX: ^byte;
  LZ: integer;
begin
  TBmp := TBitmap.Create;
  try
    LZ := (Bitmap.width * Bitmap.height) * 4;
    TBmp.PixelFormat := pf32Bit;
    TBmp.width := w;
    TBmp.height := h;
    pX := TBmp.ScanLine[TBmp.height - 1];
    CopyMemory(pX, @BytesArray.tableau[0], LZ);
    Bitmap.Assign(TBmp);
  finally
    TBmp.Free;
  end;
end;

end.

Codes Sources

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.