📄 graphwin.pas.~85~
字号:
Ellipse(U.I2X - 2, U.I2Y - 2, U.I2X + 2, U.I2Y + 2);
// 右眼看到的点K1,绘制在右图
Ellipse(U.I1X - 2, U.I1Y - 2, U.I1X + 2, U.I1Y + 2);
// 连接I2和K2
MoveTo(W.I2X, W.I2Y);
LineTo(U.I2X, U.I2Y);
// 连接I1和K1
MoveTo(W.I1X, W.I1Y);
LineTo(U.I1X, U.I1Y);
end;
// 恢复原来的Styles
RestoreStyles;
end;
procedure TForm1.test11Click(Sender: TObject);
var
lBMP: TBitmap;
begin
// 测试将图像宽度缩小一倍贴到Image控件
lBMP := TBitmap.Create;
if OpenDialog1.Execute then
begin
CurrentFile := OpenDialog1.FileName;
lBMP.LoadFromFile(CurrentFile);
end;
with Image do
begin
AutoSize := False;
Stretch := True;
Height := lBMP.Height;
Width := Round(lBMP.Width / 2);
Picture.Bitmap := lBMP;
end;
end;
procedure TForm1.mi2DTo3DClick(Sender: TObject);
var
i, j, k: Integer; // 循环变量
tmpS: string;
Dir, Fold: string;
begin
with StereoImg do
begin
// 选择原图像
lImg := TBitmap.Create;
if OpenDialog1.Execute then
begin
CurrentFile := OpenDialog1.FileName;
lImg.LoadFromFile(CurrentFile);
Dir := ExtractFileDir(CurrentFile);
Fold := Dir + '\2DTo3D';
if not DirectoryExists(Fold) then
mkDir(Fold);
// 生成右眼视图
// Produce_rImg;
for k := 1 to 10 do
begin
Produce_rImg(index);
{ 保存生成的右眼视图 }
case index of
0: CurrentFile := Fold + '\junyun' + IntToStr(M) + '_' + IntToStr(N) +
'_' + IntToStr(100 + k) + '.bmp';
1: CurrentFile := Fold + '\zhengtai' + IntToStr(M) + '_' + IntToStr(N)
+ '_' + IntToStr(100 + k) + '.bmp';
2: CurrentFile := Fold + '\sanjiao' + IntToStr(M) + '_' + IntToStr(N)
+
'_' + IntToStr(100 + k) + '.bmp';
3: CurrentFile := Fold + '\fenduan' + IntToStr(M) + '_' + IntToStr(N)
+
'_' + IntToStr(100 + k) + '.bmp';
4: CurrentFile := Fold + '\hist' + IntToStr(M) + '_' + IntToStr(N) +
'_' + IntToStr(100 + k) + '.bmp';
end;
rImg.SaveToFile(CurrentFile);
end;
end;
// 显示随机变量矩阵
fmRanVar := TfmRanVar.Create(Self);
with fmRanVar do
begin
reKmn.Lines.Clear;
for i := 0 to M - 1 do
begin
tmpS := '';
for j := 0 to N - 1 do
tmpS := tmpS + FloatToStr(Kmn[i, j]) + ' ';
reKmn.Lines.Add(tmpS);
reKmn.Lines.Add('');
end;
ShowModal;
Free;
end;
{ 以下代码将两幅图像合成一副bmp }
with Image, StereoImg do
begin
// 重新确定Image宽和高,StereoImg的lImg和rImg宽和高都是一样的
Width := lImg.Width + rImg.Width;
Height := lImg.Height;
Canvas.Draw(0, 0, lImg);
Canvas.Draw(lImg.Width, 0, rImg);
end;
// 释放所占资源
lImg.Free;
rImg.Free; // 用Free就算没有创建也不出错
end;
end;
procedure TForm1.miCrossEntropyClick(Sender: TObject);
begin
fmCrossEntropy := TfmCrossEntropy.Create(Self);
fmCrossEntropy.ShowModal;
fmCrossEntropy.Free;
end;
procedure TForm1.ComboBox1Change(Sender: TObject);
begin
index := ComboBox1.ItemIndex;
end;
//将左图向左移得到右图
procedure TForm1.MoveLeft1Click(Sender: TObject);
var
left: Integer;
lImg, rImg, tImg: TBitmap;
Dir, Fold: string;
// FillColor:TColor;
begin
lImg := TBitmap.Create;
rImg := TBitmap.Create;
tImg := TBitmap.Create;
if OpenDialog1.Execute then
begin
CurrentFile := OpenDialog1.FileName;
tImg.LoadFromFile(CurrentFile);
Dir := ExtractFileDir(CurrentFile);
Fold := Dir + '\MoveLeft';
if not DirectoryExists(Fold) then
mkDir(Fold);
lImg.Assign(tImg);
rImg.Width := tImg.Width;
rImg.Height := tImg.Height;
rImg.PixelFormat := tImg.PixelFormat;
for left := 1 to 40 do
begin
//left:= StrtoInt(InputBox('Move Left','Please Input the piexl number','0'));
rImg.Canvas.CopyRect(Rect(0, 0, rImg.Width - left, rImg.Height),
tImg.Canvas, Rect(left, 0, tImg.Width, tImg.Height));
rImg.Canvas.Brush.Color := clblack; //用黑色填充最右边
lImg.Canvas.Brush.Color := clblack;
rImg.Canvas.FillRect(Rect(rImg.Width - left, 0, rImg.Width, rImg.Height));
lImg.Canvas.FillRect(Rect(lImg.Width - left, 0, lImg.Width, lImg.Height));
//分别保存左右图
CurrentFile := Fold + '\left' + IntToStr(left) + '.bmp';
lImg.SaveToFile(CurrentFile);
CurrentFile := Fold + '\right' + IntToStr(left) + '.bmp';
rImg.SaveToFile(CurrentFile);
//lImg.Assign(tImg);
end;
end;
// 以下代码将两幅图像合成一副bmp
with Image do
begin
// 重新确定Image宽和高,StereoImg的lImg和rImg宽和高都是一样的
//Picture.Bitmap.Width:= lImg.Width + rImg.Width;
Width := lImg.Width + rImg.Width;
Height := lImg.Height;
Canvas.Draw(0, 0, lImg);
Canvas.Draw(lImg.Width, 0, rImg);
end;
lImg.Free;
rImg.Free;
tImg.Free;
end;
procedure TForm1.MoveRight21Click(Sender: TObject);
var
right: Integer;
lImg, rImg, tImg: TBitmap;
Dir, Fold: string;
begin
lImg := TBitmap.Create;
rImg := TBitmap.Create;
tImg := TBitmap.Create;
if OpenDialog1.Execute then
begin
CurrentFile := OpenDialog1.FileName;
tImg.LoadFromFile(CurrentFile);
Dir := ExtractFileDir(CurrentFile);
Fold := Dir + '\MoveRight2';
if not DirectoryExists(Fold) then
mkDir(Fold);
//right:= StrtoInt(InputBox('Move Right','Please Input the piexl number','0'));
for right := 1 to 40 do
begin
lImg.Width := tImg.Width - right;
lImg.Height := tImg.Height;
lImg.PixelFormat := tImg.PixelFormat;
rImg.Width := tImg.Width - right;
rImg.Height := tImg.Height;
rImg.PixelFormat := tImg.PixelFormat;
lImg.Canvas.CopyRect(Rect(0, 0, lImg.Width, lImg.Height), tImg.Canvas,
Rect(0, 0, tImg.Width - right, tImg.Height));
rImg.Canvas.CopyRect(Rect(0, 0, rImg.Width, rImg.Height), tImg.Canvas,
Rect(right, 0, tImg.Width, tImg.Height));
//分别保存左右图
CurrentFile := Fold + '\left' + IntToStr(right) + '.bmp';
lImg.SaveToFile(CurrentFile);
CurrentFile := Fold + '\right' + IntToStr(right) + '.bmp';
rImg.SaveToFile(CurrentFile);
end;
end;
{ 以下代码将两幅图像合成一副bmp }
with Image do
begin
// 重新确定Image宽和高,StereoImg的lImg和rImg宽和高都是一样的
Picture.Bitmap.Width := lImg.Width + rImg.Width;
//Width := lImg.Width + rImg.Width;
Picture.Bitmap.Height := lImg.Height;
Canvas.Draw(0, 0, lImg);
Canvas.Draw(lImg.Width, 0, rImg);
end;
lImg.Free;
tImg.Free;
rImg.Free;
end;
procedure TForm1.MoveRight1Click(Sender: TObject);
var
right: Integer;
lImg, rImg, tImg: TBitmap;
Dir, Fold: string;
// FillColor:TColor;
begin
lImg := TBitmap.Create;
rImg := TBitmap.Create;
tImg := TBitmap.Create;
if OpenDialog1.Execute then
begin
CurrentFile := OpenDialog1.FileName;
tImg.LoadFromFile(CurrentFile);
Dir := ExtractFileDir(CurrentFile);
Fold := Dir + '\MoveRight';
if not DirectoryExists(Fold) then
mkDir(Fold);
rImg.Assign(tImg);
//lImg.Width:=tImg.Width;
//lImg.Height:=tImg.Height;
//lImg.PixelFormat:=tImg.PixelFormat;
lImg.Width := tImg.Width;
lImg.Height := tImg.Height;
lImg.PixelFormat := tImg.PixelFormat;
for right := 1 to 40 do
begin
lImg.Canvas.CopyRect(Rect(right, 0, lImg.Width, lImg.Height), tImg.Canvas,
Rect(0, 0, tImg.Width - right, tImg.Height));
rImg.Canvas.Brush.Color := clblack; //用黑色填充最右边
lImg.Canvas.Brush.Color := clblack;
rImg.Canvas.FillRect(Rect(0, 0, right, rImg.Height));
lImg.Canvas.FillRect(Rect(0, 0, right, lImg.Height));
//分别保存左右图
CurrentFile := Fold + '\left' + IntToStr(right) + '.bmp';
lImg.SaveToFile(CurrentFile);
CurrentFile := Fold + '\right' + IntToStr(right) + '.bmp';
rImg.SaveToFile(CurrentFile);
//lImg.Assign(tImg);
end;
end;
// 以下代码将两幅图像合成一副bmp
with Image do
begin
// 重新确定Image宽和高,StereoImg的lImg和rImg宽和高都是一样的
//Picture.Bitmap.Width:= lImg.Width + rImg.Width;
Width := lImg.Width + rImg.Width;
Height := lImg.Height;
Canvas.Draw(0, 0, lImg);
Canvas.Draw(lImg.Width, 0, rImg);
end;
lImg.Free;
rImg.Free;
tImg.Free;
end;
procedure TForm1.miMergeJPSClick(Sender: TObject);
begin
{ 禁用Image的绘图功能 }
Image.Enabled := False;
with StereoImg do
begin
{ 借用StereoImg控件暂存两幅图像 }
lImg := TBitmap.Create;
rImg := TBitmap.Create;
{ 选择左眼视图 }
if OpenPicDlg.Execute then
lImg.LoadFromFile(OpenPicDlg.FileName);
{ 选择右眼视图 }
if OpenPicDlg.Execute then
rImg.LoadFromFile(OpenPicDlg.FileName);
{ 将两幅图像合成一副图像 }
// 判断图像大小是否都是800*600
if (lImg.Height = 600) and (lImg.Width = 800) and (lImg.Height = rImg.Height)
and (lImg.Width = rImg.Width) then
with Image, StereoImg do
begin
// 重新确定Image宽和高,StereoImg的lImg和rImg宽和高都是一样的
Width := lImg.Width + rImg.Width;
Height := lImg.Height;
Canvas.Draw(0, 0, lImg);
Canvas.Draw(lImg.Width, 0, rImg);
end
else
MessageDlg('No image selected or improper image selected! Both left image and right image must be 800*600!', mtError, [mbOk], 0);
{ 释放借用的变量 }
lImg.Free;
rImg.Free;
end;
end;
procedure TForm1.miCreateScriptClick(Sender: TObject);
begin
{ 禁用Image的绘图功能 }
Image.Enabled := False;
{ 打开生成静态立体图像对的脚本设置对话框 }
fmStaticStereo := TfmStaticStereo.Create(Self);
fmStaticStereo.ShowModal;
fmStaticStereo.Free;
end;
procedure TForm1.HandButtonClick(Sender: TObject);
begin
DrawingTool := dtNull;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -