• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

zw版【转发· 台@@湾 nvp系列Delphi例程】HALCONHWindowOverlayer1

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

zw版【转发· 台@@湾 nvp系列Delphi例程】HALCON HWindow Overlayer 1

------------------------------------
HALCON HWindow Overlayer 1

unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleCtrls, HALCONXLib_TLB, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
HWindowXCtrl1: THWindowXCtrl;
Button1: TButton;
Timer1: TTimer;
procedure FormShow(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
fg : HFramegrabberX;
rg : HRegionX;
op : HOperatorSetX;
img : HImageX;
mtype, w, h : OleVariant;
hw : THWindowXCtrl;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure PatchINT3;
var
NOP : Byte;
NTDLL: THandle;
BytesWritten: DWORD;
Address: Pointer;
begin
if Win32Platform <> VER_PLATFORM_WIN32_NT then
Exit;
NTDLL := GetModuleHandle('NTDLL.DLL');
if NTDLL = 0 then
Exit;
Address := GetProcAddress(NTDLL, 'DbgBreakPoint');
if Address = nil then
Exit;
try
if Char(Address^) <> #$CC then
Exit;
NOP := $90;
if WriteProcessMemory(GetCurrentProcess, Address, @NOP, 1, BytesWritten) and (BytesWritten = 1) then
FlushInstructionCache(GetCurrentProcess, Address, 1);
except
//Do not panic if you see an EAccessViolation here, it is perfectly harmless!
on EAccessViolation do ;
else raise;
end;
end;
procedure TForm1.FormShow(Sender: TObject);
begin
PatchINT3;
hw := THWindowXCtrl.Create(Self);
hw.Width := HWindowXCtrl1.Width;
hw.Height := HWindowXCtrl1.Height;
hw.Parent := Self;
hw.Visible := False;
op := CoHOperatorSetX.Create;
rg := CoHRegionX.Create;
fg := CoHFramegrabberX.Create;
fg.OpenFramegrabber('DirectShow', 1, 1, 0, 0, 0, 0, 'default', 8, 'rgb', -1, 'false', 'default', '[0] Logitech QuickCam for Notebooks Pro', 0, -1);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if Button1.Caption = 'Grab Start' then
begin
Button1.Caption := 'Grab Stop';
Timer1.Enabled := True;
end
else
begin
Timer1.Enabled := False;
Button1.Caption := 'Grab Start';
end;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
img := fg.GrabImage;
img.GetImagePointer1(mType,w,h);
HWindowXCtrl1.HalconWindow.SetPart(0,0,h-1,w-1);
hw.HalconWindow.SetPart(0,0,h-1,w-1);
img.DispObj(hw.HalconWindow);
rg := img.Threshold(60.0, 180.0);
rg.DispObj(hw.HalconWindow);
hw.HalconWindow.CopyRectangle(HWindowXCtrl1.HalconWindow, 0, 0, HWindowXCtrl1.Height-1, HWindowXCtrl1.Width-1, 0, 0);
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Timer1.Enabled := False;
op.CloseFramegrabber(fg.Handle);
fg := nil;
img := nil;
rg := nil;
end;
end.

------------------------------------
HALCON HWindow Overlayer 2

unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleCtrls, HALCONXLib_TLB, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
HWindowXCtrl1: THWindowXCtrl;
Button1: TButton;
Timer1: TTimer;
HWindowXCtrl2: THWindowXCtrl;
procedure FormShow(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
fg : HFramegrabberX;
rg : HRegionX;
op : HOperatorSetX;
img : HImageX;
mtype, w, h : OleVariant;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure PatchINT3;
var
NOP : Byte;
NTDLL: THandle;
BytesWritten: DWORD;
Address: Pointer;
begin
if Win32Platform <> VER_PLATFORM_WIN32_NT then
Exit;
NTDLL := GetModuleHandle('NTDLL.DLL');
if NTDLL = 0 then
Exit;
Address := GetProcAddress(NTDLL, 'DbgBreakPoint');
if Address = nil then
Exit;
try
if Char(Address^) <> #$CC then
Exit;
NOP := $90;
if WriteProcessMemory(GetCurrentProcess, Address, @NOP, 1, BytesWritten) and (BytesWritten = 1) then
FlushInstructionCache(GetCurrentProcess, Address, 1);
except
//Do not panic if you see an EAccessViolation here, it is perfectly harmless!
on EAccessViolation do ;
else raise;
end;
end;
procedure TForm1.FormShow(Sender: TObject);
begin
PatchINT3;
HWindowXCtrl2.Width := HWindowXCtrl1.Width;
HWindowXCtrl2.Height := HWindowXCtrl1.Height;
HWindowXCtrl2.Parent := Self;
HWindowXCtrl2.Visible := False;
op := CoHOperatorSetX.Create;
rg := CoHRegionX.Create;
fg := CoHFramegrabberX.Create;
fg.OpenFramegrabber('DirectShow', 1, 1, 0, 0, 0, 0, 'default', 8, 'rgb', -1, 'false', 'default', '[0] Logitech QuickCam for Notebooks Pro', 0, -1);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if Button1.Caption = 'Grab Start' then
begin
Button1.Caption := 'Grab Stop';
Timer1.Enabled := True;
end
else
begin
Timer1.Enabled := False;
Button1.Caption := 'Grab Start';
end;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
img := fg.GrabImage;
img.GetImagePointer1(mType,w,h);
HWindowXCtrl1.HalconWindow.SetPart(0,0,h-1,w-1);
HWindowXCtrl2.HalconWindow.SetPart(0,0,h-1,w-1);
img.DispObj(HWindowXCtrl2.HalconWindow);
rg := img.Threshold(60.0, 180.0);
rg.DispObj(HWindowXCtrl2.HalconWindow);
HWindowXCtrl2.HalconWindow.CopyRectangle(HWindowXCtrl1.HalconWindow, 0, 0, HWindowXCtrl1.Height-1, HWindowXCtrl1.Width-1, 0, 0);
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Timer1.Enabled := False;
op.CloseFramegrabber(fg.Handle);
fg := nil;
img := nil;
rg := nil;
end;
end.

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
delphiedit固定小数位数的实现(形如:1,000,000.10)发布时间:2022-07-18
下一篇:
delphi动态绑定代码都某个控件发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap