182 lines
4.8 KiB
Plaintext
182 lines
4.8 KiB
Plaintext
unit umain;
|
|
|
|
interface
|
|
|
|
uses
|
|
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
|
|
StdCtrls, ieview, imageenview, Buttons, ComCtrls, ExtCtrls, Menus, hyieutils, hyiedefs, imageenproc;
|
|
|
|
type
|
|
Tfmain = class(TForm)
|
|
ImageEnView1: TImageEnView;
|
|
Panel1: TPanel;
|
|
GroupBox1: TGroupBox;
|
|
Label1: TLabel;
|
|
SpeedButton1: TSpeedButton;
|
|
ComboBox1: TComboBox;
|
|
GroupBox2: TGroupBox;
|
|
Label2: TLabel;
|
|
TrackBar1: TTrackBar;
|
|
Label4: TLabel;
|
|
ListBox1: TListBox;
|
|
Label5: TLabel;
|
|
Button5: TButton;
|
|
Label3: TLabel;
|
|
Timer1: TTimer;
|
|
procedure SpeedButton1Click(Sender: TObject);
|
|
procedure TrackBar1Change(Sender: TObject);
|
|
procedure Button5Click(Sender: TObject);
|
|
procedure FormCreate(Sender: TObject);
|
|
procedure ComboBox1Change(Sender: TObject);
|
|
procedure ImageEnView1MediaFoundationNotify(Sender, MediaFoundationObject: TObject; NotifyType: TIEMediaFountationNotifyType);
|
|
procedure Timer1Timer(Sender: TObject);
|
|
private
|
|
{ Private declarations }
|
|
public
|
|
{ Public declarations }
|
|
end;
|
|
|
|
var
|
|
fmain: Tfmain;
|
|
|
|
implementation
|
|
|
|
uses
|
|
iemmf;
|
|
|
|
{$R *.DFM}
|
|
{$R WindowsTheme.res}
|
|
|
|
|
|
procedure Tfmain.FormCreate(Sender: TObject);
|
|
begin
|
|
// Fill Video Input combobox
|
|
with ImageEnView1.IO.MediaFoundationSourceReader do
|
|
begin
|
|
ComboBox1.Items.Assign(VideoInputs);
|
|
ComboBox1.ItemIndex := 0;
|
|
ComboBox1Change(self);
|
|
end;
|
|
end;
|
|
|
|
|
|
// selected a video input
|
|
procedure Tfmain.ComboBox1Change(Sender: TObject);
|
|
var
|
|
i: integer;
|
|
mediaType: TIEDictionary;
|
|
begin
|
|
if ComboBox1.ItemIndex > -1 then
|
|
begin
|
|
// Fill supported formats listbox
|
|
ListBox1.Clear();
|
|
with ImageEnView1.IO.MediaFoundationSourceReader do
|
|
begin
|
|
SetVideoInput(ComboBox1.ItemIndex);
|
|
for i := 0 to GetMediaTypesCount(mmf_VIDEO_STREAM) - 1 do
|
|
begin
|
|
mediaType := GetMediaType(mmf_VIDEO_STREAM, i);
|
|
ListBox1.Items.Add(Format('%d x %d %.1f fps (min fps: %.1f max fps: %.1f) %s', [
|
|
mediaType.GetInteger(IEFRAMEWIDTH_DICT_KEY), // width
|
|
mediaType.GetInteger(IEFRAMEHEIGHT_DICT_KEY), // height
|
|
mediaType.GetDouble(IEFRAMERATE_DICT_KEY), // default frame rate
|
|
mediaType.GetDouble(IEFRAMERATEMIN_DICT_KEY), // minimum frame rate
|
|
mediaType.GetDouble(IEFRAMERATEMAX_DICT_KEY), // maximum frame rate
|
|
mediaType.GetString(IESUBTYPE_DICT_KEY) // subtype = color space
|
|
]));
|
|
end;
|
|
end;
|
|
ListBox1.ItemIndex := 0;
|
|
SpeedButton1.Enabled := true;
|
|
end
|
|
else
|
|
SpeedButton1.Enabled := false;
|
|
end;
|
|
|
|
|
|
// Capture button
|
|
procedure Tfmain.SpeedButton1Click(Sender: TObject);
|
|
begin
|
|
if SpeedButton1.Down then
|
|
begin
|
|
// start capture
|
|
ComboBox1.Enabled := false;
|
|
ListBox1.Enabled := false;
|
|
|
|
ImageEnView1.IO.MediaFoundationSourceReader.SelectMediaType(mmf_VIDEO_STREAM, ListBox1.ItemIndex);
|
|
|
|
// auto-rotation (win8 only!)
|
|
ImageEnView1.IO.MediaFoundationSourceReader.VideoProcessor.SetMirror(mfpmHorizontal);
|
|
ImageEnView1.IO.MediaFoundationSourceReader.VideoProcessor.SetRotation(mfprNormal);
|
|
|
|
ImageEnView1.IO.MediaFoundationSourceReader.StartCapture();
|
|
|
|
// get actual video format (ie MJPEG may be converted to YUY2)
|
|
with ImageEnView1.IO.MediaFoundationSourceReader.GetCurrentMediaType(mmf_VIDEO_STREAM) do
|
|
begin
|
|
Label4.Caption := Format('Actual video format: %d x %d %.1f fps %s', [
|
|
GetInteger(IEFRAMEWIDTH_DICT_KEY), // width
|
|
GetInteger(IEFRAMEHEIGHT_DICT_KEY), // height
|
|
GetDouble(IEFRAMERATE_DICT_KEY), // frame rate
|
|
GetString(IESUBTYPE_DICT_KEY) // subtype = color space
|
|
]);
|
|
end;
|
|
end
|
|
else
|
|
begin
|
|
// stop capture
|
|
ImageEnView1.IO.MediaFoundationSourceReader.StopCapture();
|
|
ComboBox1.Enabled := true;
|
|
ListBox1.Enabled := true;
|
|
Label4.Caption := '';
|
|
end;
|
|
end;
|
|
|
|
|
|
// Save image
|
|
procedure Tfmain.Button5Click(Sender: TObject);
|
|
begin
|
|
ImageEnView1.IO.SaveToFile(ImageEnView1.IO.ExecuteSaveDialog('', '', false, 1, ''));
|
|
end;
|
|
|
|
|
|
// Zoom
|
|
procedure Tfmain.TrackBar1Change(Sender: TObject);
|
|
begin
|
|
ImageEnView1.Zoom := TrackBar1.Position;
|
|
end;
|
|
|
|
|
|
// Timer1 and FPS are necessary just to calculate effective FPS
|
|
var
|
|
FPS: integer = 0;
|
|
|
|
|
|
// frame received
|
|
procedure Tfmain.ImageEnView1MediaFoundationNotify(Sender, MediaFoundationObject: TObject; NotifyType: TIEMediaFountationNotifyType);
|
|
var
|
|
sample: TIEMFReceivedSample;
|
|
begin
|
|
sample := ImageEnView1.IO.MediaFoundationSourceReader.GetNextSample();
|
|
try
|
|
if sample.StreamType = mmf_VIDEO_STREAM then
|
|
begin
|
|
sample.DecodeSample(ImageEnView1.IEBitmap);
|
|
ImageEnView1.Update();
|
|
end;
|
|
finally
|
|
sample.Free();
|
|
end;
|
|
|
|
inc(FPS);
|
|
end;
|
|
|
|
|
|
procedure Tfmain.Timer1Timer(Sender: TObject);
|
|
begin
|
|
Label3.Caption := Format('%d FPS', [FPS]);
|
|
FPS := 0;
|
|
end;
|
|
|
|
end.
|