videocap 控件采集的图像的调整问题(100分)

  • 主题发起人 主题发起人 初练
  • 开始时间 开始时间

初练

Unregistered / Unconfirmed
GUEST, unregistred user!
我用videocap控件做图像采集,不知道如何使采集的图像处理后显示到Timage上,
一边采集一边显示,对速度要求不是很严。问题的关键是怎样使 Bitmap.ScanLine[X] 获得
要处理的数据。请高手指教。
 
呵呵,又该我得分了:)
以下代码中的关键部分也是别人给我的,不知道会不会侵权

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, Video,
Vfw;

type
TForm1 = class(TForm)
VideoCap1: TVideoCap;
Image1: TImage;
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure VideoCap1VideoStream(sender: TObject;
lpVhdr: PVIDEOHDR);
private
{ Private declarations }
public
{ Public declarations }
end;


var
Form1: TForm1;

implementation

{$R *.DFM}

var
info: PBitmapInfo;

procedure TForm1.Button1Click(Sender: TObject);
begin

with VideoCap1do

begin

DriverIndex := 0;
VideoPreview := true;
PreviewScaleToWindow := true;
end;

end;


procedure TForm1.Button2Click(Sender: TObject);
begin

VideoCap1.GetBitmapInfo(Pointer(info));
Image1.Picture.Bitmap.Width := info.bmiHeader.biWidth;
Image1.Picture.Bitmap.Height := info.bmiHeader.biHeight;

VideoCap1.OnFrameCallback := VideoCap1VideoStream;
end;


procedure FrameToBitmap(Bitmap: TBitmap;
FrameBuffer: pointer;
BitmapInfo: TBitmapInfo);
begin

if bitmapInfo.bmiHeader.BiCompression = bi_RGB then

with Bitmapdo

setDiBits(canvas.handle, handle, 0, BitmapInfo.bmiHeader.biheight,
FrameBuffer, BitmapInfo, DIB_RGB_COLORS);
end;


procedure TForm1.FormShow(Sender: TObject);
begin

VideoCap1.OnFrameCallback := nil;
end;


procedure TForm1.VideoCap1VideoStream(sender: TObject;
lpVhdr: PVIDEOHDR);
begin

FrameToBitmap(Image1.Picture.Bitmap, lpvhdr^.lpData, info^);
Image1.Invalidate;
end;


end.
 
我试验了一下,不知为什么,image1上部显示图像?
 
procedure TForm1.VideoCap1VideoStream(sender: TObject;
lpVhdr: PVIDEOHDR);
begin

FrameToBitmap(Image1.Picture.Bitmap, lpvhdr^.lpData, info^);
Image1.Invalidate;
end;


在这里面设置一个断点,按下 Button2 后能执行到这里吗?
 
我已经可以得到图像啦,我又发现问题
我用如语句调节突现的颜色可是不能得到平滑的颜色变化,某些地方总是出像大块的色斑
请指教,分数不够可以再加(我的图像,是摄像头得到的活动图像)
FrameToBitmap(Image1.Picture.Bitmap,lpVhdr^.lpData,bminf);
with image1.picture.bitmapdo

begin

pixelformat:=pf24bit;
for y := 0 to image1.Picture.bitmap.height -1do

begin

P := image1.picture.BitMap.ScanLine[y];
for x := 0 to image1.Picture.bitmap.width -1do

begin

with p[x]do

begin

rgbtred:=rgbtred+scrollbar1.position
// if rgbtred >255 then

// rgbtred:=250;
// if rgbtred< 0 then

// rgbtred:=0;
rgbtgreen:=rgbtgreen+scrollbar2.position
// if rgbtgreen >255 then

// rgbtgreen :=250;
// if rgbtgreen<0 then

// rgbtgreen:=0;
rgbtblue:=rgbtblue+scrollbar3.position;
// if rgbtblue >255 then

// rgbtblue:=250;
// if rgbtblue<0 then

// rgbtblue:=0;
// p[x]:=not(p[x]);
end
end
end;

Canvas.draw(0,0,image1.picture.BitMap);
Image1.Visible:= true;
Image1.Invalidate;
end;
 
应该这样:

var
r, g, b: integer;
....
begin


...

r := scrollbar1.position;
g := scrollbar2.position;
b := scrollbar3.position;

...

with p[x]do

begin

rgbtred := min(rgbtred + r, 255);
rgbtgreen := min(rgbtgreen + g, 255);
rgbtblue := min(rgbtblue + b, 255);
end;

...
end;


另外,最后两句

Canvas.draw(0,0,image1.picture.BitMap);
Image1.Visible:= true;

好像没什么用吧?
 
最后两句
Canvas.draw(0,0,image1.picture.BitMap);
Image1.Visible:= true;
确实没有用, 不过min 函数出现错误提示 undeclared indentifier:'min'
怎样解决,缺什么设定吧



 
根据你给我发来的邮件解决了我的问题,非常感谢你的帮助,谢谢,
祝愿你天天有个好心情,希望能和你交个朋友,我的邮箱地址:sunwu@telekbird.com.cn
分数献给你了。
 
后退
顶部